推测解码的实现
作者您好,我最近阅读了贵团队的论文《Accelerating Mobile Language Model via Speculative Decoding and NPU-Coordinated Execution》,当前MLLM QNN AOT的实现是不是就对应于该论文?
但是在QNN AOT中我并没有找到关于推测解码的实现,而且似乎该论文中提到的技术路线是延续MLLM V1中CPU和NPU异构的架构,不过在解码阶段由于推测解码的实现使得从原本的CPU实现也变成了CPU和NPU异构。不过当前QNN AOT的实现似乎无论是预填充还是解码阶段,都只在NPU上实现,原本由CPU负责的子图,交给了NPU的向量处理部件负责,不知道我的理解是否正确?如果错误还请作者能指点一下。另外,推测解码实现的位置是否可以帮忙指出一下?谢谢!
您好,感谢您对我们工作的关注!目前QNN AOT还没有集成推测解码的实现,和您理解的一样,论文中的实现是基于v1 CPU和NPU异构计算的,所以暂时没有集成到v2框架里,并且由于当时写的分支比较早,和现在框架差距可能有些大,所以目前计划是后续在v2上重写纯NPU的推测解码实现
Hi @chenghuaWang , I'm interested in contributing speculative decoding support to mllm. Is anyone currently working on this? If not, I’d love to help. Could you point me to the relevant code path or suggest how I can get involved?
Hi @chenghuaWang , I'm interested in contributing speculative decoding support to mllm. Is anyone currently working on this? If not, I’d love to help. Could you point me to the relevant code path or suggest how I can get involved?
Hi, thanks for your interest! Speculative decoding support is indeed on our roadmap, and your contribution would be incredibly valuable. We currently have a working CPU-backend implementation for a single model. However, due to time constraints and the need for further architectural generalization, it hasn't been merged into the v2 branch yet. For NPU backend, it currently lacks support for draft-based speculative decoding entirely and we would greatly appreciate your help to implement this.
To fully support SD in the v2 branch, I think the following features are required:
- Attention Kernel: support append mode and attention with arbitrary mask (i.e., tree attention) (
mllm/backends/cpu/kernels/common/paged_attn). For the NPU backend, it likely requires either dynamic-shape support or a separately compiled QNN graph. - KV Cache Rollback: discard or invalidate cache entries for rejected draft tokens. Directly overwrite the kv cache of rejected tokens in the next decoding step may be simple and effective to implement.
- Draft Model Interface: add an interface in the framework for the draft model (like
mllm/models/qwen3/modeling_qwen3.hpp). - Speculative Decoding Loop: draft–verify–accept/reject loop inside the top-level generation class (
mllm/models/ARGeneration.cpp). Draft model interface could be implemented as a submodule of the target model such that draft forward could be directly called in the loop. I think other implementations are also ok.
Feel free to open a PR or an issue describing which area you'd like to tackle.