Skip to content

llama-graph: prevent f16 overflow in MoE down-projection on Metal - #25442

Closed
steelannelida wants to merge 1 commit into
ggml-org:masterfrom
steelannelida:metal-moe-down-f16-overflow
Closed

steelannelida wants to merge 1 commit into
ggml-org:masterfrom
steelannelida:metal-moe-down-f16-overflow

Conversation

@steelannelida

Copy link
Copy Markdown

Metal's MUL_MAT_ID casts src1 to f16, so a SwiGLU activation above 65504 overflows to NaN and the model returns empty.
We encountered this in real life with the Laguna XS 2.1 model, which produces large activations in the later layers. We thus apply the classical trick of amax scaling the input.

Metal's MUL_MAT_ID casts src1 to f16, so a SwiGLU activation above 65504
overflows to NaN and the model returns empty. Scale each column of src1 by
its L2 norm before the matmul and undo it after; L2 is at least the largest
element so the cast stays in range, and it is a per-column identity so no
backend output changes.
@steelannelida
steelannelida requested a review from CISC as a code owner July 8, 2026 12:20
@ggml-gh-bot

ggml-gh-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

Hi @steelannelida, 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.

@SgtPooki

Copy link
Copy Markdown

Can confirm that this fixes things on my M1 mac

@CISC

CISC commented Aug 6, 2026

Copy link
Copy Markdown
Member

This is not the right fix, but tagging @ggml-org/ggml-metal for visibility.

@ggerganov

Copy link
Copy Markdown
Member

Yes, it will be fixed with: #26223

@ggerganov ggerganov closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants