Skip to content

metal : remove mul_mm_id amax rescaling - #30924

Merged
ggerganov merged 1 commit into
masterfrom
gg/metal-remove-amax
Oct 24, 2026
Merged

ggerganov merged 1 commit into
masterfrom
gg/metal-remove-amax

Conversation

@ggerganov

@ggerganov ggerganov commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Overview

Remove the amax rescaling of src1 in the Metal mul_mm_id kernel, added in #26223 to avoid inf/NaN when 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_1d max, undone on the output), so the activations reaching MUL_MAT_ID already fit in f16 and the in-kernel rescale is redundant. The path was also gated on GGML_PREC_F32 on src1, 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, the amax buffer argument and the s1_inv / s1_scale scaling in kernel_mul_mm_id, the FC_mul_mm_id_amax function constant, the amax pipeline getters and ggml_metal_kargs_mul_mm_id_amax, the amax scratch region of the MUL_MAT_ID destination buffer, and the test-backend-ops amax parameter with its src1 f16-overflow cases.

Additional information

  • The graph-level rescale from llama : scale moe down projection per expert token #30861 is exact (power of two) and applies to all backends, unlike this Metal-only workaround.
  • test-backend-ops -b MTL0 on Apple M5 Max: 18297/18297 OK, all MUL_MAT_ID cases OK.
  • docs/ops/*.csv still list the removed amax=... MUL_MAT_ID cases; those baselines are regenerated out of band, and CI only cross-checks docs/ops.md against them.

Requirements

@ggerganov
ggerganov marked this pull request as ready for review October 21, 2026 14:29
@ggerganov
ggerganov requested a review from a team as a code owner October 21, 2026 14:29
@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning Apple Metal https://en.wikipedia.org/wiki/Metal_(API) labels Oct 21, 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: #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
ggerganov force-pushed the gg/metal-remove-amax branch from e661b09 to b147b96 Compare October 24, 2026 10:48
@ggerganov
ggerganov marked this pull request as draft October 24, 2026 10:49
@ggerganov
ggerganov marked this pull request as ready for review October 24, 2026 10:52
@ggerganov
ggerganov merged commit 3f03b17 into master Oct 24, 2026
32 of 33 checks passed
@ggerganov
ggerganov deleted the gg/metal-remove-amax branch October 24, 2026 15:40
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)
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)
@BrewTestBot BrewTestBot mentioned this pull request Oct 28, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Apple Metal https://en.wikipedia.org/wiki/Metal_(API) ggml changes relating to the ggml tensor library for machine learning testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant