Inspect · Source & workspace
Requested workspace inspection and file and log inspection related to source & workspace.
1 call · #0127–#0127
echo <val>ls -l -a <val> <n> > <path>ls -l -a <path> <n> > <path>headKimi K3 · Serving
Repeated context 1dev · Implementation Optimization
01 / PROCESS MAP
Compare agents on one time axis; overlapping spans line up vertically. Select an agent or bar to inspect its events.
Time starts at the first recorded activity. Select a bar or agent to open its events. Bars span the first and last recorded observation, including gaps; colored ticks mark tool calls. A hollow diamond marks a delegation whose child timing is unavailable.
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>. Each branch belongs to its named agent. Expand a delegation to inspect its child; branches can run concurrently. Call numbers preserve source order, not a serial schedule. Times are relative to the first recorded activity.
Requested workspace inspection and file and log inspection related to source & workspace.
1 call · #0127–#0127
echo <val>ls -l -a <val> <n> > <path>ls -l -a <path> <n> > <path>headRequested file and log inspection and workspace inspection related to task requirements.
3 calls · #0128–#0130
Read <path>cd <val>ls -l -a <val> <val> <val> <val> <val> <path> <path>Requested file and log inspection related to runtime processes.
1 call · #0131–#0131
Read <path>Requested file and log inspection related to source & workspace.
1 call · #0132–#0132
Read <path>Requested file and log inspection related to benchmark & validation setup.
3 calls · #0133–#0135
Read <path>Requested file and log inspection related to source & workspace.
3 calls · #0136–#0138
Read <path>Requested file and log inspection related to task requirements.
3 calls · #0139–#0141
Read <path>Requested source searches and file and log inspection related to source & workspace.
4 calls · #0142–#0145
cd <val>grep -n <val> <path>head -n <n>sed -n <val> <path>Requested environment setup or inspection and source searches related to source & workspace.
1 call · #0146–#0146
envgrep -E <val>sortRequested file and log inspection related to source & workspace.
3 calls · #0147–#0149
cd <val>sed -n <val> <path>Read <path>Requested script or workload execution related to source & workspace.
1 call · #0150–#0150
which <val>python3 -c <script>Requested file and log inspection related to source & workspace.
2 calls · #0151–#0152
cd <val>sed -n <val> <path>Requested file and log inspection and script or workload execution related to task requirements.
1 call · #0153–#0153
cd <val>head -c <n> <path>echopython3 -c <script>Requested source searches, file and log inspection and repository inspection related to source & workspace.
2 calls · #0154–#0155
cd <val>grep -n <val> <path>head -n <n>cd <path>git log --oneline <flag> <args>catgit status <flag> <args>headls <path>Requested file and log inspection and runtime inspection related to device memory.
1 call · #0156–#0156
cat <path> <n> > <path>head -n <n>npu-smi info <n> > <path>trueRequested file and log inspection and source searches related to benchmark & validation setup.
3 calls · #0157–#0159
cd <val>sed -n <val> <path>grep -n <path> <path>head -n <n>Requested script or workload execution and file and log inspection related to source & workspace.
2 calls · #0160–#0161
cd <path>bash <script> > <path> <n> >& <path>echo <val>head -c <n> <path>cd <val>sed -n <val> <path>Requested environment setup or inspection and script or workload execution related to task requirements.
1 call · #0162–#0162
cd <path>env <vars> bash <script> > <path> <n> >& <path>echo <val>python3 -c <script>Requested script or workload execution related to benchmark & validation setup.
1 call · #0163–#0163
cd <path>bash <script> > <path> <n> >& <path>echo <val>Requested workspace inspection, file and log inspection and source searches related to attention kernels.
1 call · #0164–#0164
cd <path>ls <path> <path>head -n <n>grep -r -n <val> <path>Requested source searches and file and log inspection related to source & workspace.
1 call · #0165–#0165
cd <path>grep -r -n <val> <path>head -n <n>headRequested source searches, file and log inspection and workspace inspection related to attention kernels.
3 calls · #0166–#0168
cd <path>grep -r -n <val> <path>headgrep -r -l -n <val> <path>head -n <n>sed -n <val> <path>find <path> -name <path>python3 -c <script>ls <path> <path> <n> > <path>Requested source searches and file and log inspection related to runtime processes.
1 call · #0169–#0169
cd <path>grep -r -n <val> <path>head -n <n>grep -r -l -n <val> <path>headRequested workspace inspection, source searches and file and log inspection related to source & workspace.
1 call · #0170–#0170
cd <path>ls <path>grep -r -n <val> <path>headRequested file and log inspection and source searches related to runtime processes.
2 calls · #0171–#0172
cd <path>sed -n <val> <path>grep -n <val> <path>headgrep -i -n <val>Requested file and log inspection related to source & workspace.
1 call · #0173–#0173
cd <path>cat <path>head -n <n>Requested workspace inspection and file and log inspection related to benchmark & validation setup.
1 call · #0174–#0174
ls -l -a <path> <n> > <path>tail -n <n> <path> <n> > <path>Requested source searches and file and log inspection related to attention kernels.
1 call · #0175–#0175
grep -E <val> <path>head -n <n>Requested source searches and file and log inspection related to device memory.
1 call · #0176–#0176
grep -o <val> <path>head -n <n>grep -E <val> <path>Requested file and log inspection related to source & workspace.
1 call · #0177–#0177
Read task output <task>Requested task coordination related to batching & scheduling.
1 call · #0178–#0178
Delegate <task>Delegated by Main agent at call #0178. Observed activity +10:51–+36:43.
Requested file and log inspection related to batching & scheduling.
1 call · #0001–#0001
Read <path>Requested workspace inspection related to source & workspace.
2 calls · #0002–#0003
Find <pattern>Requested source searches and file and log inspection related to batching & scheduling.
3 calls · #0004–#0006
Search <pattern> <path>Read <path>Requested file and log inspection related to source & workspace.
1 call · #0007–#0007
Read <path>Requested source searches related to batching & scheduling.
1 call · #0008–#0008
Search <pattern> <path>Requested source searches related to source & workspace.
2 calls · #0009–#0010
Search <pattern> <path>Requested file and log inspection related to batching & scheduling.
1 call · #0011–#0011
Read <path>Requested file and log inspection related to source & workspace.
1 call · #0012–#0012
Read <path>Requested file and log inspection related to batching & scheduling.
1 call · #0013–#0013
Read <path>Requested file and log inspection related to source & workspace.
1 call · #0014–#0014
Read <path>Requested file and log inspection related to batching & scheduling.
2 calls · #0015–#0016
Read <path>Requested file and log inspection and workspace inspection related to source & workspace.
6 calls · #0017–#0022
Read <path>Find <pattern>ls <path> <path> <n> > <path>Requested source searches related to data movement.
2 calls · #0023–#0024
Search <pattern> <path>Requested file and log inspection related to source & workspace.
2 calls · #0025–#0026
Read <path>Requested source searches related to device memory.
1 call · #0027–#0027
Search <pattern> <path>Requested source searches and file and log inspection related to source & workspace.
3 calls · #0028–#0030
Search <pattern> <path>Read <path>Requested file and log inspection and source searches related to attention kernels.
8 calls · #0031–#0038
wc -l <path> <path> <path> <path>Search <pattern> <path>Read <path>Requested file and log inspection related to source & workspace.
1 call · #0039–#0039
Read <path>Requested source searches related to runtime processes.
1 call · #0040–#0040
Search <pattern> <path>Requested source searches and file and log inspection related to source & workspace.
9 calls · #0041–#0049
Search <pattern> <path>Read <path>Requested source searches related to kv-cache management.
1 call · #0050–#0050
Search <pattern> <path>Requested file and log inspection and source searches related to source & workspace.
4 calls · #0051–#0054
Read <path>Search <pattern> <path>Requested source searches related to batching & scheduling.
1 call · #0055–#0055
Search <pattern> <path>Requested source searches and file and log inspection related to device memory.
3 calls · #0056–#0058
Search <pattern> <path>Read <path>Requested file and log inspection related to batching & scheduling.
2 calls · #0059–#0060
Read <path>Requested file and log inspection and source searches related to source & workspace.
8 calls · #0061–#0068
Read <path>Search <pattern> <path>Requested source searches and file and log inspection related to batching & scheduling.
5 calls · #0069–#0073
Search <pattern> <path>Read <path>Requested file and log inspection related to source & workspace.
1 call · #0074–#0074
Read <path>Requested file and log inspection related to batching & scheduling.
1 call · #0075–#0075
Read <path>Requested source searches related to device memory.
1 call · #0076–#0076
Search <pattern> <path>Requested file and log inspection related to source & workspace.
3 calls · #0077–#0079
Read <path>Requested source searches and file and log inspection related to prefix caching.
2 calls · #0080–#0081
Search <pattern> <path>Read <path>Requested source searches and workspace inspection related to source & workspace.
2 calls · #0082–#0083
Search <pattern> <path>ls <path>Requested source searches and file and log inspection related to device memory.
3 calls · #0084–#0086
Search <pattern> <path>Read <path>Requested source searches related to prefix caching.
1 call · #0087–#0087
Search <pattern> <path>Requested file and log inspection and source searches related to source & workspace.
2 calls · #0088–#0089
Read <path>Search <pattern> <path>Requested source searches related to runtime processes.
1 call · #0090–#0090
Search <pattern> <path>Requested source searches related to device memory.
1 call · #0091–#0091
Search <pattern> <path>Requested source searches related to source & workspace.
1 call · #0092–#0092
Search <pattern> <path>Requested file and log inspection related to device memory.
1 call · #0093–#0093
Read <path>Requested source searches and file and log inspection related to source & workspace.
5 calls · #0094–#0098
Search <pattern> <path>Read <path>Requested source searches and file and log inspection related to batching & scheduling.
2 calls · #0099–#0100
Search <pattern> <path>Read <path>Requested file and log inspection and source searches related to source & workspace.
3 calls · #0101–#0103
Read <path>Search <pattern> <path>Requested source searches related to device memory.
1 call · #0104–#0104
Search <pattern> <path>Requested file and log inspection, workspace inspection and source searches related to source & workspace.
7 calls · #0105–#0111
Read <path>Find <pattern>ls <path>Search <pattern> <path>Requested source searches related to runtime processes.
1 call · #0112–#0112
Search <pattern> <path>Requested source searches related to batching & scheduling.
1 call · #0113–#0113
Search <pattern> <path>Requested file and log inspection related to source & workspace.
4 calls · #0114–#0117
Read <path>Requested source searches and file and log inspection related to batching & scheduling.
4 calls · #0118–#0121
Search <pattern> <path>Read <path>Requested source searches related to runtime processes.
1 call · #0122–#0122
Search <pattern> <path>Requested source searches related to batching & scheduling.
1 call · #0123–#0123
Search <pattern> <path>Requested file and log inspection related to runtime processes.
1 call · #0124–#0124
Read <path>Requested source searches related to source & workspace.
1 call · #0125–#0125
Search <pattern> <path>Requested file and log inspection related to batching & scheduling.
1 call · #0126–#0126
Read <path>Requested file and log inspection, script or workload execution and workspace file updates related to benchmark & validation setup.
2 calls · #0179–#0180
cat <path>python3 -c <script>mkdir -p <path>cp <path> <path>cp <path> <path> <n> > <path>ls <path>Requested script or workload execution related to benchmark & validation setup.
1 call · #0181–#0181
cd <path>bash <script> > <path> <n> >& <path>echo <val>Requested file and log inspection and source searches related to source & workspace.
6 calls · #0182–#0187
cd <path>sed -n <val> <path>grep -n <val> <path>headRequested file and log inspection and source searches related to device memory.
1 call · #0188–#0188
cd <path>sed -n <val> <path>grep -n <val> <path>Requested script or workload execution related to device memory.
1 call · #0189–#0189
python3 - <script>Requested workspace inspection, source searches and file and log inspection related to benchmark & validation setup.
1 call · #0190–#0190
ls -l -a <path>grep -v <val>tail -n <n> <path> <n> > <path>Requested source searches, file and log inspection and script or workload execution related to source & workspace.
2 calls · #0191–#0192
grep -E <val> <path>headpython3 -c <script>cd <val>sed -n <val> <path>Requested file and log inspection related to attention kernels.
1 call · #0193–#0193
cd <path>sed -n <val> <path>Requested file and log inspection and workspace inspection related to source & workspace.
2 calls · #0194–#0195
cd <path>sed -n <val> <path> <n> > <path>find <path> -name <path>headsed -n <val> <path>Requested file and log inspection related to attention kernels.
1 call · #0196–#0196
cd <path>sed -n <val> <path>Requested file and log inspection related to batching & scheduling.
1 call · #0197–#0197
cd <path>sed -n <val> <path>Requested file and log inspection and source searches related to device memory.
2 calls · #0198–#0199
cd <path>sed -n <val> <path>grep -n <val> <path>headRequested workspace inspection, file and log inspection and source searches related to source & workspace.
1 call · #0200–#0200
cd <path>ls <path>head -n <n>grep -r -n <val> <path>headRequested file and log inspection and source searches related to device memory.
1 call · #0201–#0201
cd <path>sed -n <val> <path>grep -r -n <val> <path>Requested file and log inspection, source searches and workspace inspection related to source & workspace.
5 calls · #0202–#0206
cd <path>sed -n <val> <path>grep -n <val> <path>headls <val>grep -E <val>tail -n <n> <path> <n> > <path>tail -n <n><command> <args>tail -n <n> <path>Requested source searches and file and log inspection related to batching & scheduling.
1 call · #0207–#0207
grep <val> <path>tail -n <n>echo <flag>Requested execution waits, workspace inspection and source searches related to benchmark & validation setup.
2 calls · #0208–#0209
sleep <n>ls <val>grep <val>tail -n <n> <path> <n> > <path>python3 -c <script>cp <path> <path>Requested file and log inspection and source searches related to source & workspace.
6 calls · #0210–#0215
cd <path>sed -n <val> <path>grep -r -n <val> <path>headgrep -r -n <val> <path> <n> > <path>grep -n <val> <path>sed -n <val>head -n <n>Requested script or workload execution related to device memory.
1 call · #0216–#0216
cd <path>timeout <n> <val> <val> <script>Requested source searches and file and log inspection related to source & workspace.
1 call · #0217–#0217
cd <path>grep -n <val> <path>sed -n <path> <path>Requested file and log inspection and source searches related to dependencies & build setup.
1 call · #0218–#0218
cd <path>sed -n <val> <path>grep -r -n <val> <path>headgrep -r -n <val> <path> <path> <n> > <path>Requested script or workload execution, file and log inspection and source searches related to device memory.
2 calls · #0219–#0220
cd <path>python3 -c <script> <n> >& <path>tail -n <n>grep -r -n <val> <path> --include <path>grep -v <val>headgrep -n <val> <path>sed -n <path> <path>Requested file and log inspection related to source & workspace.
1 call · #0221–#0221
Read <path>Requested code edits related to source & workspace.
1 call · #0222–#0222
Edit <path>Requested code edits related to device memory.
1 call · #0223–#0223
Edit <path>Requested file and log inspection related to device memory.
1 call · #0224–#0224
Read <path>Requested code edits related to device memory.
1 call · #0225–#0225
Edit <path>Requested file and log inspection related to attention kernels.
1 call · #0226–#0226
Read <path>Requested code edits related to attention kernels.
2 calls · #0227–#0228
Edit <path>Requested file and log inspection related to attention kernels.
1 call · #0229–#0229
Read <path>Requested code edits related to attention kernels.
1 call · #0230–#0230
Edit <path>Requested file and log inspection related to source & workspace.
1 call · #0231–#0231
Read <path>Requested code edits related to source & workspace.
1 call · #0232–#0232
Edit <path>Requested file and log inspection related to source & workspace.
1 call · #0233–#0233
cd <path>sed -n <val> <path>Requested script or workload execution related to attention kernels.
1 call · #0234–#0234
cd <path>python3 -m <module> <script> <script> <script> <script>echo <val>Requested code edits related to source & workspace.
1 call · #0235–#0235
Write <path>Requested workspace file updates, script or workload execution and file and log inspection related to task requirements.
1 call · #0236–#0236
chmod <val> <path>cd <path>bash <script> <path> <n> <val> <n> >& <path>tail -n <n>Requested file and log inspection related to batching & scheduling.
2 calls · #0237–#0238
cd <path>sed -n <val> <path>Requested file and log inspection related to source & workspace.
1 call · #0239–#0239
Read task output <task>Requested source searches and file and log inspection related to source & workspace.
1 call · #0240–#0240
cd <path>grep -n <val> <path> <path>grep -v <val>head -n <n>Requested code edits related to source & workspace.
1 call · #0241–#0241
Edit <path>Requested script or workload execution and file and log inspection related to runtime processes.
1 call · #0242–#0242
cd <path>python3 -m <module> <script>echo <val>tail -n <n> <path> <n> > <path>Requested execution waits related to source & workspace.
1 call · #0243–#0243
Wait for <task>Requested file and log inspection and workspace inspection related to runtime processes.
1 call · #0244–#0244
tail -n <n> <path>ls -l -a <path> <n> > <path>Requested workspace inspection, runtime inspection and source searches related to device memory.
1 call · #0245–#0245
datestat -c <val> <path>ps <val>grep -E <val>grep -v <val>awk <val>headnpu-smi infohead -n <n>Requested file and log inspection and source searches related to source & workspace.
2 calls · #0246–#0247
which <val><command> <args>head -n <n>echo <val>grep <flag> <args>sed -n <val> <path>Requested source searches and file and log inspection related to batching & scheduling.
1 call · #0248–#0248
grep -i -E <val> <path>tail -n <n>echo <val>grep <flag> <args>grep -E <val> <path>Requested task coordination related to source & workspace.
1 call · #0249–#0249
Stop task <task>Requested process termination, execution waits and runtime inspection related to device memory.
2 calls · #0250–#0251
pkill -f <val>sleep <n>ps <val>grep -E <val>grep -v <val>head -n <n>npu-smi infogrep <val>awk <val>npu-smi info <n> > <path>Requested file and log inspection related to attention kernels.
1 call · #0252–#0252
cd <path>sed -n <val> <path>Requested code edits related to source & workspace.
1 call · #0253–#0253
Edit <path>Requested script or workload execution and file and log inspection related to task requirements.
1 call · #0254–#0254
cd <path>python3 -m <module> <script>bash <script> <path> <n> <val> <n> >& <path>tail -n <n>Requested source searches and file and log inspection related to data movement.
1 call · #0255–#0255
cd <path>grep -n <val> <path>headgrep -n <val> -A <n> <path>head -n <n>Requested file and log inspection, workspace inspection and runtime inspection related to device memory.
1 call · #0256–#0256
datetail -n <n> <path> <n> > <path>ls <path> <n> > <path>npu-smi info <n> > <path>grep <val>Requested execution waits related to source & workspace.
1 call · #0257–#0257
Wait for <task>Requested script or workload execution, source searches and file and log inspection related to runtime processes.
1 call · #0258–#0258
python3 -c <script>grep -E <val> <path>tail -n <n>Requested script or workload execution related to benchmark & validation setup.
1 call · #0259–#0259
cd <path>bash <script> > <path> <n> >& <path>echo <val>python3 -c <script>Requested repository inspection related to source & workspace.
1 call · #0260–#0260
cd <path>git diff --statgit diffRequested file and log inspection and execution waits related to source & workspace.
2 calls · #0261–#0262
Read task output <task>Wait for <task>Requested script or workload execution related to benchmark & validation setup.
1 call · #0263–#0263
cd <path>bash <script> > <path> <n> >& <path>echo <val>Requested execution waits, workspace inspection and source searches related to source & workspace.
1 call · #0264–#0264
sleep <n>datels <val>grep -E <val>tailtail -n <n> <path> <n> > <path>cut <flag>Requested execution waits related to source & workspace.
1 call · #0265–#0265
sleep <n>date<command> <args>Requested execution waits and file and log inspection related to benchmark & validation setup.
1 call · #0266–#0266
sleep <n>date<command> <args>tail -n <n> <path> <n> > <path>tail -n <n>cut <flag>Requested execution waits related to source & workspace.
1 call · #0267–#0267
Wait for <task>Requested script or workload execution and workspace file updates related to benchmark & validation setup.
1 call · #0268–#0268
python3 -c <script>cp <path> <path>Requested script or workload execution, file and log inspection and runtime inspection related to device memory.
1 call · #0269–#0269
bash <script> <n> >& <path>tail -n <n>ps <val>grep -E <val>grep -v <val>wc -lnpu-smi info <n> > <path>cd <path>git status <flag>Requested workspace file updates related to source & workspace.
1 call · #0270–#0270
rm -f <path> <path>echo <val>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
@@ -41,11 +41,14 @@ class NPUPagedTokenToKVPoolAllocator(PagedTokenToKVPoolAllocator): ) if num_new_pages is None:- num_new_pages_tensor = (- (seq_lens + self.roundup) // self.page_size- - (prefix_lens + self.roundup) // self.page_size- ).sum()- num_new_pages_item = num_new_pages_tensor.item()+ # Compute on the host mirrors instead: a device reduction read+ # back with .item() blocks the schedule thread until all queued+ # forward work drains.+ num_new_pages_item = get_num_new_pages(+ seq_lens=seq_lens_cpu,+ page_size=self.page_size,+ prefix_lens=prefix_lens_cpu,+ ) else: num_new_pages_item = num_new_pages if self.need_sort and num_new_pages_item > len(self.free_pages):@@ -430,7 +430,12 @@ class AscendAttnBackend(AttentionBackend): def init_forward_metadata(self, forward_batch: ForwardBatch): """Init the metadata for a forward pass.""" self.forward_metadata = ForwardMetadata()- seq_lens_max = forward_batch.seq_lens.max()+ # Read the max from the host mirror: using the device tensor as a+ # slice bound forces a blocking D2H sync on every forward.+ if forward_batch.seq_lens_cpu is not None:+ seq_lens_max = forward_batch.seq_lens_cpu.max()+ else:+ seq_lens_max = forward_batch.seq_lens.max() if forward_batch.forward_mode.is_target_verify(): seq_lens_max += self.speculative_num_draft_tokens elif (@@ -459,9 +464,21 @@ 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:+ # Host mirror avoids a blocking D2H sync per prefill forward.+ extend_seq_lens_cpu = forward_batch.extend_seq_lens_cpu+ if isinstance(extend_seq_lens_cpu, torch.Tensor):+ self.forward_metadata.extend_seq_lens_cpu_int = (+ extend_seq_lens_cpu.to(torch.int32)+ )+ else:+ self.forward_metadata.extend_seq_lens_cpu_int = torch.tensor(+ 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:@@ -27,12 +27,51 @@ if TYPE_CHECKING: logger = logging.getLogger(__name__) +# Pinned host buffers for NPU D2H relay, ringed per (dtype, shape) so a later+# enqueue never overwrites a slot an earlier consumer may still be reading.+_NPU_D2H_RING_DEPTH = 4+_npu_d2h_rings: dict = {}+++def _async_d2h_npu(t: torch.Tensor) -> torch.Tensor:+ """On NPU a D2H into pageable memory blocks the caller until the copy+ stream drains (no staging through registered host memory), which defeats+ overlap scheduling. Pinned destinations make the copy truly asynchronous."""+ key = (t.dtype, tuple(t.shape))+ ring = _npu_d2h_rings.get(key)+ if ring is None:+ ring = {+ "bufs": [+ torch.empty(t.shape, dtype=t.dtype, pin_memory=True)+ for _ in range(_NPU_D2H_RING_DEPTH)+ ],+ "idx": 0,+ }+ _npu_d2h_rings[key] = ring+ bufs = ring["bufs"]+ cpu_t = bufs[ring["idx"]]+ ring["idx"] = (ring["idx"] + 1) % _NPU_D2H_RING_DEPTH+ cpu_t.copy_(t, non_blocking=True)+ try:+ t.record_stream(torch.npu.current_stream(t.device))+ except (AttributeError, RuntimeError):+ pass+ # Belt-and-braces lifetime guard: keep the device source alive until the+ # consumer (next iteration, after copy_done.synchronize()) releases cpu_t,+ # so the caching allocator cannot recycle the source while the copy stream+ # may still be reading it.+ cpu_t._d2h_src = t+ return cpu_t++ def _async_d2h(t: torch.Tensor) -> torch.Tensor: """Async D2H copy for overlap scheduling. On CUDA the dest is pinned (a D2H to pageable host memory blocks the caller until done) and record_stream keeps the source alive until the copy stream drains, so the caching allocator can't recycle it early. Non-CUDA falls back to a plain copy.""" if not t.is_cuda:+ if t.device.type == "npu":+ return _async_d2h_npu(t) return t.to("cpu", non_blocking=True) cpu_t = torch.empty(t.shape, dtype=t.dtype, pin_memory=True) cpu_t.copy_(t, non_blocking=True)