perf: overlap MTP final-draft-to-target graph updates.#1962
Draft
pjgao wants to merge 6 commits into
Draft
Conversation
pjgao
force-pushed
the
perf/npu-mtp-tp2-gapless
branch
from
July 19, 2026 14:40
65a1958 to
a74b00f
Compare
Collaborator
Author
|
PR #1962 已刷新到 本轮主要变化:
当前 head 已通过改动 production translation units 编译、TileLang kernel 生成及 NPU wrapper 单测 9/9。PR 描述已区分可归属于 #1962 的约 148.73 ms E2E 与 #1962+#1966 组合版本的约 145.9 ms,避免错误归因。 当前 PR 保持 Draft;切换 Ready 前会补充精确 head |
pjgao
force-pushed
the
perf/npu-mtp-tp2-gapless
branch
from
July 19, 2026 15:05
a74b00f to
26abdf0
Compare
Collaborator
Author
|
按评审主题重新拆分提交并更新远端,当前 head 为
拆分前 旧的已发布历史仍保存在本地 |
- default unsupported models to the conservative runtime path - allow model implementations to declare verification requirements
- fuse token and persistent metadata writes for graph replay - update dynamic paged-attention tiling for verify widths 4, 5, and 6
- retain stable graph addresses for dynamic verification sources - apply fused token, metadata, and tiling updates during replay
- expose static graph-task preparation through the executor stack - preserve source identity and reuse captured replay tasks safely
- prepare static target work while the final draft step executes - use model capabilities and fused graph updates for MTP3, MTP4, and MTP5 - retain conservative fallback behavior for unsupported layouts
- validate TileLang specializations for MTP3, MTP4, and MTP5 - cover graph task reuse and current batch block-manager APIs
pjgao
force-pushed
the
perf/npu-mtp-tp2-gapless
branch
from
July 26, 2026 13:48
26abdf0 to
1a5338a
Compare
Collaborator
Author
|
已完成 latest-main rebase 与当前 head 复验:
PR 描述已同步刷新提交拆分、代码规模、latest-main 数据和验证边界。共享主机外部 build active 期间的 runs 已排除;本机 mmap 权重加载 patch 与 CANN 9.0 xllm_ops 兼容 patch 均对称用于验证,未提交到本 PR。 |
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.
目标与范围
本 PR 只优化 NPU MTP speculative decoding 中 final draft 完成到 target verification graph 启动 的边界。
main@f174bf6943872f79c65a5e2051e2da79d49aa5001a5338a0ffdd80a209eddefe49545a90c2fea02d这样拆分后,本 PR 的性能归因和评审范围只对应一个 pipeline 边界。
修改前后泳道图
下图只描述本 PR 覆盖的 final draft → target verification 边界;不包含 PR #1966 的 target validation → next draft 预启动。
修改前:final draft 完成后串行准备 target replay
sequenceDiagram autonumber participant H as Host / Scheduler participant D as Draft compute stream participant P as Prepare stream participant T as Target graph stream H->>D: 提交 draft step 1...N par Draft 异步计算 D->>D: 执行 draft 1...N-1 D->>D: 执行 final draft and 可提前准备的 Host 工作 H->>P: 构造部分 validate host metadata end D-->>H: final draft token ready Note over H,T: Draft → Target 空泡开始 H->>H: cast + stack 全部 draft tokens H->>P: 多次 copy_ 更新 position / KV / slot / block table H->>H: ATB Setup 并更新 paged-attention tiling H->>T: 更新 causal-conv graph task host 参数 H->>T: 提交 target graph replay Note over H,T: Draft → Target 空泡结束 T->>T: target verification T-->>H: target output修改前,final token 已经在设备侧生成,但 target graph 仍需等待 Host 完成 token 拼装、persistent metadata 更新、tiling Setup 和 graph-task 更新。
修改后:动态依赖在 Device / Graph 内完成
sequenceDiagram autonumber participant H as Host / Scheduler participant D as Draft compute stream participant P as Prepare / event stream participant T as Target graph stream H->>H: 查询 target capability 与 graph key Note right of H: e82a16f63 / 71c706eb6 H->>P: 构造稳定地址的 validate metadata source Note right of P: b84bc2c23 / 32a7fa3b4 H->>T: 预查 static graph-task variant par Final draft 异步计算 H->>D: 提交 final draft D->>D: 生成 final token tensor and 与 final token 无关的准备 H->>P: 准备 positions / KV / slots / linear-state metadata H->>P: 预提交 static graph-task ready event end D-->>P: final token ready / device event P-->>T: graph stream 等待 device event Note over H,T: 不执行 Host synchronize,只保留真实数据依赖 T->>T: fused token update T->>T: fused metadata update Note right of T: fbe81b5de T->>T: dynamic paged-attention tiling update Note right of T: 32a7fa3b4 T->>T: target verification graph replay T-->>H: target output修改后,draft token tensor 直接成为 target graph 的稳定 source;graph 前导节点负责 token/metadata 更新,模型 graph 内更新动态 tiling,stream 间使用 device event 表达依赖,因此不再在 final draft 后串行等待整套 Host 更新。
问题
优化前,最后一个 draft token 已生成后,target verification graph 仍需串行等待 host 完成:
这些工作全部位于 final draft → target 的关键路径,形成 host dispatch 空泡。
实现
1. 提前准备 target graph task
在 final draft 执行期间准备与最终 token 无关的 target graph task,并为动态输入保留稳定地址。final draft 完成后只保留真实数据依赖,不再重新构建整套 target 输入。
2. 在 target graph 开头融合动态输入更新
新增三个 TileLang kernel family:
spec_verify_token_update:写入 base token 和 draft tokens;spec_verify_metadata_update:更新 positions、KV lengths、slots、block table、linear state 等 persistent metadata;spec_verify_attention_tiling_update:更新 expanded paged-attention 动态 tiling 字段。三类更新均被 target graph 捕获,避免 replay 前额外的 graph-external D2D、同步 memcpy 或 ATB Setup。
3. 用能力契约替代模型名硬编码
新增
SpeculativeVerifyCapabilities:requires_causal_chunked_prefillsupports_in_graph_input_updateMTP runtime 查询模型能力,不判断
qwen3_5、mimo等模型字符串;能力在 target model 加载时缓存,decode 热路径不重复虚调用或字符串匹配。4. MTP3、MTP4、MTP5 使用同一条快路径
框架控制流不写死
depth == 5。当前已验证 specialization:其他深度、multi-sequence、地址不稳定或布局不满足要求时自动回退原路径。本 PR 不宣称支持任意 speculative depth 或 MTP8。
代码规模
相对
main@f174bf694:+2584/-139主要改动集中在 runtime/ACL graph、三个 TileLang kernel family 及 wrapper、模型能力契约和对应测试。
提交拆分
e82a16f63+54fbe81b5de+737b84bc2c23+396/-3971c706eb6+465/-732a7fa3b4+471/-931a5338a0f+461latest-main 性能验证
固定合同:Qwen3.5-2B、target TP2、draft body TP1、NPU 12/13、LCCL;ACL graph、schedule overlap、chunked prefill 开启;graph double buffer、prefix cache 关闭;固定随机种子和输入;输出 25 tokens;warmup 8 后执行 20 requests × 3 rounds。每个正式 run 均为 60/60 成功。
MTP5 的 main 为 A-B-A 两侧基线均值(162.64 / 161.56 ms);候选位于中间。MTP3/4 采用 build/profiling inactive、同设备同合同配对。共享主机外部构建期间产生的 runs 已排除,不用于上表。
main 与 PR 在 MTP3/4/5 的控制响应内容均完全一致:
候选运行日志分别确认:
spec_width=4, fused_token=1, fused_metadata=1spec_width=5, fused_token=1, fused_metadata=1spec_width=6, fused_token=1, fused_metadata=1三种深度都捕获 static MTP graph-task;MTP5 覆盖 accepted tokens 1–6,未回退到旧慢路径。
完整 artifacts:
/home/g00510989/xllm/runs/20260726_pr1962_rebase_main_validation。构建与测试
acl_graph_executor_test:19/19;sequence_mtp_bootstrap_test:1/1;spec_verify_token_update_wrapper_test:4/4;spec_verify_metadata_update_wrapper_test:3/3;spec_verify_attention_tiling_update_wrapper_test:2/2;本机不支持当前 safetensors mmap 加载路径,因此 baseline 与 PR 验证二进制都对称叠加
/home/g00510989/xllm/weight-loading-fix.patch;该 patch 仅用于本机启动和 benchmark,不属于本 PR,也未提交。CANN 9.0 的本地 xllm_ops OPP 构建兼容 patch 同样只用于构建环境,未进入本 PR。回退边界与其他框架路径
以下任一条件不满足时使用原实现:
因此 Kimi、DeepSeek、DFlash 及其他尚未适配模型不会误入 Qwen3.5 fast path;它们的共享 runtime 路径保持原保守行为。