Repository navigation
metal : remove mul_mm_id amax rescaling - #30924
Merged
Merged
Conversation
ggerganov
marked this pull request as ready for review
October 21, 2026 14:29
The src1 power-of-two rescale in kernel_mul_mm_id is superseded by the per expert-token amax scaling done in the compute graph (ref: #30861), which keeps the MoE down-projection activations within f16 range before the op runs. Drop the two-stage reduction kernels, their scratch buffer and the GGML_PREC_F32 dispatch added in #26223, as well as the test cases that drive MUL_MAT_ID src1 out of f16 range. Assisted-by: pi:llama.cpp/ggml-org/Qwen3.8-Flash-Next-GGUF (MacBook, M5 Max, 128GB)
ggerganov
force-pushed
the
gg/metal-remove-amax
branch
from
October 24, 2026 10:48
e661b09 to
b147b96
Compare
ggerganov
marked this pull request as draft
October 24, 2026 10:49
ggerganov
marked this pull request as ready for review
October 24, 2026 10:52
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 24, 2026
The src1 power-of-two rescale in kernel_mul_mm_id is superseded by the per expert-token amax scaling done in the compute graph (ref: ggml-org#30861), which keeps the MoE down-projection activations within f16 range before the op runs. Drop the two-stage reduction kernels, their scratch buffer and the GGML_PREC_F32 dispatch added in ggml-org#26223, as well as the test cases that drive MUL_MAT_ID src1 out of f16 range. Assisted-by: pi:llama.cpp/ggml-org/Qwen3.8-Flash-Next-GGUF (MacBook, M5 Max, 128GB)
4 of 11 tasks
auRose94
pushed a commit
to auRose94/llama.cpp
that referenced
this pull request
Oct 28, 2026
The src1 power-of-two rescale in kernel_mul_mm_id is superseded by the per expert-token amax scaling done in the compute graph (ref: ggml-org#30861), which keeps the MoE down-projection activations within f16 range before the op runs. Drop the two-stage reduction kernels, their scratch buffer and the GGML_PREC_F32 dispatch added in ggml-org#26223, as well as the test cases that drive MUL_MAT_ID src1 out of f16 range. Assisted-by: pi:llama.cpp/ggml-org/Qwen3.8-Flash-Next-GGUF (MacBook, M5 Max, 128GB)
1 task done
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
Remove the amax rescaling of
src1in the Metalmul_mm_idkernel, added in #26223 to avoidinf/NaNwhen MoE activations exceed the f16 range.Since #30861 the MoE down projection is rescaled per expert-token in the compute graph (
build_amax_src1_f16+ggml_pool_1dmax, undone on the output), so the activations reachingMUL_MAT_IDalready fit in f16 and the in-kernel rescale is redundant. The path was also gated onGGML_PREC_F32onsrc1, which nothing in the graph ever sets today, so it never dispatched for a real model.Removed:
kernel_mul_mm_id_amax_part_f32/kernel_mul_mm_id_amax_f32, theamaxbuffer argument and thes1_inv/s1_scalescaling inkernel_mul_mm_id, theFC_mul_mm_id_amaxfunction constant, the amax pipeline getters andggml_metal_kargs_mul_mm_id_amax, the amax scratch region of theMUL_MAT_IDdestination buffer, and thetest-backend-opsamaxparameter with its src1 f16-overflow cases.Additional information
test-backend-ops -b MTL0on Apple M5 Max: 18297/18297 OK, allMUL_MAT_IDcases OK.docs/ops/*.csvstill list the removedamax=...MUL_MAT_ID cases; those baselines are regenerated out of band, and CI only cross-checksdocs/ops.mdagainst them.Requirements
pi:llama.cppMacBook, M5 Max, 128GB◷ 42.5m · ⚙ 15.1m · ↑ 290k · ↓ 49k · ≡ 231 · ⌨ 7