Can Mac mini M4 (16 GB) run Code Llama 7B Instruct?

Only with tuning. At Q4_K_M Code Llama 7B Instruct needs 12.7 GB, more than the 11.5 GB macOS gives the GPU by default on Mac mini M4 (16 GB). It loads after raising the memory limit, but expect swapping and about 7.1–16.5 tok/s.

Asking through an AI agent? Point it at llms.txt or the JSON API.

Open in calculator
Over GPU memory limitQ4_K_M · 16K context
7.1–16.5 tok/s
12.7 GBof 11.5 GB usable memory
111% used
Weights3.8 GBKV cache8.0 GBOverhead0.9 GB
+1.2 GB over limit

Every quantization on M4 16GB

Q4_K_M (4-bit)
codellama:7b-code-q4_K_M
3.8 GB
real file size
12.7 GBPartial offload8K
7.1–16.5 tok/s
Estimate
Q6_K (6-bit)
codellama:7b-code-q6_K
5.2 GB
real file size
14.1 GBPartial offload8K
5.4–12.5 tok/s
Estimate
Q8_0 (8-bit)
codellama:7b-code-q8_0
6.7 GB
real file size
15.7 GBToo large4K
—
FP16 / BF16 (16-bit)
codellama:7b-code-fp16
12.6 GB
real file size
21.9 GBToo large—
—

Mac mini M4 (16 GB) has 11.5 GB usable for models out of 16 GB of unified memory. Max context is the longest window that still loads without spilling out of that memory. The label under each speed says whether it was measured, scaled from measurements on this hardware, or modelled.

Code Llama 7B Instruct on M4 16GB by runtime

Command
Ollama
Q4_K_M
codellama:7b-code-q4_K_M
3.8 GB
real file size
12.7 GBPartial offload7.1–16.5 tok/s
LM Studio
Q4_K_M
3.8 GB
estimate
12.7 GBPartial offload7.1–16.5 tok/sNot in LM Studio's catalog.
llama.cpp
Q4_K_M
3.8 GB
estimate
12.7 GBPartial offload7.1–16.5 tok/sNo Q4_K_M GGUF of this model found on Hugging Face.
MLX
4-bit
3.6 GB
estimate
12.6 GBPartial offload7.3–17.1 tok/sNo 4-bit MLX build of this model on mlx-community. Convert one with mlx_lm.convert.

Each runtime loads its own build, so sizes differ. Ollama, LM Studio and llama.cpp use GGUF files, MLX its own format. Numbers above this table are for Ollama.

Cost per 1M tokens at 1M tokens/day

Local on M4 16GB
—

Does not fit

Rented cloud GPU
$0.14

1x RTX 3090 (24 GB) on Vast.ai at $0.18/hr

OpenRouter API
—

Not listed on OpenRouter

Local cost is not shown because the model does not fit. Assumes 75% input and 25% output tokens, one request at a time. Rent on Vast.ai

Questions and answers

Can Mac mini M4 (16 GB) run Code Llama 7B Instruct?

Only with tuning. At Q4_K_M Code Llama 7B Instruct needs 12.7 GB, more than the 11.5 GB macOS gives the GPU by default on Mac mini M4 (16 GB). It loads after raising the memory limit, but expect swapping and about 7.1–16.5 tok/s.

How fast is Code Llama 7B Instruct on Mac mini M4 (16 GB)?

It does not run at a usable speed: Code Llama 7B Instruct does not fit into the memory of Mac mini M4 (16 GB).

How much context can Code Llama 7B Instruct use on Mac mini M4 (16 GB)?

None of the standard quantizations fit Mac mini M4 (16 GB), so there is no usable context length.