Repository navigation
Conversation
… sizes Two failures in the vendored FlashInfer decode path, both on q_len = 1: - kv_len < TILE_SIZE with attention weights returns NaN (awslabs#156) - GQA group sizes outside {1, 2, 4, 8} without attention weights raise 'Unsupported group_size' from FlashInfer's SingleDecodeWithKVCache These tests fail on main; the fix follows in the next commit.
…GQA group sizes - tiled_decode_attention_kernel: a tz chunk that has not seen a valid key still has st.m == -inf, and the online-softmax rescale computed exp2(-inf - -inf) = NaN, which poisoned the cross-BDZ merge. Hit for any kv_len < TILE_SIZE (128 for head_size 128, 256 for 64), i.e. the first decode steps after a short prompt. Skip the rescale while the chunk is empty. Fixes awslabs#156. - FlashInfer's library decode only instantiates GQA group sizes 1, 2, 3, 4, 6, 8 and throws for others. Qwen2.5-7B (28 / 4 = 7) crashed in every decode step without attention weights. Check the group size before dispatching and catch the exception, falling back to the vendored tiled kernel.
The tiled fallback gives outputs that do not match eager for group sizes 5 and 7, so falling back is worse than the current loud failure. Tracked separately.
Contributor
|
Is this something we could contribute back, or does it only affect our use case? |
Collaborator
Author
|
@mseeger do you mean contribute to the original source code? |
Collaborator
Author
|
The bug is in our own decode kernel (tiled_decode_attention_kernel, code in keys_values/csrc), not in FlashInfer itself. It only uses FlashInfer's primitives. |
mmjerge
added a commit
to mmjerge/keys_values
that referenced
this pull request
Oct 7, 2026
Kept only the awslabs#156 NaN fix (same as PR awslabs#158). The fallback to the tiled kernel for group sizes outside FlashInfer's {1,2,3,4,6,8} produced outputs that do not match the eager reference for group sizes 5 and 7, so it traded a loud crash for silently wrong attention. Qwen2.5-7B (group 7) dense decode without attention weights will raise again until the fallback kernel is fixed.
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.
The vendored decode kernel returns NaN output and attention weights when
kv_len < TILE_SIZE(128 for head_size 128, 256 for head_size 64). It splits the KV axis over BDZ chunks, and a chunk that has not seen a valid key still hasst.m == -inf. The online softmax rescale then computesexp2(-inf - -inf) = NaN, which poisons the cross-chunk merge.This is not limited to toy shapes. Every decode right after a short prompt hits it. In RL rollouts on math prompts (a few hundred tokens) it gave NaN logits and a device-side assert in
multinomial.Fix: skip the rescale while the chunk is still empty.
merge()already handles a partner withm == -inf.Tests:
TestDecodeKernelShortCachechecks decode with attention weights against the eager reference for kv_len from 2 to 300, head_size 64 and 128, fp16 and bf16. Run on an L40S:test_flashinfer_wrapper.py+test_attn_weights.pypass in full (72). This includestest_property_3andtest_property_4, which fail on main for the same reason.The first commit adds the tests alone, so you can see them fail before the fix.
Closes #156.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.