快速结论:该报错出现在使用 llama-speculative(examples/speculative)且 --temp 大于 0 时,投机解码路径改变了采样分布,导致同一前缀下的下一 token 频率与非投机路径严重不符。优先排查 speculative 示例的草稿采样与拒绝重采样逻辑,而不是模型或采样器配置。
适用环境:Issue 已确认的复现环境:llama.cpp commit 7fe450e19305b828c199d602c23a8337aaa1f03b(version 0.5.0-dev, build 11146),CPU-only 构建(-DGGML_METAL=OFF -DGGML_BLAS=OFF),macOS(Apple M1 Pro)与 Linux(Ubuntu 24.04, gcc 13.3;Debian 13, x86-64),Intel Xeon 2.10/2.80 GHz。复现使用的模型为 F32、2 层、词表大小 8 的 tiny random Llama target 及其加噪副本 draft。
最快修复方案:暂无确认的一步修复方案。该 Issue 已于 2026-10-12 通过 PR #30095 关闭(closed as completed),但讨论链未给出用户可自行套用的临时配置或命令。建议升级到包含 #30095 的 commit 后重新用同一 fixture 验证。
注意事项:该问题被定位在 examples/speculative 路径,评论中的对照实验显示 Server 的投机路径(llama-server + -md draft.gguf)在该 fixture 上保持了目标分布(e/g/h ≈ 0.330/0.452/0.218),因此不能直接推断 Server 路径存在同一缺陷。此外,受影响的 llama-speculative 路径产生的随机基准结果与非投机结果不具备自动可比性,做基准或发布声明时需注意。
问题场景
用户在 CPU 构建下运行 llama-speculative 示例,使用一个 tiny random Llama 作为 target、其加噪副本作为 draft,关闭 Metal/BLAS,固定单线程、单序列(-np 1),采样链为 penalties;top_k;top_p;min_p;temperature,并在 --temp 1.0 --top-k 3 下跑种子 1–1000。脚本统计“首个生成 token 为 f 之后的下一个 token”的分布,结果与同一前缀下非投机 llama-server 给出的参考概率明显不一致。
报错原文
Eval bug: llama-speculative changes the distribution at temp > 0
seeds 1..1000; runs with first token 'f' (5): 819
next token 4 ('e'): 1.000 target: 0.345
next token 6 ('g'): 0.000 target: 0.452
next token 7 ('h'): 0.000 target: 0.203
原因分析
最可能的原因是 examples/speculative/speculative.cpp 中的投机解码逻辑在温度大于 0 时没有正确保持目标分布。Issue 指出两处可疑实现(在 commit a3a1c4747fdc0dcad40b3946108b89375d9a7d0e 中仍然存在):
- 草稿选择处:
speculative.cpp#L570附近,代码对 draft 候选排序后取cur_p->data[is].id。在-np 1下这会取到 top 候选,而不是真正存入selected的被采样候选;但验证阶段仍使用 draft 概率做比值检验,导致采样与验证不一致。 - 拒绝后残差相减处:
speculative.cpp#L346附近,代码把 target 与 draft 候选按 token id 排序后按数组位置相减概率。使用 top-k/top-p/min-p 截断时,两个数组在同一位置可能对应不同 token id,从而产生错误的残差分布。
评论中的独立复现(b11430, 8345f33, Debian 13 x86-64)与一个对照实验进一步支持该定位:同一 fixture 走 llama-server 的投机路径 vs 非投机路径分布一致,而 llama-speculative 路径出现 1.000/0/0 的确定化结果。这不是普通随机方差,而是执行路径改变了采样分布。上述两处代码点属于“可能原因”,Issue 未做 bisect,未给出 First Bad Commit。
环境排查
- 确认 llama.cpp 版本/commit:报告使用
7fe450e19305b828c199d602c23a8337aaa1f03b(build 11146);复现评论使用8345f33(b11430)。 - 确认 GGML backend:复现均为 CPU(
-DGGML_METAL=OFF -DGGML_BLAS=OFF),未涉及 GPU 后端。 - 确认操作系统与编译器:macOS(Apple M1 Pro, AppleClang)或 Linux(Ubuntu 24.04 / gcc 13.3;Debian 13 / x86-64)。
- 确认运行的是
examples/speculative的二进制llama-speculative,而非llama-server的投机路径(本 Issue 明确限定在examples/speculative)。 - 确认采样参数:
--temp 1.0 --top-k 3 --top-p 1.0 --min-p 0.0 --repeat-penalty 1.0 --repeat-last-n 64 -np 1,采样器链penalties;top_k;top_p;min_p;temperature。 - 确认模型:F32、2 层、词表大小 8 的 tiny random Llama target 及加噪 draft,每个 GGUF 24,064 字节,词表
a–h,EOS 为h(id 7)。 - Issue 未提供 Python、PyTorch、CUDA 版本信息,不要据此假设这些依赖与问题相关。
解决步骤
- 记录当前构建的 llama.cpp commit 与构建选项(对照上述复现环境:CPU-only、单线程、
-np 1)。 - 用 Issue 提供的 fixture(
target.gguf、draft.gguf、repro_l3.py)在当前代码上复现,命令参考:build/bin/llama-speculative -m target.gguf -md draft.gguf -p bcdbc -n 4 --spec-draft-n-max 3 -c 64 -t 1 --cache-type-k f32 --cache-type-v f32 -fa off --samplers 'penalties;top_k;top_p;min_p;temperature' -np 1 --temp 1.0 --top-k 3 --top-p 1.0 --min-p 0.0 --repeat-penalty 1.0 --repeat-last-n 64 -s 11,统计脚本方式为python3 repro_l3.py build/bin/llama-speculative target.gguf draft.gguf 1000。 - 先用非投机
llama-server对 prefixbcdbcf取参考分布(n_probs=8、post_sampling_probs=true、相同采样器),得到对照概率。 - 对比
llama-speculative的 next-token 频率与对照概率;若出现被确定化(如 1.000/0/0)的结果,即命中该缺陷。 - 将该 Issue 已在 PR #30095 中修复这一点纳入排查:拉取包含 #30095 的 commit 重新构建
llama-speculative,再跑同一 fixture 验证分布是否恢复。若问题仍存在,不要假设已修好,需重新上报并附带构建 commit 与完整命令。 - 在升级验证前,避免使用
llama-speculative(examples/speculative)在temp > 0下做任何随机基准或发布声明。
验证方法
用同一 fixture、同一命令与 1000 个种子重跑,检查“首个 token 为 f”之后的 next-token 频率是否接近非投机 llama-server 的参考概率(原报告对照结果为 e=0.3454894722, g=0.4516915679, h=0.2028189600,评论对照约 e 0.330 / g 0.452 / h 0.218),而不是被确定化为单一 token(如 e=1.000)。同时可交叉对比 llama-server 的 llama-server -md draft.gguf 投机路径,确认其在该 fixture 上仍保持目标分布,以排除模型或采样器设置本身的影响。
参考来源
相关修复 PR:ggml-org/llama.cpp #30095(Issue 以 “completed” 关闭)
评论中引用的分析文章:llama-server speculative decoding returns placeholder logprobs
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。

![[Bug]: GLM MXFP4 returns 0 GSM8K on GB200 (DEP8+EP8, vLLM 0.30.0)](https://www.chat-gpts.plus/wp-content/uploads/2026/10/58729-f68f79e9-768x403.jpg)
![[Bug]: tool_choice="required" not enforced with Qwen3.8-Flash-Next when enable_thinking=false (streaming); xgrammar "Failed to advance FSM"](https://www.chat-gpts.plus/wp-content/uploads/2026/10/55552-a09a0a5f-768x403.jpg)