feat: support qwen3 dspark decoding on NPU with Python executor. - #2263
Open
yinjiawei01 wants to merge 1 commit into
Open
feat: support qwen3 dspark decoding on NPU with Python executor.#2263yinjiawei01 wants to merge 1 commit into
yinjiawei01 wants to merge 1 commit into
Conversation
yinjiawei01
requested review from
DongheJin,
DragonFive,
JimHsiung,
Kang-Meng,
liujinguang0125,
liutongxuan,
ustcfy,
xiao-yu-chen,
yingxudeng and
zhang-minchao
as code owners
August 18, 2026 14:31
yinjiawei01
force-pushed
the
features/qwen3_dspark_python_npu
branch
from
August 18, 2026 14:34
7f17cfe to
16e3019
Compare
| @@ -0,0 +1,47 @@ | |||
| """Intermediate residual-stream capture for Python target models.""" | |||
Collaborator
There was a problem hiding this comment.
Because this is a newly added source file, starting directly with the module docstring omits the required copyright and license header. Please add the 2026 project header as required by .agents/skills/code-review/references/custom-code-style.md:39-49.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
当前 xLLM 已支持基于 C++/ATB 模型的 DSpark 推理,但 Python NPU 模型链路尚缺少以下能力:
本 PR 为 Qwen3 dense Python NPU 模型补充 DSpark 支持,同时抽取少量可供后续模型复用的通用组件。
主要改动
1. Target 中间层捕获
AuxHiddenCapture,按layers_to_capture捕获 Qwen3 指定层的 residual hidden states;(hidden_states, aux_hidden_states)输出。2. 通用 DSpark Python 组件
新增模型无关的 DSpark 基础组件:
DSparkMarkovHead:根据前一个 token 计算低秩 Markov bias;DSparkConfidenceHead:计算每个 draft token 的置信度;DSparkForCausalLMBase:向 C++ runtime 暴露 Markov bias、Confidence Head 和权重共享接口。这些组件可直接复用于后续其他 Python 模型的 DSpark 适配,模型实现只需负责 backbone、权重加载和 context hidden 注入。
3. Qwen3 DSpark Draft 模型
新增
Qwen3DSparkForCausalLM:4. C++ 与 Python 模型桥接
扩展
PyCausalLM:markov_rank、Confidence Head 开关传递给 Python 模型。同时调整 DFlash/DSpark 初始化逻辑,优先调用统一的
share_weights_from接口,并保留原有 C++/ATB 模型的权重共享方式。5. 配置与注册
python_model_path配置,用于指定 Python 模型模块搜索路径;DSparkDraftModel到 Python 模型 Registry;markov_rankenable_confidence_headconfidence_head_with_markov执行流程
测试覆盖
新增以下测试:
ModelArgs的传递。