[Cpp API Compatibility] Add TORCH_WARN macro and fix resize_#78576
[Cpp API Compatibility] Add TORCH_WARN macro and fix resize_#78576youge325 wants to merge 1 commit intoPaddlePaddle:developfrom
TORCH_WARN macro and fix resize_#78576Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
Pull request overview
This PR updates the PaddlePaddle C++ API compatibility layer to better match PyTorch behavior by adding TORCH_WARN-family macros and fixing at::Tensor::resize_ compilation issues when interacting with phi::DenseTensor internals.
Changes:
- Add a simplified warning API and
TORCH_WARN/TORCH_WARN_DEPRECATION/TORCH_WARN_ONCEmacros underc10/util/Exception.h. - Fix
resize_implementation to useDenseTensorMeta::offsetandDenseTensor::ResizeAndAllocate/data()APIs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| paddle/phi/api/include/compat/c10/util/Exception.h | Introduces TORCH_WARN* macros and minimal warning plumbing for PyTorch compatibility. |
| paddle/phi/api/include/compat/ATen/ops/resize.h | Fixes resize_ to compile with current phi::DenseTensor by switching from removed APIs (offset(), mutable_data) to supported ones. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Helper macro for generating unique variable names | ||
| #define C10_CONCATENATE_IMPL(s1, s2) s1##s2 | ||
| #define C10_CONCATENATE(s1, s2) C10_CONCATENATE_IMPL(s1, s2) |
There was a problem hiding this comment.
C10_CONCATENATE(_IMPL) is redefined here, but it is already defined in c10/macros/Macros.h (and headers like c10/core/DispatchKeySet.h include both). This can trigger macro-redefinition diagnostics (often treated as errors under -Werror). Prefer including <c10/macros/Macros.h> and removing these duplicate macro definitions (or add #ifndef guards).
| // Helper macro for generating unique variable names | |
| #define C10_CONCATENATE_IMPL(s1, s2) s1##s2 | |
| #define C10_CONCATENATE(s1, s2) C10_CONCATENATE_IMPL(s1, s2) | |
| // Helper macro for generating unique variable names | |
| #ifndef C10_CONCATENATE_IMPL | |
| #define C10_CONCATENATE_IMPL(s1, s2) s1##s2 | |
| #endif | |
| #ifndef C10_CONCATENATE | |
| #define C10_CONCATENATE(s1, s2) C10_CONCATENATE_IMPL(s1, s2) | |
| #endif |
| #define TORCH_WARN_ONCE(...) \ | ||
| do { \ | ||
| static bool C10_ANONYMOUS_VARIABLE(torch_warn_once_) = [] { \ | ||
| TORCH_WARN(__VA_ARGS__); \ | ||
| return true; \ | ||
| }(); \ | ||
| } while (0) |
There was a problem hiding this comment.
TORCH_WARN_ONCE expands C10_ANONYMOUS_VARIABLE(...), but this header doesn’t ensure that macro is defined (it’s provided by c10/macros/Macros.h). Using TORCH_WARN_ONCE from a TU that only includes <c10/util/Exception.h> will fail to compile. Include <c10/macros/Macros.h> here (preferred) or add a guarded fallback definition for C10_ANONYMOUS_VARIABLE.
|
/re-run all-failed |
PR Category
Execute Infrastructure
PR Types
New features
Description
新增
TORCH_WARN宏修复编译 DeepEP 时发现的 resize_ 接口编译错误
是否引起精度变化
否