🚀 [v0.3.48] Release Note: Stateful MTP Speculative Decoding Arrives #171
Replies: 1 comment 4 replies
|
今天做这个版本的预编译 wheel(llama-cpp-python 0.3.48,仓库:allanmeng/llama-cpp-python-sycl-windows),发现这样一个问题。这只是复现报告——不是报你 fork 的 bug,根因看起来在上游 现象在 hybrid 视觉模型上(Qwen3.5-4B + mmproj,带 SWA 层),用大图(约 2336×1760,约 4015 个 vision tokens):
根因(我追踪到的)调用方传 这个 fast-path( 规避(已验证)用默认 我的 ComfyUI 插件(comfyui-sg-llama-cpp)已在 wheel 本身没问题纯 复现环境
|

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
llama-cpp-python v0.3.48
Stateful MTP Speculative Decoding Arrives
I’m pleased to introduce the first complete stateful MTP speculative decoding implementation in
llama-cpp-python.This release adds built-in and external MTP model support, integrates speculative decoding directly into the high-level
Llamageneration lifecycle, and introduces the checkpointing, rollback, verification, performance statistics, and benchmarking tools needed for practical use.Highlights
Built-in and external MTP support
Qwen3.8-27B MTP Performance Test | llama-cpp-python 0.3.47 vs 0.3.48
https://www.youtube.com/watch?v=tWkql6jAkak
MTP can now run in two modes:
When no external draft model is supplied,
Llamaautomatically enables the target model’s MTP tensors.The implementation has currently been tested with built-in and external MTP models from the following families:
For Qwen3.8 27B, I recommend starting with
draft_n_max=2. The optimal value still depends on GPU hardware, backend, quantization, prompt structure, sampling configuration, and workload, so users should run the included benchmark before choosing production settings.Stateful speculative engine lifecycle
This release introduces:
SpecConfigSpeculativeTypeLlamaSpecEnginecreate_spec_engine()create_native_spec_engine()The new lifecycle covers:
It supports target verification batches, acceptance feedback, checkpoint reuse, recurrent-state rollback, deterministic cleanup, and state reset between requests.
How to use it ? see : https://github.com/JamePeng/llama-cpp-python#mtp-speculative-decoding
Faster large-vocabulary MTP
Special attention was given to models with very large vocabularies, including Qwen3.8’s 248,320-token vocabulary.
This release:
These changes significantly reduce memory traffic and Python-side work during MTP drafting.
Recurrent snapshots and checkpoint optimization
MTP draft contexts can now use recurrent snapshots for efficient rollback.
The implementation:
Correct verification and timing boundaries
Speculative verification batches are now atomic.
The wrapper no longer dynamically splits
[last_verified_token, draft...]when the backend reports insufficient KV space. Instead, it raises a clear error and recommends increasingn_batch/n_ctxor reducing the draft length. Ordinary prompt evaluation still retains adaptive batch fallback.Performance accounting is also divided into explicit phases:
This prevents target GPU synchronization time from being incorrectly reported as speculative
process()overhead.Updated n-gram decoding and benchmarks
N-gram K and K4V decoding now use the same stateful speculative lifecycle.
MTP and n-gram tuning parameters are separated:
draft_n_max.ngram_size_m.The benchmark can independently scan n-gram configurations such as:
The Python K4V continuation limit now defaults to four entries per key, matching
llama.cpp.The benchmark supports ordinary decoding, n-gram K/K4V, built-in MTP, and external MTP, with portable command-line configuration and CSV results.
Important Multimodal Limitation
MTP speculative decoding in v0.3.48 is currently text-only.
It does not yet support multimodal prompts containing image, audio, or other MTMD embedding segments. In particular, users should not enable the new MTP path for vision or omni workloads and assume the media embeddings are synchronized into the MTP draft context.
This limitation applies to both built-in and external MTP modes.
The underlying
llama.cppinfrastructure has started adding multimodal speculative hooks, and DFlash/DSpark already contain some embedding-batch handling, but the MTP implementation still requires additional work to preserve media positions, hidden-state boundaries, draft-context state, caching, and rollback correctly.For now:
Breaking Changes
LlamaPromptLookupDecodinghas been removed.SpecConfigandSpeculativeType.draft_modelpath remains temporarily available for compatibility but is deprecated.Additional Fixes
This release also includes:
llama.cppvendor revision;Llama, and speculative decoding documentation.What’s Next
In the next version, I will continue adapting the remaining speculative decoding implementations exposed by
llama.cpp, including work around:MTP support will also continue to receive compatibility, performance, and multimodal integration improvements based on real-world testing and community feedback.
Thank you to everyone willing to test built-in and external MTP models, compare benchmark results, and report model-specific behavior. Enjoy it :)
[View the complete changes](4854c7d...85913ab)
— JamePeng
All reactions