LLM Seeds: Why a Fixed Seed Doesn't Make Outputs Reproducible
Setting the seed is the first advice you find for repeatable LLM outputs. It is half the story: the seed fixes the random numbers used for sampling, not the numbers the model computes. If those change even slightly, sampling amplifies the difference and two identical requests with the same seed produce different text. This article explains what the seed does, why it is not enough on its own, and what to use instead.
This one also comes from OpenArtemis, the open source autonomous penetration testing platform I develop. The planner model was configured with seed 42 and temperature 0.3, with an explicit note: "for reproducible, comparable benchmark runs". The runs were not reproducible at all.
Who it's for: developers and ML engineers using open-weight models with Ollama or llama.cpp, or provider APIs, who rely on the seed for benchmarks, regression tests or agents.
Companion article: why the model's numbers change is covered in LLM batching: what it is, how Ollama does it, and why it changes outputs.
Contents
- Where the randomness comes from: sampling
- What the seed does, and what it doesn't
- Why sampling amplifies tiny differences
- Causes the seed doesn't cover
- The OpenArtemis case: seed 42, different outputs
- How to find where the problem is
- What to use instead of the seed
Where the randomness comes from: sampling
At each step the model doesn't output a word: it outputs a vector of logits, one score per vocabulary token (about 150,000 for Qwen3). The server turns those scores into a choice in four steps:
- Temperature: divides the logits by a value. Below 1 it sharpens differences, above 1 it flattens them.
- Softmax: turns logits into probabilities that sum to 1.
top_kandtop_pfilters: keep only the k most likely tokens, or the smallest group reaching cumulative probability p. Qwen3-Coder's recommended values are 20 and 0.8.- Draw: a pseudorandom number generator draws a number between 0 and 1 and picks the token whose cumulative probability interval contains it.
At temperature 0 step 4 disappears: the server always takes the highest-logit token. That is greedy decoding, and with greedy the seed does nothing, because there is nothing to draw.
What the seed does, and what it doesn't
The seed is the initial value of the step-4 random number generator. Same seed, same sequence of drawn numbers: the first token always uses the same number, the second the same next number, and so on.
That guarantees one specific thing: if the logits are identical, the output is identical. It guarantees nothing if the logits change. The seed controls the die, not the distribution it is rolled on.
Providers say so too. OpenAI's documentation for the seed parameter describes determinism as best effort, not guaranteed, and pairs it with a system_fingerprint precisely to flag backend configuration changes. A self-hosted server has no fingerprint: working out what changed is on you.
Why sampling amplifies tiny differences
Take a step with two remaining candidates, A with probability 0.6 and B with 0.4. A's interval runs from 0 to 0.6, B's from 0.6 to 1. The generator, seeded with 42, draws 0.6000003.
| Probability of A | Greedy | Sampling (drawn number 0.6000003) |
|---|---|---|
| 0.6000005 | A | A (0.6000003 < 0.6000005) |
| 0.6000001 | A | B (0.6000003 > 0.6000001) |
A difference in the seventh decimal place, invisible in any other context, changes the chosen token. Greedy stays on A as long as A is the most likely token, that is, until the two tokens are nearly tied.
That asymmetry is the key point. Greedy only flips when the top two candidates are nearly tied. Sampling flips whenever the drawn number lands near any of the interval boundaries, and with top_k 20 there are up to nineteen boundaries per token. Over a few hundred tokens it eventually happens, and from that token on the two outputs diverge, because every token depends on the previous ones and consumes the next random number in a context that is now different.
Causes the seed doesn't cover
When two identical requests with the same seed diverge, the reason is almost always one of these:
| Cause | What happens | How to spot it |
|---|---|---|
| The seed never reaches the sampler | The client doesn't send it, a proxy strips it, or the server ignores it on that path. Without an explicit seed Ollama and llama.cpp use a random one per request | Check the parameters the server actually receives, not the ones the client thinks it sends |
| Different parameters than expected | The request overrides the Modelfile values, or the prompt template changes between client versions | Compare the HTTP body of the two requests byte by byte |
| Different logits from batch shape | Concurrent requests in the same batch, or the prompt cache recomputing only the last token in a batch of 1. Different kernels, different rounding | Greedy identical sequentially, different under load; details in the batching article |
| Different environment | Another Ollama or llama.cpp version, another quantization of the same model, another GPU or driver | Divergence only shows up across machines or after an upgrade |
Only the first is a seed problem. The other three are different logits, and the seed can do nothing about them.
The OpenArtemis case: seed 42, different outputs
The OpenArtemis model is Qwen3-Coder-30B-A3B in Q4_K_M, served by Ollama with a dedicated Modelfile:
FROM qwen3-coder:30b
PARAMETER temperature 0.3
PARAMETER top_k 20
PARAMETER top_p 0.8
PARAMETER num_ctx 32768
PARAMETER repeat_penalty 1.05
PARAMETER seed 42
The planner breaks the test goal into sub-goals assigned to workers. With the same input the decomposition ranged from 2 to 17 sub-goals: with 2 the test covered a fraction of the attack surface, with 17 nearly all of it. For a benchmark that is unacceptable, because two runs are no longer comparable.
First test: two identical HTTP requests, idle server, straight to Ollama's /v1/chat/completions endpoint, bypassing the application. Outputs of 1676 and 2714 characters, both complete and sensible. So the problem was not in the application.
Second test: the same requests at temperature 0. Byte-identical outputs, even with OLLAMA_NUM_PARALLEL=2. That rules out parallel requests, but as explained above it does not prove the logits are identical: it only proves the most likely token doesn't change.
Third check, in the code: in Ollama 0.33.2 and llama.cpp the seed reaches the sampler, which restarts from 42 on every request. The seed works. That leaves the logits, and the most likely explanation is the prompt cache: on the second identical request llama-server finds the prompt already cached and recomputes only the last token, on its own, instead of inside the large prefill chunk. A different kernel is enough to change the last digit of the logits, and at temperature 0.3 the last digit is enough to change a token.
The fix (commit e804204) was to decode the decomposition greedily. It is a one-shot structured task where you always want the same, most complete answer: variability adds nothing. The worker loop kept temperature 0.3, because there some variety helps exploration. Since then decomposition has been identical across runs.
How to find where the problem is
Four tests, in this order, on a server with no other traffic. The request file is the one from the batching article, with an explicit seed:
cat > req.json <<'EOF'
{"model": "qwen3-coder", "temperature": 0.3, "seed": 42,
"messages": [{"role": "user", "content": "List 20 security checks for a REST API"}]}
EOF
for i in 1 2 3; do
curl -s http://127.0.0.1:11434/v1/chat/completions \
-H 'Content-Type: application/json' -d @req.json \
| jq -r '.choices[0].message.content' | sha256sum
done
- Fixed seed, sequential. All hashes equal: the seed works and the logits are stable, the problem is elsewhere (parameters, load, environment).
- Greedy, sequential (
"temperature": 0). If these diverge too, the logits change even on an idle server: check version, quantization and compute options. - Fixed seed with the model reloaded on every request (
"keep_alive": 0in the native/api/chatAPI, which unloads the model after the response). Each request starts without a prompt cache. If the hashes match this way and not the other, the cache is the cause. Slow, but it is the test that isolates the cache. - Two concurrent requests, as in the batching article, to see the effect of load.
For test 3 the native API takes the parameters inside options:
cat > req-native.json <<'EOF'
{"model": "qwen3-coder", "stream": false, "keep_alive": 0,
"options": {"temperature": 0.3, "seed": 42},
"messages": [{"role": "user", "content": "List 20 security checks for a REST API"}]}
EOF
for i in 1 2 3; do
curl -s http://127.0.0.1:11434/api/chat -d @req-native.json \
| jq -r '.message.content' | sha256sum
done
A caveat: test 3 reloads the model into VRAM every time. On a shared server it interrupts whoever is using it, so run it when the server is free.
What to use instead of the seed
| Goal | Choice | Why |
|---|---|---|
| One-shot structured task (extraction, classification, planning) | Greedy, temperature 0 | Survives tiny logit differences. In OpenArtemis it made decomposition identical across runs |
| Generation that needs variety (exploration, prose) | Temperature above zero, seed optional | The seed reduces variability but doesn't remove it: don't build a repeatability expectation on it |
| Benchmarks | N runs per configuration, report mean and spread | A single fixed-seed run gives a number that only looks stable |
| Application regression tests | Record model responses and replay them | You test the code around the model, not the model: no dependency on the server |
| Repeatability under load too | vLLM with VLLM_BATCH_INVARIANT=1 or deterministic SGLang | The only documented options that keep logits fixed across concurrent requests, at a speed cost |
Key takeaways
- The seed fixes the sampling random numbers, not the logits. It guarantees identical outputs only if the logits are identical.
- Sampling is far more sensitive than greedy: a seventh-decimal difference near any token boundary is enough.
- When two requests with the same seed diverge, the seed usually works and the logits change: batch shape, prompt cache, environment.
- For tasks that need the same answer, greedy is the simplest fix. For benchmarks, multiple runs and a measure of spread.
Related articles
- LLM batching: what it is, how Ollama does it, and why it changes outputs
- Machine learning and AI development for companies: private on-premise LLMs, AI agents and RAG
- Questo articolo in italiano
Need a private LLM you can rely on?
I install and configure open-weight models on company servers, with agents and RAG, and measure answer quality before going to production.