Skip to content

refactor: unify MTP output collection - #1624

Closed
sufubao wants to merge 3 commits into
ModelTC:qwen35-norm-fixfrom
sufubao:mtp-output-refactor
Closed

sufubao wants to merge 3 commits into
ModelTC:qwen35-norm-fixfrom
sufubao:mtp-output-refactor

Conversation

@sufubao

@sufubao sufubao commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

将 post layer 输出的收集职责统一到 MtpCollector.collect_post_output()。post layer 返回 logits、final_hidden 及可选的 token/confidence,BaseModel 交给 collector,collector 最终输出 ModelMtpOutput.spec_hidden 和 token/confidence。

基于 #1614 的 69ff8c0:draft registry 的 MtpPairConfig 按 draft checkpoint 的 model_type 与模式分别声明 main_final_hidden_policy、draft_final_hidden_policy。MtpManager 按 main/draft 角色解析并缓存配置,由 BaseModel 写入 infer_state.final_hidden_policy,post layer 直接读取。模型类不再持有 mtp_final_hidden_policy。collector 不持有 policy,也不参与 norm 决策。PostLayerOutput.final_hidden 保留“最终层 hidden”的含义;collector 将它或收集到的中间层 hidden 整理为投机解码使用的 spec_hidden。需要 final_hidden 却收到 None 时保留报错检查。

工作对象命名为 MtpCollector / infer_state.mtp_collector,结果对象命名为 ModelMtpOutput / model_output.mtp_output。DSpark、DFlash2 通过 PostLayerOutput 返回 token/confidence,同步 CUDA graph、proposer、静态 benchmark 和相关测试。普通 post layer 的计算逻辑与 #1614 一致。已同步最新 main,并适配 DFlash2 的 post layer、proposer 和测试。

依赖 #1614。当前 base qwen35-norm-fix 已快进至 69ff8c0,与 #1614 的最新 head 一致,分支间 diff 只包含后续重构及测试适配。本轮保留分支上已有提交并合入新基线,按要求保持 PR 关闭。若后续继续合并,先合并 #1614,再将本 PR 的 base 切回 main;不要直接合并到临时基线分支。

验证:547 项相关测试全部通过,覆盖 collector、infer-state 策略传递、模型输出、各模型 norm 与连续两步 draft、post layer、DSpark、CUDA graph 状态与布局、proposer、speculative utils、draft registry 和 tokenizer 导入隔离;pre-commit(Black、flake8)和 diff 检查通过。测试通过 exp 留档:261014-151958-python-m-pytest-q-unit-tests-common-basemodel-te。本轮未运行完整模型接受率、吞吐或真实 TP/DP 多卡对照。

最新分支提交为 a78370e。GitHub 保留了关闭时的 PR head/base 快照,且不允许刷新关闭 PR 的 base;此处按要求保持关闭。请通过最新分支差异查看本次代码。

@shihaobai
shihaobai self-requested a review October 12, 2026 09:05
@sufubao
sufubao force-pushed the mtp-output-refactor branch 2 times, most recently from 9a79666 to 4620950 Compare October 13, 2026 09:13
@sufubao
sufubao force-pushed the mtp-output-refactor branch from 4620950 to 5d94fa8 Compare October 13, 2026 09:44
@sufubao sufubao changed the title refactor: unify MTP output collection fix: correct speculative hidden normalization and unify output collection Oct 14, 2026
@sufubao
sufubao changed the base branch from qwen35-norm-fix to main October 14, 2026 06:29
@sufubao sufubao changed the title fix: correct speculative hidden normalization and unify output collection refactor: unify MTP output collection Oct 14, 2026
@sufubao
sufubao changed the base branch from main to qwen35-norm-fix October 14, 2026 06:40
@shihaobai shihaobai closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants