[Bugfix][Attention] Ignore empty MLA context chunks during merge - #49294
Merged
MatthewBonanni merged 18 commits intoJul 22, 2026
Merged
Conversation
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
LucasWilkinson
marked this pull request as ready for review
July 21, 2026 12:17
LucasWilkinson
requested review from
AndreasKaratzas,
MatthewBonanni,
WoosukKwon,
mgoin,
tlrmchlsmth,
yewentao256 and
zyongye
as code owners
July 21, 2026 12:17
This was referenced Jul 21, 2026
MatthewBonanni
enabled auto-merge (squash)
July 21, 2026 14:23
MatthewBonanni
disabled auto-merge
July 21, 2026 14:23
MatthewBonanni
enabled auto-merge (squash)
July 21, 2026 14:24
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
1 task
An empty context chunk covers no keys for its query, so the backend (e.g. TRTLLM_RAGGED) leaves the attention output rows uninitialized even while reporting an LSE of -inf; merging then computes undefined * exp(-inf) == garbage * 0 == NaN and corrupts the result. Sanitize both the LSE and the undefined output in a single mask_empty_context helper (renamed from mask_empty_context_lse), deriving emptiness from the context offsets instead of the -inf LSE. This keeps the CUDA and Triton merge kernels generic: revert the per-side output guard so new merge backends need no empty-chunk awareness, keeping only a cheap both-empty guard against 0/0 scales. Signed-off-by: Matthew Bonanni <mbonanni@redhat.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
khluu
pushed a commit
that referenced
this pull request
Jul 23, 2026
) Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com> Co-authored-by: OpenAI Codex <codex@openai.com> (cherry picked from commit 060b5f6)
1 task
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.
Summary
FIX for #49334
Alternative to #49196
-infLSE before mergingWide PCP batches can split cached context into workspace-sized chunks. A later chunk can contain no KV tokens for some prefill rows. The backend may return a finite LSE for those empty rows, causing
merge_attn_statesto treat undefined output as valid attention and corrupt the prefill result.Validation
Focused kernel test:
Result:
1 passed.All file-scoped pre-commit hooks passed, including Ruff, formatting, mypy, SPDX, configuration validation, and forbidden-import checks.
Warmed kernel microbenchmark on an NVIDIA B300 with 64 attention heads:
The kernel preserves token-proportional load balancing without adding token-to-request metadata.
Runtime configuration (4 GPUs):
100-sample GSM8K smoke evaluation:
The Triton implementation completed the evaluation in 47.862 seconds. For comparison, disabling prefix caching scored 96/100, consistent with the bug being in cached-context merging rather than sampling.
A 300-sample, three-wave run with the same 32K token budget scored 279/300 (93.0%) with no invalid responses. The PCP eval YAMLs now pin that validated token budget instead of falling back to the 8K default.
AI assistance
AI assistance was used to diagnose and implement this draft. This PR should remain a draft until the human submitter reviews every changed line, confirms the test and evaluation results, and can explain and defend the change end-to-end.