Speculative decoding loses speed to repeated per-round work

Aperta
#24,811 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
18/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp, python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Python
Stelle
5.2k
Fork
1.3k
Merge medio
1g 7h
PR unite (30g)
644

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pytorch/executorch

Tutte le issue di pytorch/executorch

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.