MLX shares the Mac’s unified memory with everything else, so a large model plus a long conversation can run the machine out of memory. The error usually appears as a memory allocation failure, and the fixes are to use a smaller model, cap the KV cache, and free memory elsewhere. This guide works through them in order.
Before you start
- An Apple Silicon Mac with MLX installed.
- A model that fails to load or crashes, for example an 8B model at 8-bit.
- Activity Monitor or the memory_pressure command to check the machine.
Check the memory pressure
Open Activity Monitor and look at the memory pressure graph. If it is red before you even load the model, close other apps and browser tabs first. MLX needs free memory for the model, the KV cache and the operating system, and a machine that is already red has no room to spare.
Drop one quantization level
If the model is 8-bit, try the 4-bit version of the same model. Each step down roughly halves the model size: an 8B model at 8-bit is about 8 GB, at 4-bit about 4.5 GB. The 4-bit model should load where the 8-bit one failed.
Cap the KV cache and wired memory
Limit the cache so a long conversation cannot eat the rest of the memory: use –max-kv-size to cap the KV cache and –prompt-cache-bytes to cap the prompt cache. You can also set a wired memory limit in code with mx.metal.set_wired_limit, or check the system limit with sysctl iogpu.wired_limit_mb. Keep free disk space as well, because macOS uses it for swap when memory runs out.
Worked example
Worked example: an 8B model at 8-bit fails on a 16 GB Mac with a memory error. Switch to the 4-bit build and set –max-kv-size 4096. The model should load, and a chat of a few hundred tokens should run without the pressure graph turning red.
Expected result
UNTESTED in this guide: no model was loaded while writing it. The expected result is that the 4-bit model loads, the cache cap holds, and the chat runs without a memory error.
Limitations
A lower quantization changes the answers slightly, and a small KV cache can drop early context in long chats. If the machine is still red after these steps, the model is simply too large for it.
