From 73adf89e38e78b64ebfa8916c4fbb854c19cae33 Mon Sep 17 00:00:00 2001 From: Satyam Thakur Date: Sat, 24 Oct 2026 19:39:02 +0530 Subject: [PATCH] minimax-m3 : forward quant scales to the graph (fixes #31063) (#31097) The generic scale pass in llama-model.cpp loads the per-expert NVFP4 scale2 tensors (ffn_{up,gate,down}_exps_s) and the per-tensor MXFP8 scales for the dense FFN and the shared expert, but minimax-m3.cpp never forwarded any of them to the graph. build_moe_ffn() defaults these to nullptr, so build_lora_mm_id() skipped its w_s branch entirely and the routed-expert weights came out global_scale times too large, swamping the residual (reported G ~= 15123 for M3.1 Flash) and producing token soup. Forward all scale tensors at the three call sites, matching the pattern used by flint and the other NVFP4-capable MoE models. Co-authored-by: origin-labs-ai --- src/models/minimax-m3.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/models/minimax-m3.cpp b/src/models/minimax-m3.cpp index 35e7b1a81..73d145dae 100644 --- a/src/models/minimax-m3.cpp +++ b/src/models/minimax-m3.cpp @@ -550,9 +550,9 @@ llama_model_minimax_m3::graph::graph(const llama_model & model, const llm_graph_ if ((uint32_t) il < hparams.n_layer_dense_lead) { // leading dense FFN (swigluoai) cur = build_ffn(cur, - model.layers[il].ffn_up, NULL, NULL, - model.layers[il].ffn_gate, NULL, NULL, - model.layers[il].ffn_down, NULL, NULL, + model.layers[il].ffn_up, NULL, model.layers[il].ffn_up_s, + model.layers[il].ffn_gate, NULL, model.layers[il].ffn_gate_s, + model.layers[il].ffn_down, NULL, model.layers[il].ffn_down_s, NULL, LLM_FFN_SWIGLU_OAI_MOE, LLM_FFN_PAR, il); cb(cur, "ffn_out", il); @@ -568,14 +568,17 @@ llama_model_minimax_m3::graph::graph(const llama_model & model, const llm_graph_ LLM_FFN_SWIGLU_OAI_MOE, hparams.expert_weights_norm, hparams.expert_weights_scale, (llama_expert_gating_func_type) hparams.expert_gating_func, - il); + il, nullptr, nullptr, + model.layers[il].ffn_up_exps_s, + model.layers[il].ffn_gate_exps_s, + model.layers[il].ffn_down_exps_s); cb(moe_out, "ffn_moe_out", il); // shared expert (swigluoai) ggml_tensor * ffn_shexp = build_ffn(cur, - model.layers[il].ffn_up_shexp, NULL, NULL, - model.layers[il].ffn_gate_shexp, NULL, NULL, - model.layers[il].ffn_down_shexp, NULL, NULL, + model.layers[il].ffn_up_shexp, NULL, model.layers[il].ffn_up_shexp_s, + model.layers[il].ffn_gate_shexp, NULL, model.layers[il].ffn_gate_shexp_s, + model.layers[il].ffn_down_shexp, NULL, model.layers[il].ffn_down_shexp_s, NULL, LLM_FFN_SWIGLU_OAI_MOE, LLM_FFN_PAR, il); cb(ffn_shexp, "ffn_shexp", il);