Skip to content

metal : gate mul_mm_id src1 rescale behind ggml_prec - #29029

Merged
ggerganov merged 3 commits into
ggml-org:masterfrom
mdegans:metal-mul-mm-id-prec
Sep 22, 2026
Merged

ggerganov merged 3 commits into
ggml-org:masterfrom
mdegans:metal-mul-mm-id-prec

Conversation

@mdegans

@mdegans mdegans commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This is a follow-up to #26223 per request from @ggerganov to use ggml_prec....

  • Set f32 src precision on the Mistral 4 down projection and rescale on Metal only when it is set.
  • With Mistral Small 4, the down projection input peaks around 2.9e5, gate/up input near 59.
  • On metal, MUL_MAT_ID 849 of 849, MUL_MAT 1265 of 1265, and the batched path is ~1% faster than master for unflagged models. See details:
Details
  • Hardware: Apple M2 Max
  • Perf Command: test-backend-ops perf -b MTL0 -o MUL_MAT_ID
  • master 4ff829e against this branch, eight passes in ABBA BAAB order, median of per-case medians, negative means this branch is faster.
N cases median best worst
1 15 -0.41% -1.49% +2.07%
4 15 +0.04% -1.74% +3.07%
8 15 +0.11% -1.67% +1.36%
32 14 -1.45% -4.28% +0.39%
64 14 -1.30% -4.99% +0.71%
128 14 -1.22% -3.88% +1.50%
256 14 -1.04% -3.26% +0.85%
512 15 -1.74% -3.22% -0.49%
1024 7 -1.01% -2.06% -0.34%
2048 7 -1.50% -2.53% -0.76%
4096 7 -0.91% -1.97% -0.63%
8192 7 -0.50% -1.86% -0.28%
all 144 -0.87%
n>=32 (mul_mm_id) 99 -1.22%

Please note that N >= 1024 are local cases only and not committed.

Additional information

  • Six amax=1e5 MUL_MAT_ID cases that were commented out in metal: fix NaN in mul_mm_id when activations exceed f16 range #26223 are re-enabled which will likely break on CUDA, Vulkan and WebGPU (now likely fixed). Let me know if these should be commented out. My guess is they should be, but that putting the test change in a seperate commit might be desirable. Please advise.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES Assisted-by: Claude Fable 5.1 -- Claude made the code changes as requested and helped with wording.

@mdegans
mdegans requested review from a team, CISC and ggerganov as code owners September 17, 2026 13:25
@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 Sep 17, 2026

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! We expect some backends to fail the new tests now - let's see.

@ggerganov ggerganov self-assigned this Sep 17, 2026
@ggerganov

Copy link
Copy Markdown
Member

@mdegans We should now update the support_op implementation of the failing backends to return false when the specified src1 precision is F32.

@ggml-org/ggml-cuda @ggml-org/ggml-vulkan @ggml-org/ggml-webgpu fyi

@mdegans

mdegans commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

@mdegans We should now update the support_op implementation of the failing backends to return false when the specified src1 precision is F32.

I will take care of that tomorrow, no problem.

@0cc4m

0cc4m commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

I was already looking into this for Vulkan, will open a PR soon.

@mdegans

mdegans commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

I was already looking into this for Vulkan, will open a PR soon.

I was about to tackle this but will hold off in this case. @ggerganov and @0cc4m please let me know which bits you want me to handle, if any.

@yomaytk

yomaytk commented Sep 20, 2026

Copy link
Copy Markdown
Member

@mdegans
For the WebGPU backend, I changed supports_op to return false for this case, so could you cherry-pick the following commit?
I confirmed that the MUL_MAT_ID tests pass on both Apple and NVIDIA machines.

fcb7238

I'll open a separate PR once WebGPU can actually compute this case.

@mdegans

mdegans commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

@mdegans For the WebGPU backend, I changed supports_op to return false for this case, so could you cherry-pick the following commit? I confirmed that the MUL_MAT_ID tests pass on both Apple and NVIDIA machines.

fcb7238

I'll open a separate PR once WebGPU can actually compute this case.

Will do tomorrow along with the rest of the backends unless anybody objects by then.

@0cc4m

0cc4m commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

I was already looking into this for Vulkan, will open a PR soon.

I was about to tackle this but will hold off in this case. @ggerganov and @0cc4m please let me know which bits you want me to handle, if any.

You can update supports_op here for failing cases, I'll open a follow-up PR with fixes for Vulkan.

@mdegans

mdegans commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

You can update supports_op here for failing cases, I'll open a follow-up PR with fixes for Vulkan.

Will do. Cherry picking WebGPU as asked and fixing supports_op for all failing backends. Going to try to test as much as I can but I do not have Intel Windows, Intel Linux, rocm, and WebGPU on Nvidia. Will rely on CI for that.

fix `supports_op` to return false for failing backends when the specified src1 precision is f32

Assisted-by: Claude Fable 5.1
@mdegans
mdegans requested review from a team as code owners September 21, 2026 11:34
@CISC

CISC commented Sep 21, 2026

Copy link
Copy Markdown
Member

Going to try to test as much as I can but I do not have Intel Windows, Intel Linux, rocm, and WebGPU on Nvidia. Will rely on CI for that.

FYI, Intel CIs are down ATM.

@mdegans

mdegans commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Going to try to test as much as I can but I do not have Intel Windows, Intel Linux, rocm, and WebGPU on Nvidia. Will rely on CI for that.

FYI, Intel CIs are down ATM.

Thanks for the heads-up but I had not looked at the causes of the failures on Intel. I think they're unrelated. So it's fine even if it runs now. Vulkan passes locally on macOS and Linux. CUDA passes on Linux. WebGPU I am assuming is workign based on @yomaytk but I will run locally as well to confirm. Edit: Confirmed on macOS.

@github-actions github-actions Bot added Vulkan Issues specific to the Vulkan backend CUDA Related to the CUDA backend WebGPU labels Sep 21, 2026
@ggerganov
ggerganov merged commit 0f8a414 into ggml-org:master Sep 22, 2026
39 of 41 checks passed
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 1, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 2, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 3, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
LadislavSopko pushed a commit to 0ics-srls/llama.cpp that referenced this pull request Oct 5, 2026
* metal : gate mul_mm_id src1 rescale behind ggml_prec

Assisted-by: Claude Fable 5.1

* ggml-webgpu: reject MUL_MAT_ID when src1 precision is F32

* cuda/vulkan: reject MUL_MAT_ID in supports_op when src1 prec is F32

fix `supports_op` to return false for failing backends when the specified src1 precision is f32

Assisted-by: Claude Fable 5.1

---------

Co-authored-by: yomaytk <yoshimura.masashi.frbs@gmail.com>
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 5, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
* metal : gate mul_mm_id src1 rescale behind ggml_prec

Assisted-by: Claude Fable 5.1

* ggml-webgpu: reject MUL_MAT_ID when src1 precision is F32

* cuda/vulkan: reject MUL_MAT_ID in supports_op when src1 prec is F32

fix `supports_op` to return false for failing backends when the specified src1 precision is f32

Assisted-by: Claude Fable 5.1

---------

Co-authored-by: yomaytk <yoshimura.masashi.frbs@gmail.com>
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 7, 2026
* metal : gate mul_mm_id src1 rescale behind ggml_prec

Assisted-by: Claude Fable 5.1

* ggml-webgpu: reject MUL_MAT_ID when src1 precision is F32

* cuda/vulkan: reject MUL_MAT_ID in supports_op when src1 prec is F32

fix `supports_op` to return false for failing backends when the specified src1 precision is f32

Assisted-by: Claude Fable 5.1

---------

Co-authored-by: yomaytk <yoshimura.masashi.frbs@gmail.com>
(cherry picked from commit 0f8a414)
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 7, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 8, 2026
* metal : gate mul_mm_id src1 rescale behind ggml_prec

Assisted-by: Claude Fable 5.1

* ggml-webgpu: reject MUL_MAT_ID when src1 precision is F32

* cuda/vulkan: reject MUL_MAT_ID in supports_op when src1 prec is F32

fix `supports_op` to return false for failing backends when the specified src1 precision is f32

Assisted-by: Claude Fable 5.1

---------

Co-authored-by: yomaytk <yoshimura.masashi.frbs@gmail.com>
(cherry picked from commit 0f8a414)
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 9, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 10, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 10, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 10, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 10, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 11, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 12, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 12, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 17, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 19, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 20, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 20, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
iki007 added a commit to iki007/llama.cpp that referenced this pull request Oct 21, 2026
Same supports_op gate CUDA, Vulkan and WebGPU got in ggml-org#29029: SYCL quantizes
src1 to q8_1 or converts it to f16, so activations beyond the f16 range turn
into NaN (MUL_MAT_ID q8_0 n_mats=8 n_used=2 n=64 amax=1e5).

Assisted-by: Claude Opus 5.5
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) CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning testing Everything test related Vulkan Issues specific to the Vulkan backend WebGPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants