Uh oh!
There was an error while loading. Please reload this page.
Prevent Voxtral NaNs in CUDA split-K attention - #22133
Conversation
🔗 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 238a723 with merge base 469debd ( 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.
shoumikhin
commented
Aug 25, 2026
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 |
Uh oh!
There was an error while loading. Please reload this page.
A fixed softmax offset is only valid while every attention score remains within the fp32 exponent range. Voxtral can exceed that range, producing infinities and NaNs. Sufficiently negative scores can instead underflow every partial weight and silently return zeros. Both split-K paths have this risk. Use each split's observed maximum and rescale against the global maximum. Each split processes only a few KV tiles, so online softmax removes the model-specific score assumption without materially extending the split-kernel recurrence. Reduce all partials together so cross-split normalization does not become a serial bottleneck. This change was authored with Codex.
Gasoonjia
left a comment
There was a problem hiding this comment.
LGTM, it would be great if we can have a perf comparsion between static phi version and online softmax
| (filled) positions (O(context) instead of O(max_seq_len)). Read | ||
| on-device, CUDA-graph safe. When None, sweeps the full L_kv. | ||
| phi is deprecated, accepted for operator-schema compatibility, and ignored. |
There was a problem hiding this comment.
maybe we no longer need to mention phi here; there's no phi in the op
There was a problem hiding this comment.
will do it later, don't want to run CI again for this :p
digantdesai
commented
Aug 27, 2026
Updated the PR summary. |
Uh oh!
There was an error while loading. Please reload this page.
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.