Skip to content

fix rmsnorm grad when input size is zero#79397

Open
greenhandF wants to merge 1 commit into
PaddlePaddle:developfrom
greenhandF:rmsnormgrad
Open

fix rmsnorm grad when input size is zero#79397
greenhandF wants to merge 1 commit into
PaddlePaddle:developfrom
greenhandF:rmsnormgrad

Conversation

@greenhandF

Copy link
Copy Markdown
Contributor

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

fix rmsnorm grad when input size is zero

是否引起精度变化

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Paddle-CI-Agent | pr_review | 2026-06-30 20:17:18

📋 Review 摘要

PR 概述:修复 GPU rms_norm_grad 在空输入时 dscale 未清零导致梯度随机值的问题
变更范围paddle/phi/kernels/gpu/rms_norm_cuda_kernel.h
影响面 Tag[Operator Mechanism]

问题

级别 文件 概述
🟡 建议 paddle/phi/kernels/gpu/rms_norm_cuda_kernel.h:1424 空输入分支缺少回归测试,无法防止 dscale 再次变为未初始化梯度

📝 PR 规范检查

标题缺少官方 Tag;同时 是否引起精度变化 填写为 ,但描述中没有说明精度变化来源、影响范围和验证方式。

标题建议(可直接复制):

  • [Operator Mechanism] fix rmsnorm grad when input size is zero
PR 描述建议(点击展开,可直接复制)
### PR Category
<!-- One of [ User Experience | Execute Infrastructure | Operator Mechanism | CINN | Custom Device | Performance Optimization | Distributed Strategy | Parameter Server | Communication Library | Auto Parallel | Inference | Environment Adaptation ] -->
Operator Mechanism

### PR Types
<!-- One of [ New features | Bug fixes | Improvements | Performance | BC Breaking | Deprecations | Docs | Devs | Not User Facing | Security | Others ] -->
Bug fixes

### Description
<!-- Describe what you’ve done -->
修复 GPU `rms_norm_grad``X.numel() == 0` 时只分配 `dscale` 但不清零的问题。空输入没有元素贡献到 `dscale`,梯度应为全 0;本 PR 在空输入分支使用 `Full``dscale` 进行 0 填充,避免未初始化内存进入梯度计算。

验证方式:N/A(当前 diff 未包含测试变更)

### 是否引起精度变化
<!-- one of the following [ 是 | 否 ]-->
是。精度变化来源于空输入场景下 `scale` 梯度从未初始化随机值修正为数学上应有的 0;影响范围为 GPU `rms_norm_grad` 的空 Tensor 输入场景。验证方式:N/A(当前 diff 未包含测试变更)。

总体评价

代码层面使用 Full<T, Context> 与非空路径的 dscale dtype 一致,修复方向合理。主要缺口是这个空 Tensor 梯度场景没有同步测试保护,PR 描述也需要补足精度变化说明。

// exactly zero. We must fill it with 0 instead of leaving the allocated
// buffer uninitialized (which would otherwise inject random values into
// the gradient computation).
Full<T, Context>(dev_ctx, dscale->dims(), 0, dscale);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 这个修复缺少覆盖 X.numel() == 0 的回归测试。

本 PR 改变的是空输入时 dscale 的数值语义:之前只分配缓冲区,现在应稳定为全 0。现有 test/legacy_test/test_rms_norm_op.py 只覆盖正常形状和 eps=None 反向,没有形如 x.shape == [0, N]scale.stop_gradient = False 的用例;后续改动很容易重新引入未初始化梯度。

建议修复方式:
test/legacy_test/test_rms_norm_op.py 增加 GPU 可运行的动态图用例,例如构造 x = paddle.randn([0, cols])scale.stop_gradient = False,执行 paddle.nn.functional.rms_norm(x, (cols,), scale).sum().backward(),并断言 scale.grad.numpy()np.zeros([cols], dtype=...) 一致。

@PaddlePaddle-bot

PaddlePaddle-bot commented Jun 30, 2026

Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-07-01 11:43:30 UTC+08:00

CI报告基于以下代码生成(30分钟更新一次):
PR commit: d10a380 | Merge base: 529fbc7 (branch: develop)


1 Required任务 : 45/48 通过

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
113(33) 80 76 2 1 0 1
任务 错误类型 置信度 日志
Check approval 需要 Approval Job
Check PR Template / Check PR问题:缺少必需审批 Job

2 失败详情

🔴 Check approval — 需要 Approval(置信度: 高)

该 Job 需要人工 Approval,完成审批后 CI 才会继续执行。

  • 根因摘要: 缺少人工审批
  • 修复建议摘要: 请通过人工审批后重跑或等待 CI 继续执行
🔴 Check PR Template / Check — PR问题:缺少必需审批(置信度: 高)

错误类型: PR问题 | 置信度: 高
分析器: 通用分析(fallback)
失败用例: PR 模板/审批检查

用例 错误摘要
Check PR Template 必需审批人 sneaxiy 尚未审批,脚本退出 8

关键日志:

Approval check result: False, message: ❌ No approvals from required approvers. Missing: sneaxiy
ERROR MESSAGE: ❌ No approvals from required approvers. Missing: sneaxiy
EXCODE: 8
ipipe_log_param_EXCODE: 8
##[error]Process completed with exit code 8.
  • 根因摘要: 缺少必需审批人 sneaxiy 的 approval。
    该失败不是编译或单测错误;日志显示 Check PR Template 步骤中的审批检查未通过,并以退出码 8 终止。

修复建议:

  1. 请由必需审批人 sneaxiy 完成 approval,然后重新触发该检查或等待 CI 继续执行。

关联变更: 未分析

@paddle-bot paddle-bot Bot added the contributor External developers label Jun 30, 2026
@greenhandF

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants