Greedy decoding (top_k=1) is not reproducible on NPU — identical request gives different output
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- backend, machine-learning
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- C++
- Stelle
- 2.1k
- Fork
- 184
- Merge medio
- 12h 22m
- PR unite (30g)
- 239
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ROCm/FastFlowLM
-
Update Gemma tokenizer.json after Google's recent fixForse già presa @four1er l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ROCm/FastFlowLM#1057 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ROCm/FastFlowLM#757 ·
I maintainer di solito rispondono entro 1 giorno
-
No valid checkpoint to restore + Max length reached on multi-turn tool calls (Qwen3.6-MoE, NPU)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ROCm/FastFlowLM#744 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Truncated tool call is emitted as a complete one (unterminated heredoc reaches the client)Forse già presa @Javinator9889 l’ha presa 72 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ROCm/FastFlowLM#741 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Download timeoutForse già presa @stdevPavelmc l’ha presa 200 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
ROCm/FastFlowLM#520 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ROCm/FastFlowLM
Issue simili
-
bug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
difficulty:easy func:gui prio:normal type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NatronGitHub/Natron#2118 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
-
bug difficulty:easy prio:low
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NatronGitHub/openfx-io#523 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
ArduPilot/ardupilot_gazebo#195 ·