[GH-ISSUE #15849] Bug: Metal backend crash on Apple M5 (llama runner terminated) when running TinyLlama #87788

Open
opened 2026-05-10 06:23:34 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @shaileshkryadav on GitHub (Apr 28, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/15849

What is the issue?

Running a model with Ollama fails with a 500 Internal Server Error. The debug logs show that the failure occurs during Metal backend initialization on Apple M5, causing the runner process to terminate.

Environment

  • Ollama Version: 0.21.2
  • OS: macOS
  • Hardware: Apple M5
  • Memory: 24 GB
  • Model: tinyllama:latest
  • Steps to Reproduce
  • OLLAMA_DEBUG=1 ollama serve

In a separate terminal:

  • ollama run tinyllama:latest

Expected Behavior

The model should load successfully and allow prompt interaction.

Actual Behavior

Request fails with:

  • Error: 500 Internal Server Error: llama runner process has terminated: %!w()
  • Runner crashes during initialization.

Relevant Logs
ggml_metal_device_init: GPU name: Apple M5
ggml_metal_device_init: has bfloat = true
ggml_metal_device_init: has tensor = true

ggml_metal_library_init: error: Error Domain=MTLLibraryErrorDomain Code=3
static_assert failed due to requirement '__tensor_ops_detail::__is_same_v<bfloat, half>'
"Input types must match cooperative tensor types"

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

level=ERROR msg="llama runner terminated" error="exit status 2"
level=INFO msg="Load failed" error="llama runner process has terminated: %!w()"

(Full logs available here: )

Observations

Ollama successfully starts and detects the GPU:

GPU name: Apple M5
However, Metal backend fails during shader compilation due to bfloat/half tensor type mismatch.
Model then falls back partially but ultimately crashes during context initialization.
Workaround Attempted

Running with CPU backend:

OLLAMA_LLM_LIBRARY=cpu OLLAMA_DEBUG=1 ollama serve

(This avoids Metal initialization but does not resolve the underlying issue.)

Possible Cause
Metal backend incompatibility with Apple M5 GPU
Issue related to bfloat16 + half precision tensor operations
Likely a bug in Metal shader generation or compatibility layer
Request
Confirm if Apple M5 is currently supported
Provide workaround or fix for Metal backend initialization failure
Guidance on disabling problematic tensor paths (bfloat/metal)

Relevant log output

ggml_metal_device_init: GPU name: Apple M5
ggml_metal_device_init: has bfloat = true
ggml_metal_device_init: has tensor = true

ggml_metal_library_init: error: Error Domain=MTLLibraryErrorDomain Code=3
static_assert failed due to requirement '__tensor_ops_detail::__is_same_v<bfloat, half>'
"Input types must match cooperative tensor types"

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

level=ERROR msg="llama runner terminated" error="exit status 2"
level=INFO msg="Load failed" error="llama runner process has terminated: %!w(<nil>)"

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.21.2

Originally created by @shaileshkryadav on GitHub (Apr 28, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/15849 ### What is the issue? Running a model with Ollama fails with a 500 Internal Server Error. The debug logs show that the failure occurs during Metal backend initialization on Apple M5, causing the runner process to terminate. Environment - Ollama Version: 0.21.2 - OS: macOS - Hardware: Apple M5 - Memory: 24 GB - Model: tinyllama:latest - Steps to Reproduce - OLLAMA_DEBUG=1 ollama serve In a separate terminal: - ollama run tinyllama:latest Expected Behavior The model should load successfully and allow prompt interaction. Actual Behavior Request fails with: - Error: 500 Internal Server Error: llama runner process has terminated: %!w(<nil>) - Runner crashes during initialization. Relevant Logs ggml_metal_device_init: GPU name: Apple M5 ggml_metal_device_init: has bfloat = true ggml_metal_device_init: has tensor = true ggml_metal_library_init: error: Error Domain=MTLLibraryErrorDomain Code=3 static_assert failed due to requirement '__tensor_ops_detail::__is_same_v<bfloat, half>' "Input types must match cooperative tensor types" 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 level=ERROR msg="llama runner terminated" error="exit status 2" level=INFO msg="Load failed" error="llama runner process has terminated: %!w(<nil>)" (Full logs available here: ) Observations Ollama successfully starts and detects the GPU: GPU name: Apple M5 However, Metal backend fails during shader compilation due to bfloat/half tensor type mismatch. Model then falls back partially but ultimately crashes during context initialization. Workaround Attempted Running with CPU backend: OLLAMA_LLM_LIBRARY=cpu OLLAMA_DEBUG=1 ollama serve (This avoids Metal initialization but does not resolve the underlying issue.) Possible Cause Metal backend incompatibility with Apple M5 GPU Issue related to bfloat16 + half precision tensor operations Likely a bug in Metal shader generation or compatibility layer Request Confirm if Apple M5 is currently supported Provide workaround or fix for Metal backend initialization failure Guidance on disabling problematic tensor paths (bfloat/metal) ### Relevant log output ```shell ggml_metal_device_init: GPU name: Apple M5 ggml_metal_device_init: has bfloat = true ggml_metal_device_init: has tensor = true ggml_metal_library_init: error: Error Domain=MTLLibraryErrorDomain Code=3 static_assert failed due to requirement '__tensor_ops_detail::__is_same_v<bfloat, half>' "Input types must match cooperative tensor types" 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 level=ERROR msg="llama runner terminated" error="exit status 2" level=INFO msg="Load failed" error="llama runner process has terminated: %!w(<nil>)" ``` ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.21.2
GiteaMirror added the bug label 2026-05-10 06:23:35 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#87788