Skip to content

[Cpp API Compatibility] add all & allclose API#77542

Open
Le-soleile wants to merge 19 commits intoPaddlePaddle:developfrom
Le-soleile:all
Open

[Cpp API Compatibility] add all & allclose API#77542
Le-soleile wants to merge 19 commits intoPaddlePaddle:developfrom
Le-soleile:all

Conversation

@Le-soleile
Copy link
Contributor

@Le-soleile Le-soleile commented Jan 27, 2026

PR Category

Execute Infrastructure

PR Types

New features

Description

新增 all & allclose 兼容接口

是否引起精度变化

@paddle-bot
Copy link

paddle-bot bot commented Jan 27, 2026

你的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 contributor External developers label Jan 27, 2026
@Le-soleile
Copy link
Contributor Author

/re-run all-failed

@Le-soleile
Copy link
Contributor Author

/re-run all-failed

@Le-soleile
Copy link
Contributor Author

/re-run all-failed

1 similar comment
@Le-soleile
Copy link
Contributor Author

/re-run all-failed

// Read the value from the tensor (could be bool, int8, int32, etc.)
auto dtype = result_tensor->dtype();
if (dtype == phi::DataType::BOOL) {
bool* bool_ptr = result_tensor->data<bool>();
Copy link
Contributor

Choose a reason for hiding this comment

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

确认一下paddle::experimental::allclose返回结果的tensor是什么,如果是逐个元素的比较结果,这里的处理就不对,本地做一下实验,将tensor打印出来看一下(type和data),保存好实验结果

Copy link
Contributor Author

@Le-soleile Le-soleile Feb 24, 2026

Choose a reason for hiding this comment

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

image

输出结果:

image

分析:

  1. paddle::experimental::allclose() 返回的是标量 Tensor(shape=[], numel=1)。
  2. dtypepaddle.bool
  3. 代码中已检查了 numel != 1 的情况。
  4. 代码能够正确从 BOOL dtype 中提取对应的值。
image
@Le-soleile
Copy link
Contributor Author

/re-run all-failed

2 similar comments
@Le-soleile
Copy link
Contributor Author

/re-run all-failed

@Le-soleile
Copy link
Contributor Author

/re-run all-failed

@Le-soleile
Copy link
Contributor Author

/re-run all-failed

3 similar comments
@Le-soleile
Copy link
Contributor Author

/re-run all-failed

@Le-soleile
Copy link
Contributor Author

/re-run all-failed

@Le-soleile
Copy link
Contributor Author

/re-run all-failed

@Le-soleile
Copy link
Contributor Author

/re-run xpu test

@Le-soleile
Copy link
Contributor Author

/re-run all-failed

1 similar comment
@Le-soleile
Copy link
Contributor Author

/re-run all-failed

@Le-soleile
Copy link
Contributor Author

/re-run all-failed

} else {
PD_THROW("allclose: unsupported result dtype");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

allallclose 的实现是否可以放在 all.hallclose.h?同时暴露 at::allat::allclose

Copy link
Member

Choose a reason for hiding this comment

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

添加后需要像 https://github.com/PaddlePaddle/Paddle/pull/78037/changes#diff-5847905442941e26d93374313b0e119d01f39267c25427c467c7829150972c06paddle/phi/api/include/compat/ATen/Functions.h 将相关函数 include 过来,以便用户使用

at::Tensor absolute() const { return abs(); }

at::Tensor& absolute_() const { return abs_(); }

Copy link
Member

Choose a reason for hiding this comment

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

这个空行不用删吧

SigureMo
SigureMo previously approved these changes Feb 27, 2026
@Le-soleile
Copy link
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

3 participants