Skip to content

[Bug]: SWA per-layer KV page-table staging can read overwritten host data #21385

Open

Description

@peter941221

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:

  1. Create a KVCacheManagerV2 with enable_swa_scratch_reuse=True.
  2. Add several dummy requests so the manager creates a non-trivial per-layer page table.
  3. Copy the page table once and synchronize to record a baseline result.
  4. Queue a long CUDA stream stall followed by copy_batch_block_offsets().
  5. Before the stream drains, overwrite host_kv_cache_block_offsets.
  6. 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

  1. added
    KV-Cache Management
    on Nov 1, 2026
  2. added 9 commits that reference this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    KV-Cache Management

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions