[GH-ISSUE #15548] Gemma 4 E2B fails to load on Apple M5 — Metal library compilation error #71994

Closed
opened 2026-05-05 03:15:56 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Chloeyz13 on GitHub (Apr 13, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/15548

Originally assigned to: @dhiltgen on GitHub.

What is the issue?

Chip: Apple M5
Ollama model: gemma4:e2b
Running ollama run gemma4:e2b results in a 500 Internal Server Error. The model never loads.

❯ ollama run gemma3:4b
Error: 500 Internal Server Error: model failed to load, this may be due to resource limitations or an internal error, check ollama server logs for details

Relevant log output

ggml_metal_device_init: simdgroup reduction   = true
ggml_metal_device_init: simdgroup matrix mul. = true
ggml_metal_device_init: has unified memory    = true
ggml_metal_device_init: has bfloat            = true
ggml_metal_device_init: has tensor            = true
ggml_metal_device_init: use residency sets    = true
ggml_metal_device_init: use shared buffers    = true
ggml_metal_device_init: recommendedMaxWorkingSetSize  = 19069.67 MB
ggml_metal_init: allocating
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: using embedded metal library
ggml_metal_library_init: error: Error Domain=MTLLibraryErrorDomain Code=3 "program_source:7131:28: warning: variable 'theta_base' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
ggml_metal_init: error: failed to initialize the Metal library
2   ollama                              0x0000000105bfe544 ggml_backend_get_default_buffer_type + 76
3   ollama                              0x0000000105b7a838 _cgo_c81fd19bee02_Cfunc_ggml_backend_get_default_buffer_type + 36
SIGABRT: abort
github.com/ollama/ollama/ml/backend/ggml._Cfunc_ggml_backend_get_default_buffer_type(0x0)
fault   0x1836b95b0

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.20.6

Originally created by @Chloeyz13 on GitHub (Apr 13, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/15548 Originally assigned to: @dhiltgen on GitHub. ### What is the issue? Chip: Apple M5 Ollama model: gemma4:e2b Running ollama run gemma4:e2b results in a 500 Internal Server Error. The model never loads. ❯ ollama run gemma3:4b Error: 500 Internal Server Error: model failed to load, this may be due to resource limitations or an internal error, check ollama server logs for details ### Relevant log output ```shell ggml_metal_device_init: simdgroup reduction = true ggml_metal_device_init: simdgroup matrix mul. = true ggml_metal_device_init: has unified memory = true ggml_metal_device_init: has bfloat = true ggml_metal_device_init: has tensor = true ggml_metal_device_init: use residency sets = true ggml_metal_device_init: use shared buffers = true ggml_metal_device_init: recommendedMaxWorkingSetSize = 19069.67 MB ggml_metal_init: allocating 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: using embedded metal library ggml_metal_library_init: error: Error Domain=MTLLibraryErrorDomain Code=3 "program_source:7131:28: warning: variable 'theta_base' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] ggml_metal_init: error: failed to initialize the Metal library 2 ollama 0x0000000105bfe544 ggml_backend_get_default_buffer_type + 76 3 ollama 0x0000000105b7a838 _cgo_c81fd19bee02_Cfunc_ggml_backend_get_default_buffer_type + 36 SIGABRT: abort github.com/ollama/ollama/ml/backend/ggml._Cfunc_ggml_backend_get_default_buffer_type(0x0) fault 0x1836b95b0 ``` ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.20.6
GiteaMirror added the bug label 2026-05-05 03:15:56 -05:00
Author
Owner

@Horacehxw commented on GitHub (Apr 13, 2026):

I can reproduce this on a local Apple M5 Pro / macOS 26.4 / Ollama 0.20.6 setup with gemma4:26b (and local aliases based on it).

Two additional data points that may help narrow this down:

  1. GGML_METAL_TENSOR_DISABLE=1 is an effective workaround for the raw runner crash on this machine.

    • With that env set, the runner reports:
      • ggml_metal_device_init: has tensor = false
      • offloaded 31/31 layers to GPU
    • Without it, the runner reports has tensor = true, then tries to compile the Metal library on the fly and aborts with the MetalPerformancePrimitives bfloat / half static_assert mismatch.
  2. The Ollama macOS app appears not to pass this env through to the ollama serve child process it launches.

    • launchctl print gui/$(id -u)/com.ollama.ollama shows GGML_METAL_TENSOR_DISABLE=1 in the app's inherited environment.
    • But ps eww -p <serve_pid> for /Applications/Ollama.app/Contents/Resources/ollama serve does not include GGML_METAL_TENSOR_DISABLE, OLLAMA_KV_CACHE_TYPE, or OLLAMA_FLASH_ATTENTION.
    • In that app-launched server path, requests still fail with 500 and logs show:
      • ggml_metal_device_init: has tensor = true
      • 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
      • MPPTensorOpsMatMul2dImpl.h ... static_assert failed due to requirement '__is_same_v<bfloat, half>'
      • SIGABRT: abort

I also observed a second app-specific issue: if I manually start ollama serve with the workaround env and then open the macOS app UI, the app sends concurrent initialization requests and I can hit context canceled during model load, which turns a generate request into 500 even though the underlying Metal workaround is active.

A stable successful request on this machine was:

GGML_METAL_TENSOR_DISABLE=1 \
OLLAMA_KV_CACHE_TYPE=q8_0 \
OLLAMA_FLASH_ATTENTION=1 \
/Applications/Ollama.app/Contents/Resources/ollama serve

Then:

curl -s http://127.0.0.1:11434/api/chat \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gemma4-agent",
    "stream": false,
    "think": false,
    "messages": [{"role": "user", "content": "Reply with exactly one word: pong"}],
    "options": {"num_predict": 32}
  }'

Response:

{"model":"gemma4-agent","message":{"role":"assistant","content":"pong"},"done":true,"done_reason":"stop"}

So at least on this machine, there seem to be two separate bugs:

  • Metal tensor path compilation/regression on Apple M5 + macOS 26.x
  • macOS app process chain not propagating critical runtime env vars to ollama serve
<!-- gh-comment-id:4238011621 --> @Horacehxw commented on GitHub (Apr 13, 2026): I can reproduce this on a local Apple M5 Pro / macOS 26.4 / Ollama 0.20.6 setup with `gemma4:26b` (and local aliases based on it). Two additional data points that may help narrow this down: 1. `GGML_METAL_TENSOR_DISABLE=1` is an effective workaround for the raw runner crash on this machine. - With that env set, the runner reports: - `ggml_metal_device_init: has tensor = false` - `offloaded 31/31 layers to GPU` - Without it, the runner reports `has tensor = true`, then tries to compile the Metal library on the fly and aborts with the `MetalPerformancePrimitives` `bfloat` / `half` static_assert mismatch. 2. The Ollama macOS app appears not to pass this env through to the `ollama serve` child process it launches. - `launchctl print gui/$(id -u)/com.ollama.ollama` shows `GGML_METAL_TENSOR_DISABLE=1` in the app's inherited environment. - But `ps eww -p <serve_pid>` for `/Applications/Ollama.app/Contents/Resources/ollama serve` does **not** include `GGML_METAL_TENSOR_DISABLE`, `OLLAMA_KV_CACHE_TYPE`, or `OLLAMA_FLASH_ATTENTION`. - In that app-launched server path, requests still fail with `500` and logs show: - `ggml_metal_device_init: has tensor = true` - `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` - `MPPTensorOpsMatMul2dImpl.h ... static_assert failed due to requirement '__is_same_v<bfloat, half>'` - `SIGABRT: abort` I also observed a second app-specific issue: if I manually start `ollama serve` with the workaround env and then open the macOS app UI, the app sends concurrent initialization requests and I can hit `context canceled` during model load, which turns a generate request into `500` even though the underlying Metal workaround is active. A stable successful request on this machine was: ```bash GGML_METAL_TENSOR_DISABLE=1 \ OLLAMA_KV_CACHE_TYPE=q8_0 \ OLLAMA_FLASH_ATTENTION=1 \ /Applications/Ollama.app/Contents/Resources/ollama serve ``` Then: ```bash curl -s http://127.0.0.1:11434/api/chat \ -H 'Content-Type: application/json' \ -d '{ "model": "gemma4-agent", "stream": false, "think": false, "messages": [{"role": "user", "content": "Reply with exactly one word: pong"}], "options": {"num_predict": 32} }' ``` Response: ```json {"model":"gemma4-agent","message":{"role":"assistant","content":"pong"},"done":true,"done_reason":"stop"} ``` So at least on this machine, there seem to be two separate bugs: - Metal tensor path compilation/regression on Apple M5 + macOS 26.x - macOS app process chain not propagating critical runtime env vars to `ollama serve`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#71994