[Bugfix][QSA] Clamp metadata token counts for graph padding - #680
Merged
yangzhuxinyzx merged 2 commits intoSep 25, 2026
Merged
Conversation
Adapt the mapped-token clamp from vllm-project/vllm#58040 to the 1Cat QSA metadata builders. Bound both Torch position construction and Triton mapped-token reads by num_actual_tokens. Add decode/verify metadata regressions for plain, compressed and circular caches with real CommonAttentionMetadata request mapping, unpadded controls, and output guards. CUDA execution remains pending. Upstream-reference: vllm-project/vllm#58040 Co-authored-by: shaopeng-666 <217884671+shaopeng-666@users.noreply.github.com> Assisted-by: OpenAI Codex Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
Exercise capture and repeated replay for decode and verify-shaped metadata, including a sequence-length update and output guards. Assisted-by: OpenAI Codex Signed-off-by: Leonccaa <166551845+Leonccaa@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Graph-padding requests can make
query_start_loc_cpu[-1]exceednum_actual_tokens. QSA's Torch builder then constructs logical positions beyond its output view; the Triton compressed-cache path can read beyond the real slot-mapping input. Clamp the mapped-token count tomin(query_end, num_actual_tokens)in both builders.Adapted from vllm-project/vllm#58040, at
645c156e3163a0a55a3057bd9844fe9a765e0dc0, with upstream author attribution preserved in the commit. This backport retains 1Cat's three-output metadata interface. The source PR targets vLLM; this PR targets 1CatAI. Searches of open 1CatAI PRs for58040,metadata padding, andQSAfound no equivalent clamp. #647 addresses a different grouped-page4 null-block/NaN path. Fork review: Leonccaa/1Cat-vLLM#20.The regression uses real
CommonAttentionMetadataand request mapping. It covers Torch/Triton, one-token decode/four-token verify-shaped inputs, zero/three padding requests, and plain/compressed/circular slot mapping. CUDA cases capture a graph, replay three times, update sequence lengths and replay again, checking exact metadata and output guards. Mapping backing capacity still includes padded offsets, as required by the existing helper.Test Plan
# In the source checkout and project virtual environment: python -m pytest tests/models/qwen4_exp/test_qsa_metadata_padding.py -q --tb=short pre-commit run --files vllm/models/qwen4_exp/common/qsa_cache.py tests/models/qwen4_exp/test_qsa_metadata_padding.py git diff --checkGPU supplemental validation used four V100 32 GB GPUs and the existing deployment image at
b4fef533ec, with this PR's exactqsa_cache.pymounted read-only (SHA256e1065b0f5e1f2a7015e3200c21739edb98114f7b79e96ab63833b47615b19bf0). It is not a full rebuild of current upstream main. Local harness paths below are validation artifacts, not added repository files:Test Result
git diff --check: passed.Exact token matches across nine requests per round:
FP16 varies even without switching the builder. The E4M3 mismatch is unresolved (batch size 4, backup-explanation prompt, first difference at output token index 2). No cause is asserted for that mismatch. The successful exit of the supplemental three-round harness means the runs completed and results were recorded; it does not mean numerical parity passed. This PR is ready for review; the validation limits above remain applicable.
Validation limits: graph/eager outputs were token-identical for only 4/9 requests per KV type, so full-model graph/eager token parity is not established. All recorded full-model metadata shapes had
query_end <= num_actual_tokens; the failing padding boundary is reproduced by the dedicated metadata/memcheck tests, not by the full-model runs. The baseline model A/B guards against the unsafe boundary and swaps the host metadata builder after initial graph capture; it is not a separately recaptured unpatched full-model run. These results do not attribute historical hangs or output changes to this bug, or make a performance or model-quality claim.AI assistance: OpenAI Codex adapted the patch, authored regression coverage and ran validation. Human review remains pending; no merge or resident deployment of this patch is requested.