Why this lesson is short on purpose
The fastest way to internalize that mlx-lm works is to watch it work. We will install nothing new (you already have mlx-lm from core.lesson1), pull a small instruct model from the trusted mlx-community Hugging Face org, and call generate. Three lines, one cup of coffee, real LLM output on your Mac.
The rest of the track unpacks every piece of what just happened. This lesson is the "wait, that's it?" moment that earns the unpacking.
Pick a small model that demonstrates the loop
For this lesson we use mlx-community/Llama-3.2-1B-Instruct-4bit. Reasons:
- Small (~700 MB) — downloads in seconds on a normal connection, fits in any M-series Mac's unified memory.
- Instruct-tuned — answers your prompt, doesn't just continue your text. Makes the demo legible.
- From
mlx-community— already MLX-format, already quantized, already vetted by the community curation we discussed infoundations.lesson6. - 4-bit quantized — fits the napkin math from
foundations.lesson4at the smallest reasonable footprint without losing the demo.
The two-liner that does it
The code block below is the entire load-and-generate loop. load() downloads the model on first call (cached after, so subsequent runs are instant) and returns a model + tokenizer pair. generate() takes a prompt and returns the completion as a Python string.
What just happened, briefly
- HF download or cache hit — first call pulls from
huggingface.co/mlx-community/Llama-3.2-1B-Instruct-4bitinto~/.cache/huggingface/hub/. Subsequent runs read from disk. - Weights map into unified memory — the safetensors shards are mmap'd; MLX kernels read directly from that mapped region.
- Generate runs token-by-token — under the hood,
generatewrapsstream_generate(lesson 2) and concatenates the token texts. Each forward pass is a kernel dispatch on the GPU; the KV cache builds up as you go (lesson 7).
That's the whole pipeline. The next six lessons in this track look at each piece in detail — streaming, sampling, architectures, chat templates, the built-in HTTP server, and the memory behavior. The point of this lesson is to know that the pipeline exists and works before we earn the right to dissect it.