Repository navigation
ggml-cuda: sanitize post-bias NaNs in MoE selection - #31005
Open
ArberSephirotheca wants to merge 1 commit into
Open
ArberSephirotheca wants to merge 1 commit into
ArberSephirotheca wants to merge 1 commit into
Conversation
|
Hi @ArberSephirotheca, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
ArberSephirotheca
marked this pull request as ready for review
October 22, 2026 23:13
am17an
approved these changes
Oct 25, 2026
This branch has not been deployed
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.
Overview
The CUDA MoE top-k kernel sanitizes NaNs in wt at lines 200–204, before adding the expert selection bias at lines 218–219. Adding bias can introduce a new NaN.
Without an additional check, NaNs can reach the warp argmax comparison at lines 270–274. Comparisons involving NaN are false, so different lanes can select different winning experts and write conflicting values to ids[k] at lines 309–310.
The fix adds a check immediately after bias addition, replacing NaNs with -FLT_MAX before group masking and subsequent top-k selection.
Additional information
This PR duplicates the closed PR #29609. I accidentally deleted the original branch, so I recovered the commit and rebased it onto the latest master. Sorry for the confusion.
@am17an @JohannesGaessler, could you take another look when you have a chance? Thank you!
Requirements
YES - Codex inspected the code and history, rebased the existing commit, and helped draft the PR explanation.