Skip to content

Conversation

@co63oc
Copy link
Contributor

@co63oc co63oc commented Jul 6, 2025

PR Category

Operator Mechanism

PR Types

Bug fixes

Description

[0-size Tensor Job2 No.60] Add 0-size Tensor support for paddle.nn.functional.instance_norm [fluid_ops]

InstanceNormInferMeta 取消维度为0判断
符号推导没有对应代码


InstanceNormGradInferMeta 修改scale、bias中维度设置为0部分,设置为scale、bias对应维度,增加bias参数

修改 backward.yaml配置文件,kernel增加bias参数, 使用到 composite 配置,修改paddle/fluid/prim/api/composite_backward/composite_backward_api.h文件增加bias参数
修改kernel前向,反向,填充为0
增加单测

torch 测试反向填充

import torch _args = [] input = torch.randn((8, 32, 32, 0)) input.requires_grad = True weight = torch.randn([32]) weight.requires_grad = True bias = torch.randn([32]) bias.requires_grad = True _args.append(x) _args.append(None) _args.append(None) _args.append(weight) _args.append(bias) result = torch.nn.functional.instance_norm(*_args) result.sum().backward() print(weight.grad) tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) 

PaddleAPITest测试通过
image

@paddle-bot paddle-bot bot added the contributor External developers label Jul 6, 2025
@co63oc co63oc changed the title [0-size Tensor Job2 No.60] Add 0-size Tensor support for paddle.nn.functional.instance_norm [fluid_ops] CI测试不review paddle.nn.functional.instance_norm [fluid_ops] Jul 6, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jul 7, 2025

Codecov Report

Attention: Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.

Please upload report for BASE (develop@8341678). Learn more about missing BASE report.

Files with missing lines Patch % Lines
paddle/phi/kernels/cpu/instance_norm_kernel.cc 10.00% 9 Missing ⚠️
...addle/phi/kernels/cpu/instance_norm_grad_kernel.cc 22.22% 7 Missing ⚠️

❌ Your patch status has failed because the patch coverage (44.82%) 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 @@ ## develop #73854 +/- ## ========================================== Coverage ? 44.82% ========================================== Files ? 4 Lines ? 29 Branches ? 0 ========================================== Hits ? 13 Misses ? 16 Partials ? 0 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@co63oc co63oc force-pushed the g41 branch 2 times, most recently from bf3b13d to 35db413 Compare July 11, 2025 06:14
@co63oc co63oc changed the title CI测试不review paddle.nn.functional.instance_norm [fluid_ops] [0-size Tensor Job2 No.60] Add 0-size Tensor support for paddle.nn.functional.instance_norm [fluid_ops] Jul 11, 2025
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Jul 14, 2025
@co63oc
Copy link
Contributor Author

co63oc commented Jul 18, 2025

@DanielSun11 CI已完成需要review

@co63oc
Copy link
Contributor Author

co63oc commented Jul 19, 2025

/re-run all-failed

DanielSun11
DanielSun11 previously approved these changes Jul 21, 2025
Copy link
Contributor

@DanielSun11 DanielSun11 left a comment

Choose a reason for hiding this comment

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

LGTM

@DanielSun11
Copy link
Contributor

代码改动较大,请 @wanghuancoder review一下

Copy link
Contributor

@wanghuancoder wanghuancoder left a comment

Choose a reason for hiding this comment

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

@luotao1 协调云飞帮忙看看

Comment on lines 1820 to 1830
args : (Tensor x, Tensor scale, Tensor bias, Tensor saved_mean, Tensor saved_variance, Tensor y_grad, float epsilon=1e-5)
output : Tensor(x_grad), Tensor(scale_grad), Tensor(bias_grad)
infer_meta :
func : InstanceNormGradInferMeta
spmd_rule : InstanceNormGradInferSpmd
kernel :
func : instance_norm_grad
data_type : x
optional : scale
optional : scale, bias
backward : instance_norm_double_grad
composite: instance_norm_grad(x, scale, saved_mean, saved_variance, y_grad, epsilon, x_grad, scale_grad, bias_grad)
composite: instance_norm_grad(x, scale, bias, saved_mean, saved_variance, y_grad, epsilon, x_grad, scale_grad, bias_grad)
Copy link
Contributor

Choose a reason for hiding this comment

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

这里有几个问题需要云飞评估:

  1. 修改反向签名是否涉及不兼容升级?
  2. 如果只是InferMeta用,好像有办法不修改函数签名,在kernel->func中标记需要传给Kernel的参数有哪些,可以参考lp_pool2d_grad的param。也需要云飞确认,这种用法用的比较少
  3. 这个bias如果只是InferMeta用,又是optional的是否可以标记为no need buffer?也需要云飞确认
Copy link
Contributor Author

Choose a reason for hiding this comment

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

2. lp_pool2d_grad

和lp_pool2d_grad不同的是,这里同时使用了composite,使用func传参数,composite中会报错

Copy link
Contributor

Choose a reason for hiding this comment

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

改反向一般不影响推理兼容性
配置no need buffer这里不太确定有没有问题,可能需要实际测试下

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改 增加 no_need_buffer : bias

template <typename T>
void instance_norm_grad(const Tensor& x,
const paddle::optional<Tensor>& scale,
const paddle::optional<Tensor>& bias UNUSED,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里需要改InferMeta吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

不增加bias参数,composite这部分报错

zyfncg
zyfncg previously approved these changes Jul 21, 2025
Comment on lines 1820 to 1830
args : (Tensor x, Tensor scale, Tensor bias, Tensor saved_mean, Tensor saved_variance, Tensor y_grad, float epsilon=1e-5)
output : Tensor(x_grad), Tensor(scale_grad), Tensor(bias_grad)
infer_meta :
func : InstanceNormGradInferMeta
spmd_rule : InstanceNormGradInferSpmd
kernel :
func : instance_norm_grad
data_type : x
optional : scale
optional : scale, bias
backward : instance_norm_double_grad
composite: instance_norm_grad(x, scale, saved_mean, saved_variance, y_grad, epsilon, x_grad, scale_grad, bias_grad)
composite: instance_norm_grad(x, scale, bias, saved_mean, saved_variance, y_grad, epsilon, x_grad, scale_grad, bias_grad)
Copy link
Contributor

Choose a reason for hiding this comment

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

改反向一般不影响推理兼容性
配置no need buffer这里不太确定有没有问题,可能需要实际测试下

@co63oc co63oc dismissed stale reviews from zyfncg and DanielSun11 via 013ec81 July 21, 2025 08:06
@co63oc
Copy link
Contributor Author

co63oc commented Jul 21, 2025

/re-run all-failed

1 similar comment
@co63oc
Copy link
Contributor Author

co63oc commented Jul 21, 2025

/re-run all-failed

@co63oc
Copy link
Contributor Author

co63oc commented Jul 21, 2025

@zyfncg 已增加no_need_buffer,CI已完成

@luotao1 luotao1 merged commit 81a6159 into PaddlePaddle:develop Jul 22, 2025
81 of 87 checks passed
@co63oc co63oc deleted the g41 branch July 23, 2025 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 skip-ci: approval

6 participants