Repository navigation
[Bugfix][Attention] Fix V masking for non-causal sliding-window attention - #65871
shiwanhang6868-arch wants to merge 1 commit into
Conversation
…tion Retain the union of valid physical query rows when sanitizing V. Add exact FP16/BF16 coverage for scalar and mixed causal windows. Co-authored-by: OpenAI Codex Signed-off-by: Wanhang Shi <shiwanhang6868@gmail.com>
|
Documentation preview: https://vllm--65871.org.readthedocs.build/en/65871/ |
|
👋 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. 🚀 |
| (dist < SLIDING_WINDOW) & right_mask_v, | ||
| ) | ||
| elif USE_CAUSAL: | ||
| sw_mask_v = dist < SLIDING_WINDOW |
There was a problem hiding this comment.
right_mask_v isn't defined in this branch, but it isn't used either. I'd suggest to assign (dist < SLIDING_WINDOW) & right_mask_v or dist < SLIDING_WINDOW to a variable depending on if USE_PER_SEQ_CAUSAL or not USE_CAUSAL and use that in the rest of the code. Then there is no branch where a variable remains un-declared.
Overview
Fix
TRITON_ATTNdiscarding Value columns still visible to later query rows in an ordinary non-causal sliding-window tile. Preserve the union of the valid physical query rows' windows.Claims
Validation
RED/GREEN Test Results
Official main tested in this submission phase:
5a2633f63dd81e132f05dd14b55878fbb2169154. Copy the new test to pristine baseline production, then run in each worktree with a compatible environment and that worktree's vLLM import path:Baseline numerical assertions:
The fixed run included all 24 new cases plus 27 existing neighboring cases:
The new test uses Q/K=0 and V=token index: every row has an analytic visible-interval mean. It covers query length 19/context 21, head 64/block 16, 2 KV heads, GQA 1/3/5/7, FP16/BF16, and causal/non-causal/mixed flags. Both sides use
atol=rtol=0.Numerical Correctness
LLM.generate(), actual ordinary non-causal SW callThe 90-case matrix covers selected FP16/BF16, head 64–256, GQA 1/2/3/4/5/7/8, queries through 513, block 16/32, remapped tables, strided KV/output and actual 2D/3D launches; it is not Cartesian coverage. Nondividing-GQA random cases use short queries to avoid conflating existing ownership bugs.
Public LLM validation used real serialized weights of a locally generated 701,828-parameter DiffusionGemma, seed 20261105, token IDs
[2,10,11,12], canvas 16/one denoising step, FP16/eager/TRITON_ATTN. An observer captured actual kernel inputs/outputs for FP32 comparison without replacing model computation. This checks execution and the requested ordinary window semantics, not pretrained-model accuracy or HF rectangular-mask parity. Original tensors and logs are retained locally, excluded from the commit.Earlier validation, not rerun for submission: 497 scheduler/KV CPU tests passed at 7dca18e (relevant core files unchanged); Qwen2.5-0.5B-Instruct controls completed 48 requests across four prefix/chunk settings on earlier baseline/fixed snapshots. These are not claimed as current or matched before/after model evaluation.
Performance Regression
Current GPU0 warm-cache microbenchmark: 128 launches/graph replay, 20 warmups, 31 alternating baseline/fixed pairs per configuration in one process; no tensor-capture observer or clock changes.
All batch 2/context 33. First two use block 16/W4; third block 16/W64; fourth block 32/W16. Baseline non-causal outputs are incorrect, so this compares cost rather than equivalent correct-work throughput. No material consistent regression observed in these four cases; no serving speedup or statistical-significance claim. Earlier noisy cross-process samples were preserved and are not used to claim improvement.
Hardware and Software Environment
W7900/gfx1100; Python 3.12.15, Torch 2.14.0+rocm7.2, Torch HIP 7.2.53211, host ROCm 7.2.4, Triton 3.8.0. Isolated worktrees/caches, explicit GPU bindings and timeouts. JIT source and worker extension hashes recorded. Same-Torch native extensions from 7ecc83a reused after checking relevant native cache/attention sources match. This is a locally verified development stack, not the official pinned ROCm CI stack. NVIDIA/MI300/XPU were not run locally.
Details
Root Cause
The score mask is per query row, but V sanitization is shared by the tile. Both old V window boundaries used its earliest query. Later rows could count a valid future key in softmax after its V was zeroed, corrupting results with finite, correctly addressed cache data.
Minimal Fix
For width W, the tile's union is
context + qlo - W < key < context + qhi + W, where:Retain the left boundary from qlo and derive the non-causal right boundary from qhi. The physical-row span handles GQA not dividing BLOCK_M; the existing per-row score mask remains authoritative. No host synchronization, API, cache layout or backend-priority changes. The diff adds one test to the existing suite and a short rendered backend note.
Current dispatch gates multi-query non-causal/per-sequence cases to 2D; 3D validation covers supported single-query non-causal cases and existing causal multi-query split-K tests. It does not claim enabled non-causal multi-query 3D dispatch. Existing L4 and MI300 attention CI steps select the test and depend on the changed directory; selection is not a passing CI result.
Related Issues / PRs
Refs #62828, #62415, #65830.
ROCM_ATTNreading non-finite evicted KV; closed after MRV2 block-table redirection in [Bugfix][V1] Null sliding-window block-table entries below the window #60767. This fixes valid future V being zeroed in a different kernel, still reproduced on current main.Open/closed searches, actual closest files patches and latest main were checked; no equivalent ordinary non-causal V-union fix found. Pre-existing multimodal/R-SWA/chunk combinations are outside scope.
AI Assistance Disclosure
OpenAI Codex assisted with investigation, implementation, test execution and review. The human submitter is responsible for reviewing and understanding every changed line and validating this contribution under vLLM's AI-assisted contribution policy. The commit includes AI attribution and the human submitter's authorized DCO signoff.
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.