Repository navigation
[Fix] dsa-eagle-topk: Copy token keys and scales when relocating index cache - #44564
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f93beaadca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Each physical page stores all key bytes followed by all scale bytes. | ||
| # Locations identify tokens; copying whole pages overwrites neighbors. | ||
| for part in (index_k[:, :key_bytes], index_k[:, key_bytes:]): | ||
| tokens = part.view(index_k.shape[0], page_size, -1) |
There was a problem hiding this comment.
Honor the ROCm preshuffle layout when moving keys
On ROCm with SGLANG_USE_AITER=1 and aiter_can_use_preshuffle_paged_mqa() enabled, index keys are not token-major: _set_k_and_s_triton_kernel stores each 16x16 tile using the offsets in python/sglang/kernels/ops/attention/dsa/index_buf_accessor.py:387-399. Consequently this view makes each apparent token row contain pieces from multiple real tokens, so a branching speculative relocation silently copies mixed key bytes while copying one token's scale; use layout-aware offsets (or gather and re-store) for this path.
Useful? React with 👍 / 👎.
|
/rerun-test test/registered/kernels/ops/kvcache/test_dsa_index_cache_move.py |
|
/rerun-failed-ci |
|
🚀 |
| for actual, expected in zip(pool.kv_buffer, original_kv, strict=True): | ||
| expected[target] = expected[source] | ||
| torch.testing.assert_close(actual, expected, rtol=0, atol=0) | ||
| assert pool.index_key_cache.buffer[1].shape[0] == 0 |
There was a problem hiding this comment.
add if __name__ == "__main__": sys.exit(pytest.main([__file__, "-v", "-s"])), without it collect_tests rejects the file and base-a-test-cpu fails on every shard.
There was a problem hiding this comment.
Done in 99556e9. Added if __name__ == "__main__": sys.exit(pytest.main([__file__, "-v", "-s"])) and the sys import. Confirmed collect_tests accepts the file.
-Robot
| index_k = self._kernel_view(index_k) | ||
| # Each physical page stores all key bytes followed by all scale bytes. | ||
| # Locations identify tokens; copying whole pages overwrites neighbors. | ||
| for part in (index_k[:, :key_bytes], index_k[:, key_bytes:]): |
There was a problem hiding this comment.
this assumes a token's key bytes are contiguous in the page, which is false on the aiter preshuffle layout. moves the wrong bytes and clobbers the rest of the tile.
There was a problem hiding this comment.
Fixed in 99556e9. Relocation now respects the AITER 16×16 preshuffled key layout and copies token scales separately. All 12 CPU layout cases and three GB300 cache tests pass. The four nonempty preshuffled cases failed before the fix. AMD hardware was not tested.
-Robot
This comment has been minimized.
This comment has been minimized.
|
/rerun-failed-ci |
Fix for dsa with speculative_eagle_topk=2
Motivation
DSATokenToKVPool.move_kv_cachepasses token-slot IDs toIndexKeyCache.move, but that method indexes its page buffer with them. With 64-token pages, slot 319 is page 4, offset 63; treating it as page 319 can access out of bounds. Small IDs that fit in the page dimension silently copy entire pages and overwrite unrelated keys.This matters when speculative decoding relocates accepted tree tokens. The ordinary single-chain (
speculative_eagle_topk=1) path skips that compaction.Modifications
Move each selected token's FP8 index key and scale within the physical-page view used by the cache writers and readers. Advanced-index gathering before assignment preserves overlapping swaps. Layers that reuse another layer's indexer remain skipped.
Nonempty moves with pooled index keys (
index_kpool > 1) now fail explicitly: relocating individual tokens would require rebuilding their pooled keys.Accuracy Tests
On upstream main
87211088c98ae4f5b60625eebcce007db36aa6af, the new small-ID regression fails: swapping slots 1 and 2 corrupts neighboring keys without a CUDA error. With this patch, all three GPU cases pass on one GB300:The tests use a real DSA pool and its production key/scale writers and readers, checking exact key bytes, scales, unchanged neighbors, latent KV, and a layer that reuses another layer's indexer.
python -m pytest -q test/registered/kernels/ops/kvcache/test_dsa_index_cache_move.py # 3 passedThese are cache correctness tests; no full-model branching-speculation accuracy run was performed for this PR.
Speed Tests and Profiling
Correctness fix; no performance claim or benchmark.
Checklist
CI States
Latest PR Test (Base): ❌ Run #39139492033
Latest PR Test (Extra): ✅ Run #39139492003
Latest PR Test (AMD ROCm 10): ❌ Run #39139492084