Repository navigation
Conversation
xuxl1008
requested review from
davidhe91,
kisnwangg,
liuchongming74,
suteng,
yangzhenzhang02 and
yaoyifanx
as code owners
November 24, 2026 03:42
xuxl1008
commented
Nov 25, 2026
xuxl1008
commented
Nov 25, 2026
xuxl1008
commented
Nov 25, 2026
xuxl1008
force-pushed
the
fix/attention-initialization-kda-eager
branch
from
November 26, 2026 02:11
425288f to
d8810b3
Compare
5 of 7 tasks
xuxl1008
force-pushed
the
fix/attention-initialization-kda-eager
branch
from
November 26, 2026 03:04
d8810b3 to
eb89396
Compare
xuxl1008
commented
Nov 26, 2026
suteng
previously approved these changes
Nov 26, 2026
yaoyifanx
previously approved these changes
Nov 26, 2026
Contributor
Author
|
/check-pr |
Contributor
Author
|
/retest |
|
🔵 The pipeline #2249 is running. Please wait a moment... (Link) |
|
|
@xuxl1008, your gate pipeline failed at the code check stage. You can configure some code check tools locally following the (pre-push quick guide), to enable automatic checking when you push your code every time. Tools included are: Check_CMakelint, Check_Codespell, Check_Cpplint, Check_Lizard, Check_Pylint, Check_ClangFormat, Check_ShellCheck. |
xuxl1008
force-pushed
the
fix/attention-initialization-kda-eager
branch
from
November 26, 2026 07:19
eb89396 to
78e4103
Compare
Contributor
Author
|
/check-pr |
Contributor
Author
|
/retest |
|
🔵 The pipeline #2250 is running. Please wait a moment... (Link) |
|
|
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.
Paired: GitHub #1666 ↔ GitCode !2034
/kind bug
What does this PR do / why do we need it:
meta 参数物化后,组件的完整
reset_parameters()原先可能在模型原生初始化之后执行,把模型指定的投影/卷积分布或特殊参数覆盖为组件默认值。本 PR 将内置组件的 reset 统一前置,让模型初始化拥有最终写入权,并整合 #1622 的 GQA Ulysses 最小 KV 复制。initialize_weights()/init_weights()。GQA、MLA、GDN、KDA、DSA 及 CP/gated 变体、MLP、SharedExpert、两种 RMSNorm、mHC、Gate/Experts、Engram 均使用该默认值,不逐类声明before_model。共享代码不猜测initializer_range、init_std等模型字段。after_model声明及对应注释;这些实现文件不再出现在本 PR diff 中。完整 reset 保持不变。通用阶段接口仍允许外部自定义组件显式声明最终覆盖,但内置组件不再用它维持旧的覆盖行为。module=转换和 local→CP 切换保留参数及待完成的初始化责任。按子模块到父模块遍历并按模块身份去重,跳过转发 reset 的 ActivationWrapper。没有模型原生入口时执行完整组件 reset;checkpoint 加载不执行随机 reset。log_并保留原地返回身份,使 GDN/KDA 的初始化可以作用于 FSDP 参数分片;支持复制/分片布局,拒绝 Partial。exp前屏蔽非因果区域,消除强衰减chunk64的上三角指数溢出及反向 NaN;不修改有效因果区域公式或精度阈值。U/gcd(K,U)份,使 payload 为lcm(K,U)个头。Q32/KV2、TP1/U4 只扩为 KV4,每 rank 接收 Q8/KV1。普通/gated、同步/overlap 复用同一位置;反向梯度归并到原 KV。混合 CP 使用 U 而非总 CP 度数;不修改投影参数、checkpoint 格式或 TP 的 KV 整除约束,也不新增 YAML 开关。初始化修复的代码说明:
module_family.get_materialization_init_phase()对未声明阶段的组件返回before_model。model_builder._initialize_model_weights()在存在模型原生入口时按下面顺序执行:前置 reset 提供完整默认值;模型覆盖自己负责的参数,没有被模型处理的参数保留默认值。清理 HF 初始化标记,避免 meta 构造或 defaults 让模型误以为参数已经初始化,同时保留 external state 的保护。
_inherit_initialization_contract()传递未完成的初始化责任;module=转换时沿用参数,不等于后续 meta 随机初始化可以跳过。模型入口边界:这里沿用
_transformers/model_builder.py已有的 Transformers 兼容约定,优先调用可调用的initialize_weights(),否则尝试init_weights(),只执行其中一个。HF 模型自己的逐模块_init_weights(module)由 HF 原生遍历负责分派;不是让共享代码猜初始化参数的名称。非 HF 自定义模型若使用其他方法名,需要在模型/provider/adapter 中明确桥接;两个入口都没有时只执行组件完整 reset,不能据此声称已执行任意自定义模型策略。实际修复:DeepseekV4.1 的
_initialize_v41_owned_module()为 Pipelined mHC 指定scale=1和模型 std 的fn。旧流程及本 PR 上一版d8810b377会再将其覆盖为scale=0.01、fnstd=0.02;当前版本使用真实模型 helper 的 CPU 回归,确认 scale 和模型写入的 fn 均被精确保留。仍需处理的适配边界:OffsetRMSNorm 存储 offset,实际缩放为
1 + weight。当前前置初始化会保留模型明确指定的 offset,但不识别该表示的通用 HF norm 初始化仍可能把 offset 写为 1,实际缩放变为 2。删除后置声明不等于完成这一表示适配;不能再依靠组件最后无条件归零来掩盖它。源模型中依赖被替换前具体类型的初始化分支,也需要模型/adapter 明确保持。以上继续由 #1694 跟踪。接口兼容:外部自定义组件若依赖旧的后置覆盖,需显式声明
after_model。reset_parameters()保持完整;有自定义 reset 的 replacement 仍需提供make_transforms()。前置替代后置只是交换执行顺序,不增加一轮 reset;部分参数仍可能被组件和模型分别写入,尚未进行生产规模初始化耗时测量。基于 master
06dbda40f;一个 commit,21 个文件,+810/-75。保留 master 的 DSA 并行和激活包装逻辑,仅包含实现、相关回归和契约文档,不含 Xing4 私有修改、诊断日志或临时验证脚本。Which issue(s) this PR fixes:
关联 #1694:修复默认 reset 覆盖模型策略以及已复现的 Pipelined mHC 冲突;OffsetRMSNorm 表示适配等问题仍待处理,不自动关闭 issue。整合 #1622 的功能增量,不自动关闭该 PR。KDA 的 FLA naive chunk 参考 在相同强衰减输入下也曾复现反向非有限值,逐 token 递推正常。
Test Plan and Test result:What scenarios were tested, and what were the verification results(Function, performance, reliability, etc.):
环境:Python 3.11.15、PyTorch 2.13.0+cpu、torch-npu 2.13.0、CANN 9.2、Transformers 5.21.0;已有 NPU 回归使用 Ascend 910B3。
scale=1与全部模型初始化快照;未放宽阈值。W0640:测试循环内的回调晚绑定reset/model。已通过默认参数绑定当前轮次的 reset 与 block。此前仓库.pylintrc禁用了该规则,门禁使用的公共规则启用了它;此次同时使用 Pylint 3.3.7 / astroid 3.3.11 核对本地和公共配置。仓库配置通过,公共配置的 3 条阻断诊断消失;最终门禁结果以本次提交触发的新流水线为准。case_log.py:CPU 双进程的复制、Shard(0)、Shard(-1) 共 3 个用例全部通过,检查数值、返回对象与底层存储身份,以及反向梯度。它是log_注册和原地分发修复的正式回归,予以保留。d8810b377:相关 UT 209 passed;NPU 四卡 GQA 和双卡 CP2+FSDP2 初始化各 1 passed。本轮未重跑 NPU,不将历史结果计为当前提交的新测试次数。验证边界:未重跑生产规模、全部融合后端、MLA/DSA CP 训练或 GQA 性能基准;没有新增 eager state CP 支持,不把 #1622 旧环境的性能数字计作本轮测量。缺少
hyper_multicore的独立测试文件未纳入验收。Self-checklist: