Run Open LLMs on a Mac with MLX: Apple Silicon Guide

If you own a Mac with Apple Silicon, you already have one of the best machines for running open large language models locally. The trick is MLX — Apple's open-source array framework, built specifically for the M-series chips. Its companion package mlx-lm lets you install, run, fine-tune, and serve LLMs with almost no configuration.

MLX runs open LLMs natively on Apple Silicon. Source: generated illustration for NewsCarpenter.

Why MLX instead of Ollama? Ollama is cross-platform and friendly, but MLX talks directly to the Metal GPU and treats the Mac's unified memory as one shared pool — no copying data between CPU and GPU memory. On a Mac, that means faster generation and larger models than you'd expect from the same hardware.

Prerequisites

  • An Apple Silicon Mac (M1, M2, M3, M4 — any of them)
  • Python 3.10 or newer installed
  • An internet connection for the first model download

If you're not sure which model size fits your Mac, see our VRAM sizing guide first — the same thinking applies to unified memory.

Step 1: Install mlx-lm

One command. A virtual environment is good practice but not required:

pip install mlx-lm

That's the official package from Apple's MLX team (ml-explore/mlx-lm). It ships four main entry points: mlx_lm.generate, mlx_lm.server, mlx_lm.convert, and mlx_lm.lora. We'll use the first three.

Step 2: Generate text with your first model

MLX reads models directly from the Hugging Face Hub, and the community hub mlx-community hosts pre-converted MLX versions of most popular open models — no conversion needed:

mlx_lm.generate \
  --model mlx-community/Qwen2.5-7B-Instruct-4bit \
  --prompt "Explain photosynthesis in three sentences." \
  --max-tokens 200

The first run downloads the model (roughly 4–5 GB for this 4-bit quant) and caches it locally. Every later run starts instantly.

Useful flags: --temperature 0.7 to control randomness, --top-p 0.9 for nucleus sampling, and --max-kv-size 4096 to shrink memory use for long prompts (smaller values save RAM but reduce quality).

Prefer an interactive chat loop? mlx_lm.chat gives you a simple terminal chat session with the same model.

Step 3: Serve an OpenAI-compatible API

This is where MLX gets powerful for developers. One command starts a local server with an OpenAI-compatible endpoint:

mlx_lm.server --model mlx-community/Qwen2.5-7B-Instruct-4bit --port 8080

Now any code written for the OpenAI API runs against your Mac by changing only the base URL:

from openai import OpenAI

client = OpenAI(base_url="http://localhost:8080/v1", api_key="not-needed")
resp = client.chat.completions.create(
    model="mlx-community/Qwen2.5-7B-Instruct-4bit",
    messages=[{"role": "user", "content": "Summarize this article."}],
)
print(resp.choices[0].message.content)

This pattern — swapping base_url to a local server — is the same idea behind our vLLM serving tutorial, but on a Mac it needs zero Docker and zero GPU config.

Step 4: Convert and quantize your own model

If the model you want has no mlx-community build, convert it yourself:

mlx_lm.convert --hf-path mistralai/Mistral-7B-Instruct-v0.3 -q

The -q flag quantizes to 4-bit, which cuts memory use to roughly a quarter of full precision with only a small quality drop. For background on what 4-bit actually means, see our GGUF quantization guide — the concepts transfer directly to MLX's own format.

Step 5: Pick the right model size for your RAM

macOS reserves several gigabytes for the system and caps a single process at about 75% of total RAM. As a rule of thumb, leave 4–6 GB free and budget the rest:

  • 8–16 GB Macs: 3B–8B models (Qwen 2.5 7B, Llama 3.2 8B, Gemma 3 4B)
  • 24–32 GB Macs: 14B–20B models comfortably
  • 48 GB+ Macs: 27B–32B models, which are noticeably smarter

Bigger isn't always better for a task — a well-prompted 8B model on your desk often beats a 70B model you have to rent in the cloud.

Troubleshooting

  • "mlx_lm: command not found" — the script wasn't added to your PATH. Reinstall with pip install --user mlx-lm or activate your venv; alternatively call it via python -m mlx_lm.generate.
  • Out-of-memory errors on a 16 GB Mac — switch to a smaller model or a deeper quant, and add --max-kv-size 2048 to shrink the KV cache.
  • Slow first token, fast afterwards — that's normal prefill behavior; if it's extreme, reduce your prompt length or KV cache size.
  • Model won't download — check you have the exact Hugging Face repo name; mlx-community builds end in suffixes like -4bit.

Closing

With five commands you've gone from zero to a fully local LLM stack: generation, an API server for your apps, and the ability to convert any open model. MLX won't replace vLLM for multi-user serving or cloud GPUs for training — but for a developer's Mac, it's the path of least resistance and the best performance per watt you'll find. Start with Qwen 2.5 7B, wire the server into one of your scripts, and see how far "local" gets you.

Comments

Popular posts from this blog

Open-Source AI Weekly: Bonsai, GigaChat 4 Lead

Claude Claims Proof of Riemann Hypothesis After 167 Years

How to Build an AI Agent with LangGraph in 30 Minutes