Skip to content

llama : enable moe amax rescaling for laguna - #31147

Merged
CISC merged 2 commits into
ggml-org:masterfrom
begcdn:laguna-moe-f16-rescale
Oct 26, 2026
Merged

CISC merged 2 commits into
ggml-org:masterfrom
begcdn:laguna-moe-f16-rescale

Conversation

@begcdn

@begcdn begcdn commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Overview

Adds LLM_ARCH_LAGUNA to the existing build_amax_src1_f16 condition in build_moe_ffn, so Laguna applies the same f16 activation rescaling already used by Mistral4, Mellum and Flint.

Without it, Laguna MoE models overflow on Metal when the prefill microbatch is 32 tokens or larger (#30896): kernel_mul_mm_id stages the f32 activation through half in shared memory, so gate/up outputs above 65504 become inf in the down projection. At smaller microbatches a different kernel path is used, which is why the failure only appears at ubatch >= 32.

Verified locally on a Laguna-XS-2.1 slice: the src1 amax into ffn_moe_down dropped from 103671.5 to 1018.9 with this change, and the unflagged Metal MUL_MAT_ID path produces NaN for src1 ~1e5 at n >= 32 while CPU does not.

Additional information

Ref: #30896, #30584

Requirements

@begcdn
begcdn requested a review from CISC as a code owner October 25, 2026 12:19
@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 25, 2026
@CISC CISC removed the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 26, 2026
@CISC

CISC commented Oct 26, 2026

Copy link
Copy Markdown
Member

@ggerganov

Copy link
Copy Markdown
Member

@begcdn Apply this patch:

diff --git a/src/llama-arch.cpp b/src/llama-arch.cpp
index 39e29d09a..3a5afe36f 100644
--- a/src/llama-arch.cpp
+++ b/src/llama-arch.cpp
@@ -1338,6 +1338,7 @@ bool llm_arch_supports_sm_tensor(const llm_arch & arch) {
         case LLM_ARCH_MISTRAL4:
         case LLM_ARCH_MELLUM: // [TAG_MOE_AMAX_SCALE]
         case LLM_ARCH_FLINT:  // [TAG_MOE_AMAX_SCALE]
+        case LLM_ARCH_LAGUNA: // [TAG_MOE_AMAX_SCALE]
         case LLM_ARCH_KIMI_LINEAR:
         case LLM_ARCH_BAILINGMOE3:
         case LLM_ARCH_KIMI_K3:

@CISC
CISC merged commit 961c376 into ggml-org:master Oct 26, 2026
20 checks passed
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
* llama : enable moe amax rescaling for laguna

Assisted-by: Devin

* llama : declare laguna sm tensor support
yzhou51 pushed a commit to yzhou51/llama.cpp that referenced this pull request Oct 30, 2026
* llama : enable moe amax rescaling for laguna

Assisted-by: Devin

* llama : declare laguna sm tensor support
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.

3 participants