Loading page

Download the Gemma 4 E4B GGUF model

You’ll benchmark Gemma 4 E4B on your Apple silicon Mac. After benchmarking, you’ll serve the model with Hermes Agent.

From inside your ~/hermes-gemma4/llama.cpp directory, create a ./models directory. Set up a Python virtual environment for the Hugging Face CLI:

    

        
        
mkdir -p models
python3 -m venv .venv
source .venv/bin/activate
pip install -U huggingface_hub

    

Download the Q4_0 quantized GGUF weights for Gemma 4 E4B from ggml-org (~4.3 GB):

    

        
        
hf download ggml-org/gemma-4-E4B-it-GGUF \
  --include "*Q4_0*.gguf" \
  --local-dir ./models

    

Verify that the .gguf file is present in ./models/:

    

        
        
ls -lh ./models/gemma-4-E4B-it-Q4_0.gguf

    

The output is similar to:

    

        
        -rw-r--r--@ 1 user  staff   4.3G Nov 24 15:55 ./models/gemma-4-E4B-it-Q4_0.gguf

        
    

Benchmark Metal GPU versus CPU performance

Offload all model layers to the Apple silicon Metal GPU with Flash Attention enabled (-ngl 99 -fa 1). On an Apple M4 Pro, this delivers 2.20x (+120%) faster prompt processing than the fastest CPU-only run (-ngl 0). Token generation is 1.50x (+50%) faster.

The source build also outperforms a prebuilt Homebrew version of llama.cpp run with identical flags. Metal prompt processing improves by 18.7%, and token generation improves by 17.7%.

On CPU-only runs (-ngl 0 at 8 threads), Arm KleidiAI with SME lifts prompt processing by 2.51x (+151%) over the Homebrew package.

Run llama-bench with full Metal GPU offload (-ngl 99). Compare Flash Attention disabled (0) and enabled (1), and set -t to your performance-core count:

    

        
        
P_CORES=$(sysctl -n hw.perflevel0.physicalcpu)

./build/bin/llama-bench \
  -m ./models/gemma-4-E4B-it-Q4_0.gguf \
  -ngl 99 -fa 0,1 -t "$P_CORES" -r 3 \
  -p 512 -n 128

    

The output is similar to:

    

        
        ggml_metal_device_init: GPU name:   MTL0 (Apple M4 Pro)
ggml_metal_device_init: GPU family: MTLGPUFamilyApple9  (1009)
ggml_metal_device_init: GPU family: MTLGPUFamilyMetal4  (5002)
ggml_metal_device_init: simdgroup reduction   = true
ggml_metal_device_init: simdgroup matrix mul. = true
ggml_metal_device_init: has unified memory    = true
...
| model                          |       size |     params | backend    | threads |  fa |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | ------: | --: | --------------: | -------------------: |
| gemma4 E4B Q4_0                |   4.26 GiB |     7.46 B | MTL,BLAS   |       8 |   0 |           pp512 |       1062.75 ± 4.13 |
| gemma4 E4B Q4_0                |   4.26 GiB |     7.46 B | MTL,BLAS   |       8 |   0 |           tg128 |         61.00 ± 0.54 |
| gemma4 E4B Q4_0                |   4.26 GiB |     7.46 B | MTL,BLAS   |       8 |   1 |           pp512 |      1078.39 ± 10.40 |
| gemma4 E4B Q4_0                |   4.26 GiB |     7.46 B | MTL,BLAS   |       8 |   1 |           tg128 |         62.47 ± 0.12 |

        
    

Next, run a CPU-only sweep (-ngl 0) to measure the CPU baseline. Compare four threads, your performance-core count, and all physical cores (hw.physicalcpu):

    

        
        
ALL_CORES=$(sysctl -n hw.physicalcpu)

./build/bin/llama-bench \
  -m ./models/gemma-4-E4B-it-Q4_0.gguf \
  -ngl 0 -t "4,$P_CORES,$ALL_CORES" -r 1 \
  -p 512 -n 128

    

This shows how efficiency cores affect throughput.

The following reference results were measured on an Apple M4 Pro with 24 GB unified memory running macOS 27.2.1:

ConfigurationOffload (-ngl)Threads (-t)Flash Attention (-fa)Prompt Processing pp512 (tok/s)Token Generation tg128 (tok/s)
Metal GPU (source build)99811078.39 ± 10.4062.47 ± 0.12
Metal GPU (source build)99801062.75 ± 4.1361.00 ± 0.54
Metal GPU (Homebrew v1.0.0)9981908.86 ± 2.2453.06 ± 1.25
CPU-only (source, KleidiAI + SME)080489.62 ± 0.0035.79 ± 0.00
CPU-only (source, KleidiAI + SME)040318.22 ± 0.0041.60 ± 0.00
CPU-only (source, P + E cores)0120163.35 ± 0.0017.79 ± 0.00
CPU-only (Homebrew v1.0.0)080194.91 ± 0.0034.53 ± 0.00

Verify Metal and KleidiAI usage

Check the llama-bench startup lines for ggml_metal_device_init: GPU name: MTL0 (Apple M4 Pro) or the chip name of your Mac. Confirm that has unified memory = true also appears. The backend column in the results table should list MTL,BLAS.

For CPU-only runs, -DGGML_CPU_KLEIDIAI=ON compiles Arm KleidiAI SME kernels into libggml-cpu.dylib. Verify this directly:

    

        
        
nm -gU ./build/bin/libggml-cpu.dylib | grep -iE "kleidi|sme" | head -n 6

    

The output is similar to:

    

        
        00000000000c7d14 T __Z28ggml_kleidiai_select_kernels11cpu_featurePK11ggml_tensor
00000000000c8374 T __Z32ggml_kleidiai_select_kernels_f3211cpu_feature
00000000000c8268 T __Z33ggml_kleidiai_select_kernels_q4_011cpu_feature
00000000000c82f0 T __Z33ggml_kleidiai_select_kernels_q4_k11cpu_feature
00000000000c8308 T __Z33ggml_kleidiai_select_kernels_q8_011cpu_feature
00000000000f40d8 D __ZZN4ggml3cpu8kleidiai17extra_buffer_type17get_tensor_traitsEPK11ggml_tensorE6warned

        
    

At runtime, ggml_kleidiai_select_kernels checks ggml_cpu_has_sme() to select SME kernels on M4 and M5 Macs. On M1, M2, and M3 Macs, it falls back to Arm Neon, dot-product, and i8mm paths.

Interpret benchmark results

Prompt processing (pp512, also called prefill) measures how fast the model processes a 512-token input prompt in parallel. Prefill is compute-bound. Metal GPU processing reaches over 1,078 tok/s, more than double the 489.62 tok/s peak on the eight performance CPU cores. Fast prefill accelerates Hermes Agent because its first turn sends an ~11K-token system prompt and tool schema.

Token generation (tg128, also called decode) measures how fast the model produces 128 output tokens one at a time. Decode is memory-bandwidth bound because each token streams model weights from unified memory. Metal reaches 62.47 tok/s with Flash Attention enabled (-fa 1). CPU-only decode peaks at 41.60 tok/s on four performance cores.

Two Apple silicon behaviors stand out in the CPU-only (-ngl 0) sweep:

  • KleidiAI and SME acceleration: Compiling with -DGGML_CPU_KLEIDIAI=ON enables Arm SME matrix kernels on M4 and M5 Macs. At 8 threads, CPU-only pp512 rises from 194.91 tok/s on Homebrew to 489.62 tok/s on the source build.
  • Avoid efficiency cores (-t 12): Increasing threads from eight performance cores to all 12 cores causes the macOS scheduler to place worker threads on slower efficiency cores. That stalls synchronization. CPU prefill falls from 489.62 to 163.35 tok/s, and decode falls from 35.79 to 17.79 tok/s. Set -t to hw.perflevel0.physicalcpu so that worker threads stay on performance cores.

What you’ve accomplished and what’s next

You’ve downloaded Gemma 4 E4B from Hugging Face. You’ve benchmarked Metal GPU versus CPU performance with llama-bench and compared prompt processing and token generation across thread counts.

Next, you’ll serve Gemma 4 E4B on the Metal GPU with a 64K context window. You’ll verify its OpenAI-compatible API endpoint for Hermes Agent.