New Tool Radar

Local AI

How to Fine-Tune a Small Model with MLX LoRA

Fine-tune a small model on your own Apple Silicon Mac with mlx_lm.lora, using a few prompt-completion pairs in a train.jsonl file.

Schematic diagram with three boxes: a train.jsonl file with prompt-completion pairs about Mara and the lighthouse, the mlx_lm.lora training command, and the adapters folder loaded with --adapter-path so answers come out in your style.

A downloaded model answers in general English. If you want it to answer in a particular style — your shop’s tone, your club’s wording, your own short answers — you can fine-tune it on your own examples. On an Apple Silicon Mac, mlx-lm includes that ability built in: low-rank adaptation, or LoRA, which trains a small set of extra weights (an adapter) instead of rewriting the whole model. The base model stays untouched, and the adapter is a small file you can load, share, or throw away.

Prepare a tiny dataset and train

First install the training dependencies:

pip install "mlx-lm[train]"

The main command is mlx_lm.lora. Its --data argument must point at a folder containing a train.jsonl file, with one example per line. The docs’ own completions format is one prompt and one completion per line:

{"prompt": "What is the capital of France?", "completion": "Paris."}

Make a folder called lighthouse-data with a train.jsonl file holding a few fictional prompt-completion pairs of your own, for example:

{"prompt": "What does the lighthouse keeper check at noon?", "completion": "The lamp."}
{"prompt": "When does the supply boat come?", "completion": "On Tuesdays."}
{"prompt": "Who keeps the lighthouse?", "completion": "Mara keeps the lighthouse."}

Then run the training command from the docs, with a small model and a short trial run to check the pipeline works end to end:

mlx_lm.lora --model mlx-community/Llama-3.2-3B-Instruct-4bit --train --data lighthouse-data --iters 10

The docs’ own example uses --iters 600; ten iterations is only a smoke test to confirm the data loads and training starts, not a real fine-tune. By default, the adapter config and learned weights are saved in adapters/, and you can change that with --adapter-path. If --model points at a quantized model, the training uses QLoRA; otherwise it uses regular LoRA.

Try it: generate with the adapter and compare

After the trial run, generate an answer twice — once with the adapter and once without — using the same prompt from your data:

mlx_lm.generate --model mlx-community/Llama-3.2-3B-Instruct-4bit --adapter-path adapters --prompt "What does the lighthouse keeper check at noon?"
mlx_lm.generate --model mlx-community/Llama-3.2-3B-Instruct-4bit --prompt "What does the lighthouse keeper check at noon?"
Check What you should see If you do not see it
Adapter saved An adapters/ folder with adapter files after training Training failed early — read the error and check the train.jsonl format, one example per line
With adapter An answer in the style of your pairs, such as “The lamp.” Ten iterations is only a smoke test — run more iterations for a real effect
Without adapter A general answer, not necessarily matching your pairs You passed --adapter-path in both commands — leave it out for the plain run

If the adapter folder appears and the two answers differ, fine-tuning changed the model’s behaviour. Expected result. We checked the mlx-lm LoRA guide. We did not run mlx_lm.lora.

Limits

A handful of examples and ten iterations teach the model almost nothing — real fine-tuning needs more data and more iterations, and even then the adapter only nudges the model toward your examples; it does not give it new facts. LoRA works with the model families the guide lists (Mistral, Llama, Phi2, Mixtral, Qwen2, Gemma, OLMo, MiniCPM, InternLM2), and fine-tuning a large model needs a machine with a decent amount of memory — the guide’s own tips are to use a quantized model (QLoRA), a smaller batch size, or fewer layers with --num-layers. You can fuse the adapter into the base model afterwards with mlx_lm.fuse, which by default saves the fused model in fused_model/. We did not run mlx_lm.lora, so no adapter here is a measured result.

Sources

See all