Skip to content

[XPU] fix index's datatype, using int64 instead of int, part 2 (g-z) #72519

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

Merged
merged 1 commit into from
May 13, 2025

Conversation

cqulilujia
Copy link
Contributor

@cqulilujia cqulilujia commented Apr 27, 2025

PR Category

Custom Device

PR Types

Bug fixes

Description

Fix index's datatype, using int64 instead of int, part 2 (g-z)

Copy link

paddle-bot bot commented Apr 27, 2025

你的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.

@paddle-bot paddle-bot bot added the XPU label Apr 27, 2025
@cqulilujia cqulilujia closed this May 8, 2025
@cqulilujia cqulilujia reopened this May 8, 2025
@cqulilujia cqulilujia changed the title [XPU] fix index's datatype, using int64 instead of int, part 2 (g-n) [XPU] fix index's datatype, using int64 instead of int, part 2 (g-z) May 8, 2025
@cqulilujia cqulilujia force-pushed the int64_part2 branch 3 times, most recently from e776275 to 9faff6b Compare May 9, 2025 09:43
@@ -29,6 +29,8 @@ set(XPU_XBLAS_LIB_NAME "libxpu_blas.so")
set(XPU_XFA_LIB_NAME "libxpu_flash_attention.so")
set(XPU_XPUDNN_LIB_NAME "libxpu_dnn.so")
set(XPU_FFT_LIB_NAME "libcufft.so")
# Avoid deprecated int32 apis:
add_compile_definitions(XPUAPI_NOT_INCLUDE_DEPRECATED)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

不再include int32老接口,参阅内部卡片xpu-paddlepaddle-864

@@ -1075,6 +1075,7 @@ XPUOpMap& get_kl3_ops() {
phi::DataType::BFLOAT16})},
{"pow2_decay_with_linear_warmup", XPUKernelSet({phi::DataType::FLOAT32})},
{"prior_box", XPUKernelSet({phi::DataType::FLOAT32})},
{"prelu", XPUKernelSet({phi::DataType::FLOAT32, phi::DataType::FLOAT16})},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

顺手绑了一个之前遗留的算子

@@ -39,13 +39,13 @@ void UnfoldGradKernel(const Context& ctx,
const auto& x_dims = x_grad->dims();
const int batch_size = static_cast<int>(x_dims[0]);

int out_height = phi::funcs::CalcOutputSize(x_dims[2],
int out_height = phi::funcs::CalcOutputSize(static_cast<int>(x_dims[2]),
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么这里要static_cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

paddle/phi/kernels/funcs/unfold_functor.h中对函数CalcOutputSize新增了模板T,能够同时支持int和int64,修改之后再调用时必须将入参统一为int或int64。这里x_dims[2]是int64类型,而kernel_sizes[0]等是int类型

} // namespace phi
#endif
#
Copy link
Contributor

Choose a reason for hiding this comment

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

这个是不是有点问题

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到,这里漏掉了。单独的#不会影响编译,后续PR一起带上修复

@@ -273,14 +281,17 @@ void RnnGradKernel(const Context& dev_ctx,
hidden_size,
seq_len,
seq_len_tensor,
1,
Copy link
Contributor

Choose a reason for hiding this comment

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

这为什么突然+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bilstm_grad的int接口是老接口,在deprecated.h中。int64接口为新接口,与老接口相比多了一个参数,这里添加1参考了api接口中int调用int64接口的逻辑。

const int64_t col = in_dims[in_dims.size() - 1];

int r =
xpu::sorted_topk<XPUType>(dev_ctx.x_context(),
Copy link
Contributor

Choose a reason for hiding this comment

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

topk index int64_t版本走了不一样的分支,因此可能需要联系算子加固

Copy link
Contributor Author

Choose a reason for hiding this comment

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

算子已加固,参考内部卡片API-BR-394中链接的PR

@@ -39,13 +39,13 @@ void UnfoldGradKernel(const Context& ctx,
const auto& x_dims = x_grad->dims();
const int batch_size = static_cast<int>(x_dims[0]);

int out_height = phi::funcs::CalcOutputSize(x_dims[2],
int out_height = phi::funcs::CalcOutputSize(static_cast<int>(x_dims[2]),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

paddle/phi/kernels/funcs/unfold_functor.h中对函数CalcOutputSize新增了模板T,能够同时支持int和int64,修改之后再调用时必须将入参统一为int或int64。这里x_dims[2]是int64类型,而kernel_sizes[0]等是int类型

} // namespace phi
#endif
#
Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到,这里漏掉了。单独的#不会影响编译,后续PR一起带上修复

@@ -273,14 +281,17 @@ void RnnGradKernel(const Context& dev_ctx,
hidden_size,
seq_len,
seq_len_tensor,
1,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bilstm_grad的int接口是老接口,在deprecated.h中。int64接口为新接口,与老接口相比多了一个参数,这里添加1参考了api接口中int调用int64接口的逻辑。

nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
i_f_g_o,
c);
c,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

同理,两个xpu::Activation_t类型的参数也是新旧接口的差异

const int64_t col = in_dims[in_dims.size() - 1];

int r =
xpu::sorted_topk<XPUType>(dev_ctx.x_context(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

算子已加固,参考内部卡片API-BR-394中链接的PR

Copy link
Contributor

@QingshuChen QingshuChen 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

@zhangbo9674 zhangbo9674 left a comment

Choose a reason for hiding this comment

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

LGTM for error message

@cqulilujia
Copy link
Contributor Author

/re-run approval

@QingshuChen QingshuChen merged commit 331d556 into PaddlePaddle:develop May 13, 2025
44 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants