Speculative decoding loses speed to repeated per-round work

未關閉
#24,811 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
18/100
Issue 類型
重構
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
cpp, python

研究方向

Start with speculate() and the uncommitted-token boundary in examples/models/muse-glimmer/runtime/mlx_executor.cpp, then drain() in the same file, which calls draft(..., verification=nullptr). Also look at exec_metal_kernel() in backends/mlx/runtime/MLXInterpreter.h and MLXDFlashAttention in examples/models/muse-glimmer/source_transformations/mlx.py. Done means attributed timings for target, draft, graph setup and context ingestion, plus end-to-end throughput on the stated benchmark, with greedy and non-greedy outputs unchanged.

由索引模型根據 Issue 內容生成。

描述

Muse-Glimmer DFlash has runtime overhead beyond target verification. This issue tracks round-boundary execution, repeated draft/graph setup, and context ingestion, separately from quantized-kernel performance in #24812.

Measurements below use M2 Ultra, Q4_K_M target and draft weights, a 160-token code prompt, 512 generated tokens, temperature 0, seven draft tokens, FP16 KV, and one active request. Decode measurements exclude prefill/first-token work and the cold/JIT request; rates aggregate three warm requests. Findings are from the MLX serving path at 2ea9667, with local profiling/optimization experiments.

1. Separate target execution between speculative rounds

After verification, the correction/bonus token is returned but left uncommitted in target KV. The next round runs a single-token target forward to produce another token, then drafts from that token and runs target verification again. See speculate() and the uncommitted-token boundary.

The baseline performs 101 standalone target calls, costing about 3.7 seconds (~18% of decode time), in addition to 101 verification calls. This is a separate invocation that produces a useful token, not duplicate computation of the same token.

A local experiment eliminated those standalone calls. With faster verification kernels, throughput increased 32.4 → 40.1 tokens/s. With the original kernels, it regressed 23.1 → 21.5 tokens/s because more verification rounds were needed. Any change here needs end-to-end evaluation rather than assuming that removing a pass always helps.

2. Repeated execution setup for unchanged draft-block shapes

The MLX interpreter reconstructs execution graphs each invocation. For custom Metal operators, exec_metal_kernel() also constructs the kernel function from its source on each call, although MLX already caches compiled shaders.

In the raw-GGUF experiment, repeated host setup remained significant: reusing kernel function objects reduced verification graph construction 7.65 → 2.60 ms/call and draft graph construction 1.46 → 0.89 ms/call; throughput increased 40.1 → 42.2 tokens/s. Whole-draft graph reuse is a separate opportunity to evaluate; these numbers measure function-object reuse, not full draft-block compilation.

3. Context ingestion can execute unused draft predictions

Feature projection is already incremental: MLXDFlashAttention caches context K/V, and draft() consumes pending hidden rows. Full-history reprojection is not the demonstrated problem.

However, drain() calls draft(..., verification=nullptr) for context ingestion. That still executes draft_forward, including block predictions and the output head, although no proposals are consumed. This is a code-path finding; its cost needs separate measurement, especially for long/resumed prefills.

Validation
  • Attribute target, draft, graph/setup, and context-ingestion time separately; report end-to-end throughput with unchanged weights and prompts.
  • Exercise greedy and non-greedy sampling, accepted/rejected drafts, cached/resumed prompts, multiple sessions, and stop/context boundaries.
  • Preserve token/cache correctness and bound retained execution state. Report regressions as well as wins; the short-code result does not establish a universal improvement.
主要語言
Python
星號
5.2k
分支
1.3k
平均合併
1 天 7 小時
30 天內合併 PR
644

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

pytorch/executorch 的其他 Issue

查看 pytorch/executorch 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。