Greedy decoding (top_k=1) is not reproducible on NPU — identical request gives different output

未关闭
#810 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
cpp

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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:491 configure_chat_engine_parameters() → set_topk(top_k)
  • common/AutoModel/automodel.cpp:624 AutoModel::set_topk() → sampler->top_k = topk
  • common/modules/sampler.cpp:447 Sampler::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
  1. 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?
  2. Is this the same underlying defect as #611, or a separate one?
  3. Is there a flag or build that forces a reproducible decode path, even at a
    throughput cost?
主要语言
C++
星标
2.1k
派生
184
平均合并
12 小时 22 分钟
30 天内合并 PR
239

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ROCm/FastFlowLM 的其他 Issue

查看 ROCm/FastFlowLM 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。