Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix instance_norm、conv2d_xpu、inplace optimizer bugs. #52627

Merged
merged 3 commits into from
Apr 13, 2023

Conversation

csy0225
Copy link
Contributor

@csy0225 csy0225 commented Apr 7, 2023

PR types

Bug fixes

PR changes

OPs

Describe

修复 instance_norm 算子在 scale == null、bias == null 时出现 segment fault 的错误。
修复 inplace 优化算子的前一个算子是 feed 算子时, model input variable shape 被修改,导致第二次推理失败的问题。
修复 conv2d_xpu 算子 has_bias 错误的问题。
取消了 assign_value 算子在 xpu 后端 fp16类型的注册。

@paddle-bot
Copy link

paddle-bot bot commented Apr 7, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@@ -186,6 +186,5 @@ PD_REGISTER_KERNEL(assign_value,
int,
float,
double,
int64_t,
phi::dtype::float16) {}
Copy link
Contributor

@hong19860320 hong19860320 Apr 7, 2023

Choose a reason for hiding this comment

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

assign kernel 为什么不支持 fp16?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

本身assign_value 这个 kernel 就没有为 fp16 设计,kernel 类型实现和属性绑定的,例如 fp32的 kernel 需要有一个 fp32_values 的属性,int64类型的 kernel 需要有一个 int64_values 的属性,但是 fp16类型没有fp16_values的属性,不适合新增fp16类型注册。

saved_mean->data<float>(),
saved_var->data<float>(),
true);
DenseTensor scale_data;
Copy link
Contributor

@hong19860320 hong19860320 Apr 10, 2023

Choose a reason for hiding this comment

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

float* scale_data_ptr = nullptr;
DenseTensor one_scale; // or dummy_scale
if (!scale_ptr) {
    one_scale.Resize({c});
    // xdnn interface expects float data
    dev_ctx.template Alloc<float>(&one_scale);
    phi::funcs::set_constant(dev_ctx, &one_scale, static_cast<float>(1));
    scale_data_ptr = one_scale.data<float>();
} else {
   scale_data_ptr = scale_ptr->data<float>();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

h,
w,
epsilon,
scale_ptr == nullptr ? scale_data.data<float>()
Copy link
Contributor

Choose a reason for hiding this comment

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

scale_data_ptr

epsilon,
scale_ptr == nullptr ? scale_data.data<float>()
: scale_ptr->data<float>(),
bias_ptr == nullptr ? bias_data.data<float>() : bias_ptr->data<float>(),
Copy link
Contributor

Choose a reason for hiding this comment

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

bias_data_ptr

@csy0225 csy0225 force-pushed the instance_norm_fix branch 2 times, most recently from 3823f84 to d496241 Compare April 10, 2023 12:03
@csy0225 csy0225 closed this Apr 11, 2023
@csy0225 csy0225 reopened this Apr 11, 2023
const float* bias_data_fp32 = nullptr;
const auto* bias_ptr = bias.get_ptr();
if (bias_ptr == nullptr) {
DenseTensor bias_data;
Copy link
Contributor

Choose a reason for hiding this comment

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

能定义在{}内部吗?bias_data_fp32 会不会变成野指针?

scale_data_fp32 = scale_data.data<float>();
} else if (scale_ptr->dtype() ==
phi::CppTypeToDataType<phi::dtype::float16>::Type()) {
float* scale_data_temp =
Copy link
Contributor

Choose a reason for hiding this comment

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

scale_data_temp 这个内存什么时候被释放?RAII_GUARD 析构的时候?

dev_ctx.template Alloc<float>(&scale_data);
phi::funcs::set_constant(dev_ctx, &scale_data, static_cast<float>(1));
scale_data_fp32 = scale_data.data<float>();
} else if (scale_ptr->dtype() ==
Copy link
Contributor

@hong19860320 hong19860320 Apr 11, 2023

Choose a reason for hiding this comment

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

条件是不是应该是:

scale_ptr->dtype() != phi::CppTypeToDataType<phi::dtype::float>::Type()

zhupengyang
zhupengyang previously approved these changes Apr 11, 2023
Copy link
Contributor

@zhupengyang zhupengyang left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@hong19860320 hong19860320 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhupengyang zhupengyang merged commit fa8abee into PaddlePaddle:develop Apr 13, 2023
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.

3 participants