Repository navigation
[Bugfix][Test] Rotate KV into RHT domain in the INT4 unified attn test - #62881
Conversation
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment Once the PR is approved or has the If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
|
This pull request has merge conflicts that must be resolved before it can be |
dcd2061 to
1ce3e15
Compare
jikunshang
left a comment
There was a problem hiding this comment.
LGTM. as long as CI can pass.
|
/ci run |
|
❌ This PR is 551 commits behind upstream |
|
/ci run |
|
❌ This PR is 555 commits behind upstream |
…ntion test test_triton_unified_attention_per_token_head_scale filled the INT4 cache with unrotated K/V. unified_attention_int4 assumes the cache holds RHT-rotated data, as written by reshape_and_cache_int4: it rotates Q and inverse-rotates the output. The kernel output was therefore uncorrelated with the reference. The test passed only while every element stayed within atol=rtol=0.5, and failed on 1-2 elements for some seeds and platforms. This is why Hopper needed atol=1.1 and Intel CI deselected the int4 seq_lens1 case. Rotate K/V with single_rht before the asymmetric quantization, and inverse-rotate the dequantized reference back to the original domain, like the other INT4 tests in this file. Both runs now see the same KV, so INT4 uses the same 5e-2 tolerance as INT8/FP8. Drop the Hopper special case and the Intel CI deselect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Dudi Lester <dudi.lester@intel.com>
7e6869b to
7f88221
Compare
|
/ci run |
|
✅ Triggered Buildkite CI #99919 for commit |
Overview
Fix the INT4 case of
test_triton_unified_attention_per_token_head_scale. It filled the INT4 cache with unrotated K/V and compared the result against a reference that didn't match whatunified_attention_int4computes. The test now writes the cache in the RHT domain, likereshape_and_cache_int4, so it actually checks the INT4 attention kernel.Follow-up to #40835. Removes the Intel CI deselect of
[int4-16-128-num_heads0-seq_lens1]. Downstream report: intel/intel-xpu-backend-for-triton#8358.Not a duplicate: no open PR or issue fixes this test. #62113 edits the same test but keeps the INT4 reference as is and widens the Intel deselect to two INT4 cases. See Details for how the two PRs combine.
Claims
atol=rtol=5e-2as INT8/FP8, down from 0.5. This also removes the Hopper-onlyatol=1.1.Validation
Test commands run:
Results:
main(e9cc624) with this PR: all 82 tests in the file pass. Before the fix,seq_lens1fails:Mismatched elements: 2 / 1024, Greatest absolute difference: 1.086 (up to 0.5 allowed), Greatest relative difference: 1.0.fp8e4nv not supported in this architecture(Ampere has no e4m3). This is unrelated to this PR.[(4, 128), (4, 97)]INT4 case and bothseq_threshold_3Dvalues, with neither of [Perf][Attention] 16-byte-align per-token-head KV slots so Triton vectorizes loads #62113's two INT4 deselects. [Perf][Attention] 16-byte-align per-token-head KV slots so Triton vectorizes loads #62113 alone fails exactly the two INT4 cases it deselects.ruff check,ruff format --checkandtypospass.CI coverage:
hadacoreRHT path.Not validated locally:
hadacorepath. On the RTX 3060 Ti the RHT ran through the Triton Hadamard kernel; the H200 job above covers both.Details
Root cause.
reshape_and_cache_int4storesK_s = H·D·k(RHT, withH·H = d·I,D·D = I).unified_attention_int4relies on that layout:q' = H·D·qand usessoftmax_scale / d, soq'·K_s / d = q·k;D·H(·) / dto the output, which undoes the rotation of V.The test wrote unrotated
k,vinto the cache. As a result the kernel attended overD·H·k / dandD·H·v / d. Those entries have std ≈ 1/√128, sooutput_q ≈ 0, which is uncorrelated withoutput_ref.The check
|out_q − ref| ≤ 0.5 + 0.5·|ref|then reduces to roughly|ref| ≤ 1:refstd ≈ 0.15) almost always passes;refstd ≈ 0.25–0.3) fails on 1–2 elements whenever a|ref|tail exceeds 1.That explains the reported abs diff just above 1.0 and relative diff of exactly 1.0. The failure is deterministic per seed but differs across platforms because their RNG streams differ, hence the Hopper
atol=1.1and the Intel deselect.Fix. Rotate K/V with
single_rht(rounding through bf16, likereshape_and_cache_int4) before quantizing. Then inverse-rotate the dequantized reference back to the original domain, astest_reshape_and_cache_per_token_headandtest_per_token_head_round_trip_accuracyalready do. The original-domain values stay around N(0,1), so the reference attention is still meaningful.Tolerance. The remaining error comes from bf16 rounding and accumulation order only. The worst case is 0.021 over 200 seeds on CUDA, 2.4× under 5e-2. CUDA's error is larger than XPU's because the Triton Hadamard path rotates in bf16. The reference divides by
head_size, which equalslargest_power_of_2_divisor(head_size)for the parametrizedhead_size=128, consistent with the rest of the file.Interaction with #62113. The two PRs only conflict textually, on adjacent lines:
Whichever PR merges second should keep that assert and drop all
test_triton_unified_attention_per_token_head_scale[int4-*]deselects.AI assistance (Claude Code) was used to investigate, write and validate this change. I reviewed every changed line and the validation results.
Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.