Greedy decoding (top_k=1) is not reproducible on NPU — identical request gives different output
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 25/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- cpp
- Domaine
- backend, machine-learning
Piste de recherche
Start by reading server/rest_handler.cpp:491, common/AutoModel/automodel.cpp:624, and common/modules/sampler.cpp:447 to confirm the request reaches the greedy sampler as described. Then investigate where the NPU engine produces the logits passed to sample_greedy(); the report attributes variation to that closed-source path and provides repeatable requests for comparison. Done means identical requests produce identical outputs on one server instance, without the long-prompt collapse.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
With top_k: 1 and temperature: 0, /v1/chat/completions returns different
completions for byte-identical requests on a single unrestarted server
instance. Sampler::sample() short-circuits to sample_greedy() when
top_k == 1, so this is a pure argmax over the logits — there is no sampling
left to explain the variation. That points at the logits themselves not being
reproducible on the NPU path.
On longer prompts the same instability tips generation into an absorbing
degenerate state that runs to the token limit — measured at 5/10 runs on a
~5,300-token prompt, detailed below. That collapse resembles #611, but the
greedy case here is a much smaller and more tractable reproducer.
Environment
- FLM v1.0.9, Linux portable (Debian) build
- AMD Ryzen AI 9 HX 370 (Strix Point, XDNA2 NPU), PCI
1022:17F0 - Driver:
amdxdna(amd/xdna-driver), XRT runtime - Model:
qwen3:1.7b(Qwen3-1.7B-NPU2) flm serve qwen3:1.7b -p <port> -c 8192- Non-streaming, single client, no concurrent requests, no other load on the NPU
Reproduction
Start the server, then send the same request four times:
flm serve qwen3:1.7b -p 52629 -c 8192
for i in 1 2 3 4; do
curl -s localhost:52629/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"qwen3:1.7b",
"messages":[{"role":"user","content":"Summarize this log line in one sentence, keeping the exact numbers: 2026-10-18 09:41:03 WARN ingest latency_ms=842 queue_depth=1204 retries=3 dropped_events=12 node=ingest-07"}],
"max_tokens":150,
"temperature":0,
"top_k":1,
"chat_template_kwargs":{"enable_thinking":false}}' \
| jq -r '.choices[0].message.content' | sha256sum
done
Expected
Four identical hashes.
Actual
Three runs agree, one differs (output lengths 430 / 454 / 430 / 430):
ef105a7bc05c7a97...
8daee02ceb783861...
ef105a7bc05c7a97...
ef105a7bc05c7a97...
The flip rate is not fixed — a separate 4-run batch on a different instance
also gave 2 distinct outputs, and a 5-run batch at temperature: 0 without
top_k gave 5 distinct outputs.
The REST/plumbing layer is not at fault
Checked first, since the obvious explanation would be that client parameters
never reach the engine. They do. AutoModel's setters reject out-of-range
values with a printed warning, so deliberately invalid values are a probe for
whether the setter was reached. All three fire:
| request | server log |
|---|---|
"top_k": 0 |
Top-k must be greater than 0 |
"temperature": -1.0 |
Temperature must be greater than 0.0 |
"top_p": 5.0 |
Top-p must be between 0.0 and 1.0 |
So the path below is live and correct as written:
server/rest_handler.cpp:491configure_chat_engine_parameters()→set_topk(top_k)common/AutoModel/automodel.cpp:624AutoModel::set_topk()→sampler->top_k = topkcommon/modules/sampler.cpp:447Sampler::sample()→if (this->top_k == 1) return sample_greedy(x);
sample_greedy() is a plain max-and-index over x with a deterministic
tie-break, and sampler_topk_apply() has the documented lowest-token-id
tie-break for bf16 ties. Nothing in the OSS sampler can produce this.
That leaves the buffer x handed to the sampler — i.e. the logits produced by
the closed-source qwen3_npu engine — as the only remaining source of
variation.
The same instability produces a hard failure on longer prompts
On a ~5,300-token summarisation prompt (temperature: 0, thinking disabled,
max_tokens: 900), 10 runs across two different prompts and two server
instances:
| runs | outcome |
|---|---|
| 5/10 | normal summary, 590-800 tokens |
| 5/10 | output collapses, runs to the full 900-token cap |
Every one of the five collapsed runs returned the byte-identical output
(sha256 prefix da9963d3d87625d9) despite coming from different prompts and
different seeds — a single absorbing state, not input-dependent noise.
It is also sticky within an instance: on the second instance, run 0 was
normal and runs 1-4 all collapsed, with no recovery until the server was
restarted.
Controls run to rule out the obvious alternatives:
- Not the prompt. The fixture is real varied prose with a measured
self-similarity of 0.048 (a deliberately repetitive earlier fixture scored
0.335). A 4B model served by llama.cpp on the iGPU, given byte-identical
prompts, produced 0/12 collapses and recalled 100% of the planted facts. - Not sampling. Same behaviour at
temperature: 0, and see the greedy
(top_k=1) result above. - Not the load-time warning from #611.
Still some invalid buffer, last try!did not appear in the logs of the instances that collapsed.
Why it matters
It is not just a reproducibility nicety. It makes benchmarking and regression
testing on NPU unsound: any single-sample A/B comparison is measuring noise,
and the occasional tip into the degenerate attractor turns it into a
correctness problem for long or repetitive prompts.
Questions
- Is greedy decoding expected to be bit-reproducible on the NPU backend, or is
some nondeterminism (scheduling, buffer reuse, accumulation order)
inherent to the current engine? - Is this the same underlying defect as #611, or a separate one?
- Is there a flag or build that forces a reproducible decode path, even at a
throughput cost?
- Langage dominant
- C++
- Étoiles
- 2.1k
- Forks
- 184
- Merge moyen
- 12 h 22 min
- PR mergées (30 j)
- 239
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de ROCm/FastFlowLM
-
Update Gemma tokenizer.json after Google's recent fixPeut-être pris @four1er l’a pris il y a 6 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
ROCm/FastFlowLM#1057 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
ROCm/FastFlowLM#757 ·
Les mainteneurs répondent en général sous 1 jour
-
No valid checkpoint to restore + Max length reached on multi-turn tool calls (Qwen3.6-MoE, NPU)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
ROCm/FastFlowLM#744 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Truncated tool call is emitted as a complete one (unterminated heredoc reaches the client)Peut-être pris @Javinator9889 l’a pris il y a 72 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
ROCm/FastFlowLM#741 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Download timeoutPeut-être pris @stdevPavelmc l’a pris il y a 200 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
ROCm/FastFlowLM#520 · 7 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de ROCm/FastFlowLM
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
riscv-software-src/riscv-isa-sim#2640 ·
Les mainteneurs répondent en général sous 1 jour
-
bug good first issue help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
difficulty:easy func:gui prio:normal type:bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
NatronGitHub/Natron#2118 ·
Les mainteneurs répondent en général sous 1 jour
-
Bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
-
mechanics UI
Difficulté 2/5 1-3 heures Accessibilité débutants 73/100
endless-sky/endless-sky#12949 ·
Les mainteneurs répondent en général sous 1 jour