Prevent Voxtral NaNs in CUDA split-K attention - #22133
Conversation
Voxtral attention scores can exceed the fixed-phi exponent range, turning partial softmax values into infinities and decoder logits into NaNs. Use stable normalization because a fixed offset cannot cover both large positive and negative score ranges. No perf regression.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22133
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 2dd38cf with merge base d0fe35d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
Pull request overview
This PR fixes numerical instability in the CUDA Triton split-K decode SDPA path by replacing the prior fixed-offset (“phi”) softmax approximation with a stable online-softmax that tracks per-split maxima and rescales partials during the cross-split reduction. This directly targets Voxtral decode cases where very large positive or negative attention scores previously caused overflow/underflow leading to NaNs or silent zero outputs.
Changes:
- Implement stable per-split online softmax in
_sdpa_decode_splitk_kernel, and stable global rescaling in_sdpa_decode_reduce_kernelvia a newM_partialbuffer. - Remove the fixed
_DEFAULT_SPLITK_PHIusage from the split-K decode implementation (while keepingphiin the operator signature for schema compatibility and explicitly documenting it as ignored). - Add regression tests covering large positive logits (overflow case), large negative logits (underflow-to-zero case), and correctness with
kv_lenexcluding empty trailing splits.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| backends/cuda/triton/kernels/sdpa.py | Reworks split-K decode softmax to be numerically stable using per-split max tracking + global rescaling; introduces M_partial and updates launch plumbing. |
| backends/cuda/tests/test_triton_sdpa_splitk.py | Adds targeted regression tests to prevent NaNs/Infs and validate correctness under extreme logits and kv_len-bounded decode. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
The algorithm change looks correct to me, and it matches what Three things before it lands. 1. The rebase has to cover both split-K kernels. Since this branched, main added The merge is also not safe to resolve mechanically. This PR deletes 2. "No perf regression" does not hold at Alternating base/head processes on an idle H100,
Profiling attributes essentially all of it to the reduce kernel, which gets 3.2x For what it is worth, the Happy either way on the fix, but the claim in the description should probably be 3. It passes on the pre-change kernel too, so it cannot fail for the reason this PR It is still a useful test of the new uninitialized-buffer contract, just a weak Comment nit, # The split grid unconditionally writes every partial, including empty
# splits, so these buffers do not need initialization kernels.The stores are not unconditional, they are masked by Also, since |
Voxtral attention scores can exceed the fixed-phi exponent range, turning partial softmax values into infinities and decoder logits into NaNs.
Use stable normalization because a fixed offset cannot cover both large positive and negative score ranges. No perf regression.