Skip to content

Conversation

@yongqiangma
Copy link
Contributor

@yongqiangma yongqiangma commented Aug 4, 2025

PR Category

User Experience

PR Types

New features

Description

pcard-67164
convert torch C++ api to paddle api

@yongqiangma yongqiangma marked this pull request as draft August 4, 2025 08:26
@paddle-bot
Copy link

paddle-bot bot commented Aug 4, 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.

SigureMo
SigureMo previously approved these changes Aug 30, 2025
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

一些 TODO,发版后会持续优化

# Add paddle_includes to pass CI, for more details,
# please refer to the comments in `paddle/tests/custom_op/utils.py``
paddle_includes = []
for site_packages_path in getsitepackages():
Copy link
Member

Choose a reason for hiding this comment

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

重复的模板代码,一次要改十多处,后续提取成公共逻辑

classes_[qualified_name] =
std::make_unique<ClassRegistration>(namespace_name, class_name);
// TODO(SigureMo): Use vlog for debug logging
// std::cout << "Registered class: " << qualified_name << std::endl;
Copy link
Member

Choose a reason for hiding this comment

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

后续拆分到 .cpp 并使用 VLOG 打印

@SigureMo
Copy link
Member

SigureMo commented Aug 30, 2025

/skip-reason distribute-stable 是因为 #74899 matmul 下沉不再支持老 IR 导致挂掉的,但 #74899 没触发 distribute stable,本 PR 刚刚修改了单测导致触发,故而挂掉,与本 PR 无关

报错流水线链接:https://github.com/PaddlePaddle/Paddle/actions/runs/17340353250/job/49235747651?pr=74402

@yongqiangma yongqiangma requested a review from zyfncg August 30, 2025 14:39
Comment on lines +38 to +56
inline at::Tensor empty(at::IntArrayRef size,
::std::optional<at::ScalarType> dtype,
::std::optional<at::Layout> layout,
::std::optional<at::Device> device,
::std::optional<bool> pin_memory,
::std::optional<at::MemoryFormat> memory_format) {
PD_CHECK(!layout.has_value(), "`layout` is not supported now.");
PD_CHECK(!(pin_memory.has_value() && pin_memory.value() != false),
"`pin_memory` other than False is not supported now.");
PD_CHECK(!(memory_format.has_value() &&
memory_format.value() != c10::MemoryFormat::Contiguous),
"`MemoryFormat` other than Contiguous is not supported now.");

return paddle::experimental::empty(
size._PD_ToPaddleIntArray(),
compat::_PD_AtenScalarTypeToPhiDataType(
dtype.value_or(c10::get_default_dtype())),
device.value_or(at::kCPU)._PD_GetInner());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

能否把这些头文件的实现逻辑放到.cc中,否则使用时很容易编译体积膨胀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

能否把这些头文件的实现逻辑放到.cc中,否则使用时很容易编译体积膨胀

好的,后续统一调整一下,一开始这样写主要是和torch的结构统一。

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@yongqiangma yongqiangma merged commit 78d7550 into develop Aug 31, 2025
112 of 122 checks passed
@SigureMo SigureMo deleted the compatible-with-torch-3rd branch August 31, 2025 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants