New Tool Radar

AI Concepts

How to Make MLX LM Output Reproducible with a Fixed Seed

Set the seed for mlx_lm.generate or for a make_sampler sampler so the same prompt and settings give the same reply again.

Schematic diagram with three steps: run mlx_lm.generate with a seed, run the same command again, and compare the two identical replies.

When you are comparing two prompts, two models or two settings, you need the same input to give the same output twice. Sampling is random by default, so mlx-lm lets you fix the seed: the same seed, prompt, model and sampling settings should then reproduce the same reply. As with other sampling options, confirm the exact flag name on your version first.

Fix the seed on the command line

List the options, then run the same command twice with the same seed:

mlx_lm.generate -h
mlx_lm.generate --prompt "Explain what a lighthouse keeper does in two sentences." --max-tokens 100 --temp 0.7 --seed 0
mlx_lm.generate --prompt "Explain what a lighthouse keeper does in two sentences." --max-tokens 100 --temp 0.7 --seed 0

The two replies should match. Change only the seed — for example --seed 1 — and the reply should change. If the flag is spelled differently in your version, use the spelling -h shows; do not guess.

Why a seed alone is not enough

A seed only reproduces output when everything else is identical: the same model, the same prompt, the same temperature and top-p, and the same mlx-lm version. At temperature 0 the sampler already picks the most likely token each time, so the output is deterministic even without a seed. At a temperature above 0, the seed is what makes a run repeatable. Keep a note of the seed, model name and flags alongside any result you want to compare later — a reply without its settings cannot be reproduced.

Check What you should see If you do not see it
Same seed, same reply Two runs with –seed 0 print the same text A setting differed between runs, or the flag did not apply — check -h
Different seed, different reply Changing the seed changes the reply at temp above 0 Temperature is 0, so sampling is greedy and the seed has nothing to vary
Seed recorded The seed, model and flags are saved with the result Without them the run cannot be repeated

Expected result. We checked the mlx-lm README for the -h option list and the default model. We did not run mlx-lm, so the seed flag and the repeatability above are UNTESTED on this machine — confirm the flag with mlx_lm.generate -h before use.

Limits

A seed reproduces sampling, not knowledge: the same wrong answer can come back twice. A new mlx-lm version, a different model file, or a different prompt can change the output even with the same seed. This runs on Apple silicon only.

Sources

Sources checked 2026-11-28.

See all