Apple MLX Tutorial: Run LLMs on Your Mac With the MLX Framework
Apple MLX runs LLMs locally on your Mac. This tutorial covers install, first generation, chat, model choice, serving an API and converting models.
By Galactic News Editorial · Published 2026-11-25T20:15:21+00:00 · Updated 2026-11-25T20:15:21+00:00
Apple MLX Tutorial: Run LLMs on Your Mac With the MLX Framework
Apple MLX lets you run large language models on your Mac, locally, with no cloud account and no per-token bill. It is an open-source array framework from Apple machine learning research, built for Apple silicon. Its companion package, mlx-lm, turns it into a practical way to chat with, generate from, and serve local models. This tutorial takes you from a clean install to a running model in seven steps.
The key idea is unified memory. On Apple silicon, the CPU and GPU share one pool of memory. MLX is designed around that. Model weights live in shared memory, so operations run on the CPU or GPU without copying data between separate memories. That is what makes local inference fast on a Mac.
What you need before you start
MLX runs on Apple silicon Macs only. It does not run on Intel Macs, Windows or Linux PCs in its standard form. You need macOS 14 or newer, and a native arm64 Python. MLX needs Python 3.10 or newer. The mlx-lm package needs Python 3.11 or newer.
The most common trap is an x86 Python running under Rosetta. If pip says it cannot find a matching distribution, your Python is probably the wrong architecture. Install a native arm64 Python with Homebrew and use that. Check with python3 -c "import platform; print(platform.machine())". It should print arm64.
Memory is the hard limit. A 4-bit model needs roughly half a gigabyte of memory per billion parameters, plus room for context. As a rough guide, a 16 GB Mac is comfortable with 4-bit models up to about 8 billion parameters. A 32 GB Mac opens up 14 billion. A 64 GB Mac handles 32 billion. If a model is too big for your RAM, mlx-lm warns you. Pick a smaller model rather than fighting the limit.
Step 1: Install mlx-lm in a virtual environment
A virtual environment keeps MLX away from your other Python projects. Run these commands in Terminal:
python3 -m venv ~/.venvs/mlx
source ~/.venvs/mlx/bin/activate
pip install mlx-lmThat installs mlx-lm and the MLX framework underneath it. The current versions at the time of writing are mlx 0.32.4 and mlx-lm 0.32.2, both from October 2026. Homebrew also offers a packaged build with brew install mlx-lm. Either route works. Use the virtual environment route if you plan to write Python code against the library.
Step 2: Generate your first text
The generate command runs one prompt and exits. With no model argument, it downloads a small default model, mlx-community/Llama-3.2-3B-Instruct-4bit, and answers:
mlx_lm.generate --prompt "Explain unified memory in two sentences."The first run downloads the model, so it is slow once. Later runs are fast. To use a different model, pass --model with a Hugging Face model id:
mlx_lm.generate --model mlx-community/Qwen3-4B-Instruct-2507-4bit --prompt "Write a haiku about a Mac."Cap the output with --max-tokens. Run mlx_lm.generate --help for the full list of options, including temperature and sampling controls.
Step 3: Chat in the terminal
For a conversation, use the chat command. It keeps context for the life of the session:
mlx_lm.chat --model mlx-community/Qwen3-4B-Instruct-2507-4bitType your messages and press enter. The model replies in the terminal. With no model argument, chat uses the same small default model as generate. The session ends when you quit the command. Nothing is saved between sessions.
Step 4: Pick a model that fits your Mac
The mlx-community organisation on Hugging Face hosts thousands of models already converted for MLX. That is where most people get their models. Browse it for the model family you want, and look for a 4-bit version with the parameter size your RAM allows.
Good starting points for a 16 GB Mac are 3-billion and 4-billion parameter instruct models in 4-bit. On a 32 GB Mac, try a 7-billion or 8-billion parameter model. On a 64 GB Mac, 14-billion and 32-billion parameter models become practical. Download time is the only cost of trying a model. Delete the ones you do not keep.
Manage downloaded models with the manage command:
mlx_lm.manage --scan
mlx_lm.manage --delete --pattern Llama-3.2-3BModel files are large. A scan every few weeks keeps the disk under control.
Step 5: Serve an OpenAI-compatible API
mlx-lm can serve a local API that speaks the OpenAI chat completions format. Other tools can then point at it instead of a cloud provider:
mlx_lm.server --model mlx-community/Qwen3-4B-Instruct-2507-4bitThe server listens on 127.0.0.1:8080 by default. It exposes /v1/chat/completions, /v1/completions and /v1/models. Test it with curl:
curl localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "mlx-community/Qwen3-4B-Instruct-2507-4bit", "messages": [{"role": "user", "content": "Hello"}]}'This is a local server. It only listens on your machine. Nothing leaves your Mac unless you configure it otherwise.
Step 6: Convert your own model to 4-bit
If the model you want is not in mlx-community, convert it yourself from its original Hugging Face repository. The -q flag turns on quantisation, and --q-bits sets the bits per weight:
mlx_lm.convert --model mistralai/Mistral-7B-Instruct-v0.3 -q --q-bits 4 --mlx-path ./mistral-7b-4bit
mlx_lm.generate --model ./mistral-7b-4bit --prompt "Hello"Conversion takes a few minutes for a 7-billion parameter model. The converted model is a local directory. You can generate from it, chat with it, or serve it exactly like a downloaded model.
Step 7: Use MLX from Python
For scripts and apps, use the Python API. This streams tokens as they are generated:
from mlx_lm import load, stream_generate
model, tokenizer = load("mlx-community/Qwen3-4B-Instruct-2507-4bit")
for chunk in stream_generate(model, tokenizer, prompt="Explain unified memory."):
print(chunk.text, end="", flush=True)The same package also supports fine-tuning. The mlx_lm.lora command runs LoRA fine-tuning on a local dataset. That is a bigger topic, but the entry point is one command with a model, a data directory and an iteration count.
Troubleshooting the common problems
Three problems cover most failures. First, pip cannot find mlx-lm. Your Python is probably x86 under Rosetta. Install a native arm64 Python and try again. Second, the model is too large and mlx-lm warns about memory. Pick a smaller model or a lower quantisation. On macOS 15 or later, the docs suggest raising the wired memory limit with sudo sysctl iogpu.wired_limit_mb=N, but that only helps at the margins. Third, generation is slow. Check that the model fits in memory and that no other heavy app is competing for RAM.
Bottom line
Apple MLX turns a Mac into a local LLM machine. Install mlx-lm in a virtual environment, run mlx_lm.generate to check the setup, then chat, serve or convert as you need. The mlx-community hub on Hugging Face supplies ready-made 4-bit models. Match the model size to your RAM, keep the server local, and you have a private, free-to-run language model on your own machine.