Repository navigation
Description
System Info
- GPU: NVIDIA GeForce RTX 5090, 32 GB, SM120
- OS: Ubuntu under WSL2
- TensorRT-LLM commit: 5d86481
- Installed validation build: TensorRT-LLM 1.3.0rc28
- CUDA: 13.0
- PyTorch: 2.10.0+cu130
- Configuration: enable_swa_scratch_reuse=True
Reproduction
The SWA per-layer path in KVCacheManagerV2 uses persistent host staging tensors as sources for asynchronous device copies:
- copy_idx is copied with non_blocking=True;
- host scratch metadata is copied with non_blocking=True;
- host_kv_cache_block_offsets is copied with non_blocking=True.
The following sequence reproduces the page-table variant:
- Create a KVCacheManagerV2 with enable_swa_scratch_reuse=True.
- Add several dummy requests so the manager creates a non-trivial per-layer page table.
- Copy the page table once and synchronize to record a baseline result.
- Queue a long CUDA stream stall followed by copy_batch_block_offsets().
- Before the stream drains, overwrite host_kv_cache_block_offsets.
- Synchronize and compare the result with the baseline.
The asynchronous copy can read the host source after it has been overwritten. The GPU therefore receives page-table data from a later host state instead of the state associated with the queued operation.
Observed on RTX 5090:
- Baseline checksum: 3048
- Five control copies: all matched the baseline
- Five raced copies: all mismatched
- Raced checksums: 597333024, 597333792, 597334560, 597335328, 597336096
The same harness passes when the persistent page table is snapshotted into a fresh pinned host buffer before the asynchronous copy; the output checksum returns to 3048.
Expected behavior
Each call to copy_batch_block_offsets() should consume a stable snapshot of its page table, copy index, and scratch metadata inputs, even when the overlap scheduler queues the next iteration before the previous CUDA work has drained.
Actual behavior
The SWA per-layer path reuses persistent host staging buffers while their non-blocking device copies may still be pending. This can silently produce incorrect per-layer KV block offsets and cause attention to read the wrong physical KV pages.
Additional notes
PR #16088 fixed the analogous default V2 block-offset path and explicitly identified the enable_swa_scratch_reuse per-layer path as a separate follow-up. This report covers that remaining path.
The failure is a correctness issue rather than a performance-only issue: the operation completes, but the resulting page table can describe a different host state.
Activity
[NVIDIA#21385][style] Format SWA staging copy
[NVIDIA#21385][test] Cover all SWA staging inputs
[NVIDIA#21385][test] Cover all SWA staging inputs
[NVIDIA#21385][test] Cover all SWA staging inputs
[NVIDIA#21385][test] Cover all SWA staging races
[NVIDIA#21385][test] Cover all SWA staging races
[NVIDIA#21385][test] Assert SWA scratch offsets
[NVIDIA#21385][style] Format SWA scratch assertions
[NVIDIA#21385][test] Cover concurrent SWA staging copies