support high_precision_norm in swa#1333
Conversation
|
root seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
8ef12ac to
d43a411
Compare
PaddleFleet Log Analysis
日志分析报告
失败的测试case: 根本原因分析: 修复建议:
🔄 每次 Re-run 后自动更新 |
d43a411 to
287850c
Compare
86f7e7b to
d763838
Compare
a65d77a to
7c4861c
Compare
7c4861c to
ea664da
Compare
ea664da to
cfbc5be
Compare
cfbc5be to
3a2c8aa
Compare
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-06-30 21:29:14
📋 Review 摘要
PR 概述:新增 DSv4 SWA 高精度 RMSNorm 开关,并扩展 RMSNorm/DSv4 RoPE 路径。
变更范围:src/paddlefleet/transformer/、DSv4 attention、RMSNorm、TransformerConfig、相关单测
影响面 Tag:Transformer TransformerConfig Tests
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🔴 Bug | src/paddlefleet/transformer/transformer_config.py:1236 |
swa_high_precision_norm 未限制 norm 实现,合法 LayerNorm 配置会在 DSv4 KV path 传参时报错 |
| 🟡 建议 | tests/single_card_tests/ai_edited_test/transformer/test_ai_swa_high_precision_norm.py:29 |
新测试手动改 sys.path,容易导入非当前 PR 代码 |
| 🟡 建议 | tests/single_card_tests/ai_edited_test/transformer/test_ai_swa_high_precision_norm.py:65 |
高精度 norm 测试只断言 dtype/shape,不能验证 fp32 计算语义 |
历史 Findings 修复情况
| Finding | 问题 | 状态 |
|---|---|---|
| F1 | 新增的 swa_high_precision_norm 只落到了 dataclass,命令行入口没有同步。 |
|
| F2 | swa_high_precision_norm 没有覆盖 Q path 里已有的 q_layernorm。 |
|
| F3 | high_precision_norm=True 但 return_high_precision_norm=False 时没有恢复输入 dtype。 |
📝 PR 规范检查
标题缺少官方 Tag;描述结构符合 checklist §D2。
标题建议(可直接复制):
[New features] Support high precision norm in SWA
PR 描述建议(点击展开,可直接复制)
### PR Category
<!-- One of [ User Experience | Execute Infrastructure | Operator Mechanism | Custom Device | Performance Optimization | Distributed Strategy | Parameter Server | Communication Library | Environment Adaptation ] -->
Execute Infrastructure
### PR Types
<!-- One of [ New features | Bug fixes | Improvements | Performance | BC Breaking | Deprecations | Docs | Devs | Not User Facing | Security | Others ] -->
New features
### Description
<!-- Describe what you’ve done -->
新增 `swa_high_precision_norm` 开关:在 DSv4 Hybrid Attention 的 Q/KV RMSNorm 计算中使用 fp32,并在 KV RoPE 前保留 fp32 结果以支持高精度 RoPE;同时为 DSv4 非融合 RoPE 路径传递 `high_precision_rope`。本 PR 还扩展 `RMSNorm.forward`,增加 `high_precision_norm` 和 `return_high_precision_norm` 参数。总体评价
当前实现补上了部分 DSv4/KV 高精度路径,但新增开关还缺少对 norm 实现的约束,存在可触发的运行时崩溃组合。历史三条 finding 在当前 diff 中仍未完全修复,建议和本轮新增问题一起处理后再合入。
|
|
||
| # swa_high_precision_norm is only supported for DSv4 models. | ||
| if ( | ||
| self.swa_high_precision_norm |
There was a problem hiding this comment.
🔴 Bug swa_high_precision_norm 当前只校验了 DSv4 variant,但没有限制 norm 实现。DSv4 layer spec 会按 config.normalization 构造 q_layernorm/kv_layernorm;当用户设置 normalization="LayerNorm" 时,kv_layernorm 是 LayerNorm.forward(self, hidden_states),而 get_query_key_value_tensors() 在该开关下会传 high_precision_norm/return_high_precision_norm,运行时会报 unexpected keyword argument。
建议修复方式:
在这里同时要求 normalization == "RMSNorm",或给 LayerNorm/所有可作为 kv_layernorm 的实现补齐相同 kwargs 语义;按 PR 描述这是 RMSNorm 专项,优先在 config 校验阶段拒绝非 RMSNorm。
| import os | ||
| import sys | ||
|
|
||
| sys.path.insert( |
There was a problem hiding this comment.
🟡 建议 新增测试里手动 sys.path.insert 会绕过仓库的测试入口依赖。这个路径从当前文件只回到 tests/ 目录,若工作目录/PYTHONPATH 不同,可能导入到环境里已安装的 paddlefleet 而不是本 PR 的 src/paddlefleet;文件末尾的 unittest.main() 也属于同一类本地运行入口依赖。
建议修复策略:
删除 sys.path.insert 和脚本入口,按仓库测试配置提供 PYTHONPATH=src/editable install 后直接 import,或将公共测试路径配置放到测试 runner/conftest。
| """When high_precision_norm=True, computation should happen in float32 | ||
| and output should be cast back to original dtype.""" | ||
| q = paddle.randn([2, 4, 8, 32]).astype(paddle.bfloat16) | ||
| result = _q_rms_norm(q, eps=1e-5, high_precision_norm=True) |
There was a problem hiding this comment.
🟡 建议 这个用例只断言 dtype/shape,不能证明 high_precision_norm=True 真的按 fp32 算;即使分支里没有 q.float()、或计算顺序退回 bf16,测试仍会通过。对 precision feature 需要数值对齐保护,否则当前 Q/KV 路径的精度回归很容易被漏掉。
建议修复策略:
构造一组 bf16 输入,分别计算 fp32 reference 和低精度 reference,断言 high_precision 分支更接近 fp32 reference;同时覆盖 RMSNorm(..., high_precision_norm=True) 和 DSv4 get_query_key_value_tensors() 的实际调用路径。
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (76.66%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## release/0.3 #1333 +/- ##
==============================================
Coverage ? 76.66%
==============================================
Files ? 3
Lines ? 30
Branches ? 9
==============================================
Hits ? 23
Misses ? 4
Partials ? 3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
PR Category
Execute Infrastructure
PR Types
New features
Description
新增开关:
RMS_Norm forward函数新增入参
备注
当swa_high_precision_norm开启,kv的rms_norm将在fp32下进行,并返回kv为fp32
是否引起精度变化
是