Skip to content

ggml-cuda: sanitize post-bias NaNs in MoE selection - #31005

Open
ArberSephirotheca wants to merge 1 commit into
ggml-org:masterfrom
ArberSephirotheca:recovered-pr-29609
Open

ArberSephirotheca wants to merge 1 commit into
ggml-org:masterfrom
ArberSephirotheca:recovered-pr-29609

Conversation

@ArberSephirotheca

@ArberSephirotheca ArberSephirotheca commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure:
    YES - Codex inspected the code and history, rebased the existing commit, and helped draft the PR explanation.

@ArberSephirotheca
ArberSephirotheca requested a review from a team as a code owner October 22, 2026 23:03
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Oct 22, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

Hi @ArberSephirotheca, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Oct 22, 2026
@github-actions
github-actions Bot marked this pull request as draft October 22, 2026 23:10
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Oct 22, 2026
@ArberSephirotheca
ArberSephirotheca marked this pull request as ready for review October 22, 2026 23:13

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants