ollama - 💡(How to fix) Fix Metal shader compile fails on macOS 26.3.1 — MPPTensorOpsMatMul2dImpl static_assert (bfloat/half) on Apple M5 [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#15862Fetched 2026-04-29 06:11:44
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Error Message

ggml_metal_init: picking default device: Apple M5 ggml_metal_init: the device does not have a precompiled Metal library - this is unexpected ggml_metal_init: will try to compile it on the fly ggml_metal_library_init: error: Error Domain=MTLLibraryErrorDomain Code=3 MPPTensorOpsMatMul2dImpl.h:3266: static_assert failed due to requirement '__tensor_ops_detail::__is_same_v<bfloat, half>' "Input types must match cooperative tensor types" MPPTensorOpsMatMul2dImpl.h:3267: static_assert failed due to requirement '__tensor_ops_detail::__is_same_v<half, bfloat>' ggml_metal_init: error: failed to initialize the Metal library ggml_backend_metal_device_init: error: failed to allocate context llama_init_from_model: failed to initialize the context: failed to initialize Metal backend panic: unable to create llama context

Root Cause

Root cause (from logs)

On-the-fly Metal library compilation fails against macOS 26.3.1's MetalPerformancePrimitives headers, which now enforce strict type-matching on cooperative tensors:

Code Example

ggml_metal_init: picking default device: Apple M5
ggml_metal_init: the device does not have a precompiled Metal library - this is unexpected
ggml_metal_init: will try to compile it on the fly
ggml_metal_library_init: error: Error Domain=MTLLibraryErrorDomain Code=3
  MPPTensorOpsMatMul2dImpl.h:3266: static_assert failed due to requirement
    '__tensor_ops_detail::__is_same_v<bfloat, half>'
    "Input types must match cooperative tensor types"
  MPPTensorOpsMatMul2dImpl.h:3267: static_assert failed due to requirement
    '__tensor_ops_detail::__is_same_v<half, bfloat>'
ggml_metal_init: error: failed to initialize the Metal library
ggml_backend_metal_device_init: error: failed to allocate context
llama_init_from_model: failed to initialize the context: failed to initialize Metal backend
panic: unable to create llama context
RAW_BUFFERClick to expand / collapse

Environment

  • Hardware: MacBook Pro (Mac17,2), Apple M5
  • macOS: 26.3.1 (a) — build 25D771280a (Rapid Security Response)
  • Ollama: tested on 0.21.2 (stable) and 0.22.0-rc1 — same failure

Symptom

POST /api/chat returns 500 Internal Server Error: llama runner process has terminated. Affects every model loaded so far (gemma4:26b, llama3.2:3b).

Root cause (from logs)

On-the-fly Metal library compilation fails against macOS 26.3.1's MetalPerformancePrimitives headers, which now enforce strict type-matching on cooperative tensors:

ggml_metal_init: picking default device: Apple M5
ggml_metal_init: the device does not have a precompiled Metal library - this is unexpected
ggml_metal_init: will try to compile it on the fly
ggml_metal_library_init: error: Error Domain=MTLLibraryErrorDomain Code=3
  MPPTensorOpsMatMul2dImpl.h:3266: static_assert failed due to requirement
    '__tensor_ops_detail::__is_same_v<bfloat, half>'
    "Input types must match cooperative tensor types"
  MPPTensorOpsMatMul2dImpl.h:3267: static_assert failed due to requirement
    '__tensor_ops_detail::__is_same_v<half, bfloat>'
ggml_metal_init: error: failed to initialize the Metal library
ggml_backend_metal_device_init: error: failed to allocate context
llama_init_from_model: failed to initialize the context: failed to initialize Metal backend
panic: unable to create llama context

Embedded GGML shader source is instantiating mpp::tensor_ops::matmul2d with mismatched <half, bfloat> operands; the new MPP headers reject this.

Notes

  • Models that previously worked (cached compiled shaders) broke after the macOS 26.3.1 RSR purged Metal's per-device shader cache, forcing a recompile that now fails.
  • Reproduces on a fresh install of 0.22.0-rc1 (verified locally).

extent analysis

TL;DR

Update the GGML shader source to use matching types for mpp::tensor_ops::matmul2d operands to resolve the Metal library compilation failure.

Guidance

  • Verify that the issue is indeed caused by the type mismatch in the mpp::tensor_ops::matmul2d instantiation by checking the Metal library compilation logs for the specific error message.
  • Identify the embedded GGML shader source code that instantiates mpp::tensor_ops::matmul2d with mismatched types and update it to use matching types (e.g., both half or both bfloat).
  • Consider temporarily using a previous version of macOS or disabling the Metal library compilation to work around the issue, if possible.
  • Test the updated GGML shader source with the 0.22.0-rc1 version to ensure the fix works as expected.

Example

No code snippet is provided as the issue is specific to the GGML shader source code, which is not included in the issue body.

Notes

The fix may require updates to the GGML library or the llama runner process to handle the new strict type-matching requirements in the MetalPerformancePrimitives headers.

Recommendation

Apply a workaround by updating the GGML shader source code to use matching types for mpp::tensor_ops::matmul2d operands, as this is the most direct way to resolve the Metal library compilation failure.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING