Inspect · Source & workspace
Requested workspace inspection related to source & workspace.
1 call · #0001–#0001
echo <val>ls -l -a <val> <n> > <path>trueKimi K3 · Serving
Online SLO goodput 1dev · Implementation Optimization
01 / PROCESS MAP
Each row shows one agent’s tool events in its own recorded order. Colors show broad activities; bar widths do not represent duration.
Main agentKimi K3 · 192 visible calls
02 / EVENT SEQUENCE
Requests are grouped by agent, activity and topic. Delegations open into child branches. Summaries describe visible requests; tool errors and missing responses are flagged. A recorded response does not establish command success or a performance improvement.
Scroll within this panel to view all events. Command sketches retain familiar programs and options. Values become <val> or <n>; paths, addresses and script bodies are hidden as <path>, <url> and <script>.
Requested workspace inspection related to source & workspace.
1 call · #0001–#0001
echo <val>ls -l -a <val> <n> > <path>trueRequested file and log inspection, environment setup or inspection and workspace inspection related to task requirements.
3 calls · #0002–#0004
Read <path>env <vars>ls -l -a <path> <path> <path> <path> <path> <path> <n> > <path>Requested file and log inspection related to runtime processes.
1 call · #0005–#0005
Read <path>Requested file and log inspection related to source & workspace.
1 call · #0006–#0006
Read <path>Requested file and log inspection related to benchmark & validation setup.
2 calls · #0007–#0008
Read <path>Requested file and log inspection related to task requirements.
4 calls · #0009–#0012
Read <path>Requested environment setup or inspection, source searches and runtime inspection related to device memory.
1 call · #0013–#0013
envgrep -E <val>sortecho <flag>npu-smi info <n> > <path>head -n <n>trueRequested source searches and file and log inspection related to source & workspace.
6 calls · #0014–#0019
grep -n <val> <path>head -n <n>Read <path>Requested script or workload execution related to source & workspace.
1 call · #0020–#0020
which <val>python3 -c <script> <n> >& <path>echo <flag>Requested repository inspection and file and log inspection related to source & workspace.
2 calls · #0021–#0022
cd <path>git status --shorthead -n <n>git log --oneline <flag> <args>head -n <n> <path>Requested script or workload execution related to task requirements.
2 calls · #0023–#0024
python3 - <script>Requested file and log inspection and script or workload execution related to source & workspace.
2 calls · #0025–#0026
Read <path>cd <path>bash <script> <n> >& <path>tail -n <n>Requested script or workload execution and file and log inspection related to benchmark & validation setup.
2 calls · #0027–#0028
cd <path>bash <script> <n> >& <path>tail -n <n>echo <val>bash <script> > <path> <n> >& <path>tail -n <n> <path>Requested workspace inspection, file and log inspection and source searches related to attention kernels.
1 call · #0029–#0029
ls <path>head -n <n>echo <flag>grep -i -E <val>ls <path> <n> > <path>Requested workspace inspection and file and log inspection related to source & workspace.
1 call · #0030–#0030
ls -R <path>head -n <n>Requested file and log inspection and source searches related to attention kernels.
1 call · #0031–#0031
wc -l <path> <path> <path> <n> > <path>echo <flag>grep -r -n <val> <path>head -n <n>Requested file and log inspection related to source & workspace.
1 call · #0032–#0032
Read <path>Requested file and log inspection related to source & workspace.
1 call · #0033–#0033
Read task output <task>Requested source searches and file and log inspection related to runtime processes.
2 calls · #0034–#0035
grep -r -n <val> <path>grep -i <val>headecho <flag>grep -n <val> <path>head -n <n>sed -n <val> <path>Requested file and log inspection, source searches and workspace inspection related to benchmark & validation setup.
1 call · #0036–#0036
tail -n <n> <path> <n> > <path>grep -v -E <val>tail -n <n>ls <path> <n> > <path>Requested source searches and file and log inspection related to attention kernels.
2 calls · #0037–#0038
grep -n <val> <path>head -n <n>Read <path>Requested source searches and file and log inspection related to benchmark & validation setup.
1 call · #0039–#0039
grep -E <val> <path> <n> > <path>tail -n <n>Requested file and log inspection and source searches related to source & workspace.
2 calls · #0040–#0041
Read <path>grep -n <val> <path>headRequested file and log inspection related to source & workspace.
1 call · #0042–#0042
Read task output <task>Requested workspace inspection, file and log inspection and source searches related to batching & scheduling.
3 calls · #0043–#0045
ls <path>wc -l <path> <path> <n> > <path>ls <path> <n> > <path>grep -n <val> <path>headecho <flag>grep -r -n <val> <path>head -n <n>Read <path>Requested execution waits related to source & workspace.
1 call · #0046–#0046
Wait for <task>Requested workspace file updates, file and log inspection and script or workload execution related to benchmark & validation setup.
1 call · #0047–#0047
cp <path> <path>cat <path>python3 -m <module>head -n <n>Requested script or workload execution related to benchmark & validation setup.
1 call · #0048–#0048
cd <path>bash <script> > <path> <n> >& <path>echo <val>tee -a <path>Requested file and log inspection, workspace inspection and source searches related to source & workspace.
7 calls · #0049–#0055
Read <path>sed -n <val> <path>tail -n <n> <path> <n> > <path>ls -l -a <path> <n> > <path>tailgrep -n <val> <path>head -n <n>wc -l <path>tail -n <n> <path>ls <path>Requested file and log inspection related to batching & scheduling.
1 call · #0056–#0056
Read <path>Requested execution waits, file and log inspection and workspace inspection related to source & workspace.
1 call · #0057–#0057
sleep <n>tail -n <n> <path>ls <path>grep -E <val>Requested script or workload execution related to latency & request handling.
2 calls · #0058–#0059
python3 - <script>Requested source searches and file and log inspection related to batching & scheduling.
1 call · #0060–#0060
grep -n <val> <path>head -n <n>Requested workspace inspection, source searches and file and log inspection related to source & workspace.
1 call · #0061–#0061
ls -l -a <path>grep -E <val>echo <flag>tail -n <n> <path>Requested script or workload execution related to latency & request handling.
1 call · #0062–#0062
python3 - <script>Requested script or workload execution related to source & workspace.
1 call · #0063–#0063
python3 - <script>Requested source searches and file and log inspection related to batching & scheduling.
2 calls · #0064–#0065
grep -n <val> <path>grep -i -E <val>head -n <n>grep -E <val>awk <val>grep -v -E <path>Requested workspace inspection, source searches and file and log inspection related to source & workspace.
1 call · #0066–#0066
ls <path>grep -E <val>tail -n <n> <path>Requested script or workload execution related to latency & request handling.
1 call · #0067–#0067
python3 - <script>Requested file and log inspection related to source & workspace.
1 call · #0068–#0068
sed -n <val> <path>Requested file and log inspection related to attention kernels.
1 call · #0069–#0069
Read <path>Requested execution waits, workspace inspection and source searches related to source & workspace.
1 call · #0070–#0070
sleep <n>ls <path>grep <val>tail -n <n> <path> <n> > <path>Requested script or workload execution and workspace file updates related to latency & request handling.
1 call · #0071–#0071
python3 - <script>cp <path> <path>Requested source searches and file and log inspection related to runtime processes.
1 call · #0072–#0072
grep -r -n <val> <path>head -n <n>Requested workspace file updates and environment setup or inspection related to batching & scheduling.
1 call · #0073–#0073
mkdir -p <path>cd <path>env <vars> nohup <val> -m <val> <flag> <args>echo <val>Requested source searches and execution waits related to source & workspace.
1 call · #0074–#0074
<command> <args>grep -q <val>sleep <n>Requested service requests, script or workload execution and execution waits related to device memory.
1 call · #0075–#0075
cd <path>curl -s -X <val> <url> -H <path> -d <val>echopython3 - <script>curl -s -X <val> <url> <val>sleep <n>ls -l -a <path>headRequested workspace inspection, file and log inspection and script or workload execution related to source & workspace.
9 calls · #0076–#0084
find <path> -name <val>headfind <path> -type <val>head -n <n>python3 - <script>head -n <n> <path>wc -l <path>Requested script or workload execution related to source & workspace.
1 call · #0085–#0085
python3 - <script>Requested source searches and file and log inspection related to batching & scheduling.
1 call · #0086–#0086
grep -r -n <val> <path>headRequested source searches and file and log inspection related to source & workspace.
1 call · #0087–#0087
grep -r -n <val> <path> -lgrep -r -n <val> <path>headRequested source searches, file and log inspection and script or workload execution related to batching & scheduling.
4 calls · #0088–#0091
grep -n <val> <path>head -n <n>python3 - <script>which <val> <val> <n> > <path>python3 -c <script> <n> >& <path>echo <flag>sed -n <val> <path>ps <val>grep -E <val>grep -v <val>awk <val>headRequested environment setup or inspection, execution waits and file and log inspection related to device memory.
1 call · #0092–#0092
cd <path><command> <args>env <vars>sleep <n>tail -n <n>head -n <n>wait <val>Requested source searches and file and log inspection related to source & workspace.
2 calls · #0093–#0094
grep -n <val> <path>headsed -n <val> <path>Requested file and log inspection related to source & workspace.
1 call · #0095–#0095
Read task output <task>Requested script or workload execution related to batching & scheduling.
1 call · #0096–#0096
python3 - <script>Requested source searches and file and log inspection related to batching & scheduling.
1 call · #0097–#0097
grep -E <val> <path>tail -n <n>echo <path>grep -c <val> <path>Requested execution waits and file and log inspection related to batching & scheduling.
1 call · #0098–#0098
cd <path><command> <args>sleep <n>tail -n <n>Requested source searches and file and log inspection related to source & workspace.
1 call · #0099–#0099
grep -n <val> <path>head -n <n>echo <flag>sed -n <val> <path>Requested script or workload execution related to source & workspace.
1 call · #0100–#0100
python3 - <script>Requested file and log inspection and source searches related to runtime processes.
1 call · #0101–#0101
tail -n <n> <path>echo <val>grep -c <val> <path>Requested script or workload execution, execution waits and source searches related to task requirements.
1 call · #0102–#0102
cd <path>nohup <val> -m <val> <flag> <args>echo <val>sleep <n>grep -c <val> <path><command> <args>tail -n <n>Requested script or workload execution related to source & workspace.
1 call · #0103–#0103
python3 - <script>Requested file and log inspection related to source & workspace.
3 calls · #0104–#0106
sed -n <val> <path>Requested file and log inspection related to attention kernels.
1 call · #0107–#0107
Read <path>Requested file and log inspection related to source & workspace.
1 call · #0108–#0108
Read <path>Requested file and log inspection related to attention kernels.
1 call · #0109–#0109
Read <path>Requested file and log inspection related to source & workspace.
2 calls · #0110–#0111
Read <path>Requested file and log inspection related to attention kernels.
1 call · #0112–#0112
Read <path>Requested source searches and file and log inspection related to source & workspace.
1 call · #0113–#0113
grep -n <val> <path>head -n <n>Requested code edits related to source & workspace.
1 call · #0114–#0114
Edit <path>Requested file and log inspection related to attention kernels.
1 call · #0115–#0115
Read <path>Requested file and log inspection and source searches related to source & workspace.
1 call · #0116–#0116
sed -n <val> <path>grep -n <val> <path>headRequested code edits related to attention kernels.
1 call · #0117–#0117
Edit <path>Requested source searches and file and log inspection related to runtime processes.
1 call · #0118–#0118
grep -n <val> <path> <path> <n> > <path>head -n <n>Requested file and log inspection related to source & workspace.
2 calls · #0119–#0120
sed -n <val> <path>Read <path>Requested file and log inspection related to batching & scheduling.
2 calls · #0121–#0122
Read <path>Requested process termination, execution waits and runtime inspection related to device memory.
1 call · #0123–#0123
kill <n> <n> > <path>sleep <n>pkill -f <val> <n> > <path>npu-smi infogrep -E <val>head -n <n>ps <val>grep -c <val>Requested runtime inspection, source searches and file and log inspection related to device memory.
1 call · #0124–#0124
ps <val>grep -E <val>grep -v <val>awk <val>echo <flag>npu-smi infogrep <flag> <args>Requested script or workload execution, file and log inspection and source searches related to source & workspace.
1 call · #0125–#0125
python3 -c <script>echo <val>cat <path> <n> > <path>grep -i <val>headls <path>Requested code edits related to source & workspace.
1 call · #0126–#0126
Write <path>Requested script or workload execution, source searches and execution waits related to batching & scheduling.
1 call · #0127–#0127
cd <path>nohup <val> -m <val> <flag> <args>echo <val><command> <args>grep -q <val>sleep <n>Requested script or workload execution and file and log inspection related to source & workspace.
1 call · #0128–#0128
bash <script> <val> <n> >& <path>tail -n <n>Requested process termination, execution waits and repository inspection related to runtime processes.
1 call · #0129–#0129
pkill -f <val>sleep <n>cd <path>git stash <val> -m <val>git diff --stat <val>tail -n <n>Requested repository inspection and file and log inspection related to source & workspace.
1 call · #0130–#0130
cd <path>git stash <val>git status --shortheadRequested runtime inspection, source searches and file and log inspection related to batching & scheduling.
1 call · #0131–#0131
ps <val>grep -E <val>grep -v <val>awk <val>Requested repository inspection and file and log inspection related to source & workspace.
1 call · #0132–#0132
cd <path>git stash <val> -m <val>git status --shorthead -n <n>echo <val>Requested script or workload execution, source searches and execution waits related to batching & scheduling.
1 call · #0133–#0133
cd <path>nohup <val> -m <val> <flag> <args><command> <args>grep -q <val>sleep <n>bash <script> <val> <n> >& <path>tail -n <n>Requested script or workload execution and source searches related to latency & request handling.
1 call · #0134–#0134
cd <path>python3 -m <module> <flag> <args>grep -E <val>Requested process termination, execution waits and repository inspection related to runtime processes.
1 call · #0135–#0135
pkill -f <val>sleep <n>cd <path>git stash <val>git diff --stattail -n <n>Requested repository inspection and file and log inspection related to source & workspace.
2 calls · #0136–#0137
cd <path>git stash <val>git status --shorthead -n <n>Requested file and log inspection, workspace file updates and script or workload execution related to runtime processes.
1 call · #0138–#0138
cat > <path> <script>chmod <val> <path>bash <script>Requested script or workload execution, source searches and execution waits related to batching & scheduling.
1 call · #0139–#0139
cd <path>nohup <val> -m <val> <flag> <args><command> <args>grep -q <val>sleep <n>Requested script or workload execution, file and log inspection and source searches related to latency & request handling.
1 call · #0140–#0140
bash <script> <val> <n> >& <path>tail -n <n>cd <path>python3 -m <module> <flag> <args>grep -E <val>Requested source searches and file and log inspection related to runtime processes.
1 call · #0141–#0141
grep <val> <path>grep <flag> <args>awk <val>sort -ntail -n <n>echo <flag>Requested script or workload execution, environment setup or inspection and execution waits related to device memory.
1 call · #0142–#0142
python3 - <script>env <vars>sleep <n>grep <val> <path>tail -n <n>wait <val>Requested source searches and file and log inspection related to source & workspace.
1 call · #0143–#0143
grep -n <val> <path>head -n <n>Requested script or workload execution related to latency & request handling.
1 call · #0144–#0144
python3 - <script>Requested script or workload execution, environment setup or inspection and execution waits related to device memory.
1 call · #0145–#0145
python3 - <script>env <vars>sleep <n><command> <args>head <flag> <args>tail -n <n>kill <val> <n> > <path>Requested script or workload execution related to source & workspace.
1 call · #0146–#0146
python3 - <script>Requested file and log inspection related to source & workspace.
1 call · #0147–#0147
sed -n <val> <path>Requested source searches, file and log inspection and script or workload execution related to attention kernels.
1 call · #0148–#0148
grep -r -n <val> <path> <n> > <path>headpython3 - <script>Requested file and log inspection, source searches and repository inspection related to source & workspace.
3 calls · #0149–#0151
sed -n <val> <path>grep -n <val> <path>headcd <path>git diff <path>head -n <n>Requested source restoration and repository inspection related to source & workspace.
1 call · #0152–#0152
cd <path>git checkout <path>git diff --statRequested workspace inspection, source searches and file and log inspection related to source & workspace.
2 calls · #0153–#0154
ls <path>grep -n <val> <path>headsed -n <val> <path>Requested source searches, file and log inspection and environment setup or inspection related to benchmark & validation setup.
1 call · #0155–#0155
grep -n <val> <path>headenvgrep -i <val>python3 -c <script>Requested source searches and file and log inspection related to source & workspace.
2 calls · #0156–#0157
grep -n <val> <path>head -n <n>Read <path>Requested source searches and file and log inspection related to runtime processes.
1 call · #0158–#0158
grep -E <val> <path>tail -n <n>Requested file and log inspection related to source & workspace.
1 call · #0159–#0159
Read <path>Requested code edits related to source & workspace.
3 calls · #0160–#0162
Edit <path>Requested source searches and file and log inspection related to source & workspace.
1 call · #0163–#0163
grep -r -n <val> <path>headgrep -r -n <val> <path> --include <path>grep -v <val>Requested code edits related to source & workspace.
1 call · #0164–#0164
Edit <path>Requested file and log inspection related to source & workspace.
1 call · #0165–#0165
Read <path>Requested code edits related to source & workspace.
1 call · #0166–#0166
Edit <path>Requested source searches, file and log inspection and script or workload execution related to speculative decoding.
1 call · #0167–#0167
grep -r -n <val> <path> <path> <n> > <path>headecho <flag>python3 -c <script>Requested script or workload execution, source searches and execution waits related to batching & scheduling.
1 call · #0168–#0168
bash <script>cd <path>nohup <val> -m <val> <flag> <args><command> <args>grep -q <val>sleep <n>grep -E <val> <path>tail -n <n>Requested runtime inspection, source searches and file and log inspection related to runtime processes.
1 call · #0169–#0169
ps <val>grep -E <val>grep -v <val>awk <val>tail -n <n> <path> <n> > <path>Requested file and log inspection and script or workload execution related to runtime processes.
1 call · #0170–#0170
cat > <path> <script>bash <script>Requested source searches, execution waits and file and log inspection related to batching & scheduling.
1 call · #0171–#0171
cd <path><command> <args>grep -q <val>sleep <n>grep -E <val> <path>tail -n <n>Requested script or workload execution and file and log inspection related to source & workspace.
1 call · #0172–#0172
bash <script> <val> <n> >& <path>tail -n <n>Requested script or workload execution and source searches related to latency & request handling.
2 calls · #0173–#0174
cd <path>python3 -m <module> <flag> <args>grep -E <val>echo <val>grep -E <val> <path>Requested file and log inspection related to source & workspace.
1 call · #0175–#0175
tail -n <n> <path>Requested file and log inspection and source searches related to runtime processes.
1 call · #0176–#0176
tail -n <n> <path>grep -v -E <val>Requested source searches and file and log inspection related to source & workspace.
1 call · #0177–#0177
grep -n <val> <path>headgrep -r -n <val> <path>head -n <n>Requested code edits related to source & workspace.
4 calls · #0178–#0181
Edit <path>Requested script or workload execution, source searches and execution waits related to batching & scheduling.
1 call · #0182–#0182
bash <script>cd <path><command> <args>grep -q <val>sleep <n>Requested script or workload execution, file and log inspection and source searches related to runtime processes.
2 calls · #0183–#0184
bash <script> <val> <n> >& <path>tail -n <n>grep <flag> <args>grep -i -E <val> <path>head -n <n>Requested script or workload execution and source searches related to latency & request handling.
2 calls · #0185–#0186
cd <path>python3 -m <module> <flag> <args>echo <val>grep -E <val> <path>python3 - <script>Requested source searches and file and log inspection related to source & workspace.
2 calls · #0187–#0188
grep -r -n <val> <path> --include <path>grep -v <path>sed -n <val> <path>Requested script or workload execution related to runtime processes.
1 call · #0189–#0189
date -ubash <script>Requested script or workload execution and file and log inspection related to benchmark & validation setup.
1 call · #0190–#0190
cd <path>bash <script> > <path> <n> >& <path>echo <val>tail -n <n> <path>Requested repository inspection and file and log inspection related to source & workspace.
1 call · #0191–#0191
cd <path>git diff --statgit status --shortheadRequested script or workload execution, file and log inspection and runtime inspection related to device memory.
1 call · #0192–#0192
cd <path>bash <script> <n> >& <path>tail -n <n>ps <val>grep -E <val>grep -v <val>wc -lnpu-smi infogrep <flag> <args>03 / CANDIDATE ARTIFACT
Read code changes as Git diffs. Identifying strings are masked; binary files are listed by their full relative names.
Base commit: 340db9201005fc64635bb25db1d2538f955761c3
@@ -459,9 +459,16 @@ class AscendAttnBackend(AttentionBackend): ) if forward_batch.extend_seq_lens is not None: self.forward_metadata.extend_seq_lens = forward_batch.extend_seq_lens- self.forward_metadata.extend_seq_lens_cpu_int = (- forward_batch.extend_seq_lens.cpu().int()- )+ if forward_batch.extend_seq_lens_cpu is not None:+ # Use the host-side mirror instead of a stream-ordered D2H+ # readback, which would stall on any in-flight device work.+ self.forward_metadata.extend_seq_lens_cpu_int = torch.tensor(+ forward_batch.extend_seq_lens_cpu, dtype=torch.int32+ )+ else:+ self.forward_metadata.extend_seq_lens_cpu_int = (+ forward_batch.extend_seq_lens.cpu().int()+ ) if forward_batch.seq_lens is not None: self.forward_metadata.seq_lens = forward_batch.seq_lens.int() else:@@ -39,9 +39,26 @@ if TYPE_CHECKING: class NPUCudaGraphBackend(BaseCudaGraphBackend):- """One torch.npu.NPUGraph per shape; attention metadata captured+ """Two torch.npu.NPUGraph slots per shape; attention metadata captured inside the graph. replay_with_input_update substitutes fresh- seq_lens without re-recording."""+ seq_lens without re-recording.++ Dual-slot update pipelining: ``NPUGraph.update`` re-dispatches every+ recorded host-input operator (one FIA per layer) through the driver+ task-update API, which costs several ms per step on the critical path+ between two replays of the same graph. Two alternating graph slots are+ captured per shape so the seq_lens update for the *next* step can be+ issued on the idle slot while the current slot's replay is still on the+ device. The update of a slot is only ever issued when every previously+ launched replay (of any slot) is guaranteed complete: callers reach this+ method only after the runner's stream-ordered readback of the current+ step's seq_lens, which drains all prior replays on the compute stream.+ A slot is fast-replayed only when its armed seq_lens exactly equal the+ current batch's; any batch-composition change falls back to an inline+ update, preserving the legacy behavior and numerics.+ """++ _NUM_SLOTS = 2 def __init__( self,@@ -51,6 +68,13 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend): ) -> None: self._graphs: Dict[Any, Any] = {} self._outputs: Dict[Any, Any] = {}+ # Per-shape slot state: [{"armed": tuple|None, "thread": Thread|None}].+ self._slot_state: Dict[Any, list] = {}+ # torch_npu routes every NPUGraph.update through one shared, class-level+ # update stream, and the driver rejects a task-update group started+ # while another update is in flight. Serialize all update issuing+ # (inline and background) across slots and shapes with this lock.+ self._update_lock = threading.Lock() self._pool = None self._device_module = cuda_graph_runner.device_module self._device_id = self._device_module.current_device()@@ -93,8 +117,6 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend): if post_warmup_hook is not None: post_warmup_hook() - graph = torch.npu.NPUGraph()- if self._enable_torch_compile: skip_guard_context = torch.compiler.set_stance(skip_guard_eval_unsafe=True) else:@@ -112,19 +134,28 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend): else: graph_ctx = torch.npu.graph - with (- skip_guard_context,- graph_ctx(- graph,- pool=self._pool,- stream=self._capture_stream,- auto_dispatch_capture=True,- ),- ):- out = forward_fn()+ graphs = []+ outputs = []+ for _ in range(self._NUM_SLOTS):+ graph = torch.npu.NPUGraph()+ with (+ skip_guard_context,+ graph_ctx(+ graph,+ pool=self._pool,+ stream=self._capture_stream,+ auto_dispatch_capture=True,+ ),+ ):+ out = forward_fn()+ graphs.append(graph)+ outputs.append(out) - self._graphs[shape_key] = graph- self._outputs[shape_key] = out+ self._graphs[shape_key] = graphs+ self._outputs[shape_key] = outputs+ self._slot_state[shape_key] = [+ {"armed": None, "thread": None} for _ in range(self._NUM_SLOTS)+ ] def can_run(self, forward_batch: ForwardBatch, shape_key: ShapeKey) -> bool: return shape_key in self._graphs@@ -139,8 +170,37 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend): static_forward_batch: ForwardBatch, **kwargs, ) -> Any:- self._graphs[shape_key].replay()- return self._outputs[shape_key]+ self._graphs[shape_key][0].replay()+ return self._outputs[shape_key][0]++ def _build_update_tensor(self, seq_lens, attr_type):+ if isinstance(attr_type, torch.Tensor):+ seq_lens = torch.from_numpy(np.array(seq_lens).astype(np.int32))+ return seq_lens++ def _issue_update_thread(self, shape_key, slot_idx, attr_name, seq_lens_value, armed):+ """Update ``slot_idx`` of ``shape_key`` on a background thread.++ Only launched right after a replay was issued, i.e. after the+ caller's stream-ordered seq_lens readback has drained every prior+ replay on the compute stream, so the slot being updated has no+ in-flight execution. ``armed`` is published only after the update+ call returns, so a matching armed value implies completion.+ """+ graph = self._graphs[shape_key][slot_idx]+ state = self._slot_state[shape_key][slot_idx]+ cpu_update_input = [{attr_name: seq_lens_value}]++ def _update():+ self._device_module.set_device(self._device_id)+ with self._update_lock:+ graph.update(cpu_update_input=cpu_update_input)+ state["armed"] = armed+ state["thread"] = None++ thread = threading.Thread(target=_update, daemon=True)+ state["thread"] = thread+ thread.start() def replay_with_input_update( self,@@ -150,33 +210,109 @@ class NPUCudaGraphBackend(BaseCudaGraphBackend): attr_type: Any = None, cpu_update_input: list = None, ) -> Any:- """Rebind seq_lens on the recorded NPU graph in a background- thread, then replay. Used when the model is not deepseek-nsa.-- Two calling conventions:- 1. (legacy) seq_lens + attr_name + attr_type:- Constructs cpu_update_input=[{attr_name: seq_lens}] internally.- 2. cpu_update_input: A list of {attr_name: seq_lens} dicts,- one per speculative step. Used by EAGLE draft runners.+ """Rebind seq_lens on a recorded NPU graph, then replay.++ Dual-slot fast path: when the slot armed (pre-updated) with exactly+ this step's seq_lens exists, replay it directly without paying the+ multi-ms NPUGraph.update on the step's critical path, then issue the+ predicted next-step update (+1 per live request, padded slots stay 0)+ on the other slot in the background.++ Any mismatch (batch composition changed, speculative path, missing+ arming) falls back to the legacy inline update + replay on a slot,+ which keeps behavior identical to the single-graph implementation. """- if cpu_update_input is None:- if isinstance(attr_type, torch.Tensor):- seq_lens = torch.from_numpy(np.array(seq_lens).astype(np.int32))- cpu_update_input = [{attr_name: seq_lens}]+ graphs = self._graphs[shape_key] - graph = self._graphs[shape_key]+ # Speculative / explicit update path: keep legacy inline semantics on+ # slot 0 and invalidate its arming since the new values are opaque.+ if cpu_update_input is not None:+ state = self._slot_state[shape_key][0]+ pending = state["thread"]+ if pending is not None:+ pending.join()+ state["thread"] = None+ graph = graphs[0] - def _update():- self._device_module.set_device(self._device_id)- graph.update(cpu_update_input=cpu_update_input)+ def _update():+ self._device_module.set_device(self._device_id)+ with self._update_lock:+ graph.update(cpu_update_input=cpu_update_input) - thread = threading.Thread(target=_update)- thread.start()- graph.replay()- thread.join()- return self._outputs[shape_key]+ thread = threading.Thread(target=_update, daemon=True)+ thread.start()+ graph.replay()+ thread.join()+ state["armed"] = None+ return self._outputs[shape_key][0]++ seq_lens_list = list(seq_lens)+ armed_key = tuple(int(v) for v in seq_lens_list)+ states = self._slot_state[shape_key]++ # Fast path: a slot is already armed with exactly these seq_lens and+ # its arming update has completed (armed is set after update returns).+ hit = -1+ for idx in range(len(graphs)):+ if states[idx]["armed"] == armed_key and states[idx]["thread"] is None:+ hit = idx+ break++ if hit >= 0:+ graph = graphs[hit]+ graph.replay()+ output = self._outputs[shape_key][hit]+ else:+ # Slow path: inline update on a slot whose pending background+ # update (if any) has been joined, then replay.+ hit = 0 if states[0]["armed"] is None else 1+ state = states[hit]+ pending = state["thread"]+ if pending is not None:+ pending.join()+ state["thread"] = None+ graph = graphs[hit]+ with self._update_lock:+ graph.update(+ cpu_update_input=[+ {+ attr_name: self._build_update_tensor(+ seq_lens_list, attr_type+ )+ }+ ]+ )+ graph.replay()+ state["armed"] = armed_key+ output = self._outputs[shape_key][hit]++ # Arm the other slot with the predicted next-step seq_lens. Decode+ # advances every live request by exactly one token per step; padded+ # slots stay 0. The prediction is only a hint — the next step's exact+ # comparison above guarantees correctness on any deviation.+ other = 1 - hit+ other_state = states[other]+ if other_state["thread"] is None:+ predicted = [v + 1 if v > 0 else 0 for v in seq_lens_list]+ self._issue_update_thread(+ shape_key,+ other,+ attr_name,+ self._build_update_tensor(predicted, attr_type),+ tuple(predicted),+ )++ return output def cleanup(self) -> None:+ for states in self._slot_state.values():+ for state in states:+ pending = state.get("thread")+ if pending is not None:+ pending.join()+ state["thread"] = None+ state["armed"] = None+ self._slot_state.clear() self._graphs.clear() self._outputs.clear() self._pool = None