[API Compatibility] Implement paddle.addcmul API -part#77333
[API Compatibility] Implement paddle.addcmul API -part#77333Manfredss wants to merge 34 commits intoPaddlePaddle:developfrom
Conversation
…rnels for CPU/GPU (fp16, fp32, fp64, bf16) - Add operator configuration in ops.yaml and backward.yaml - Implement AddcmulInferMeta for shape inference - Add PIR symbolic shape inference support - Add Python API: paddle.addcmul() and Tensor.addcmul() - Add comprehensive test suite (52 tests, all passing) - Add to FP64 gradient threshold whitelist - Formula: output = input + value * tensor1 * tensor2 - Supports broadcasting and multiple dtypes.
… ApiEnhance354
|
你的PR提交成功,感谢你对开源项目的贡献! |
zhwesky2010
left a comment
There was a problem hiding this comment.
看下覆盖率,确保都能测到。
同时提前进行下PaConvert测试,确保与torch计算结果一致。截图下PaConvert的case计算结果。
python/paddle/tensor/math.py
Outdated
| return _C_ops.addmm_(input, x, y, beta, alpha) | ||
|
|
||
|
|
||
| def addcmul( |
There was a problem hiding this comment.
新增API直接采取C++下沉的方法吧,这个可以不加
1179fb5 to
ca45edd
Compare
|
/re-run all-failed |
python/paddle/_paddle_docs.py
Outdated
|
|
||
| add_doc_and_signature( | ||
| "i1", | ||
| "addcmul", |
There was a problem hiding this comment.
不要删掉别的,改完后自己先check下所有改动是否符合预期
a9a8f4b to
a20a003
Compare
python/paddle/tensor/math.py
Outdated
| return _C_ops.addmm_(input, x, y, beta, alpha) | ||
|
|
||
|
|
||
| # def addcmul( |
Codecov Report❌ Patch coverage is Please upload reports for the commit 55f8f54 to get more accurate results. Additional details and impacted files@@ Coverage Diff @@
## develop #77333 +/- ##
==========================================
Coverage ? 34.70%
==========================================
Files ? 8
Lines ? 268
Branches ? 0
==========================================
Hits ? 93
Misses ? 175
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/re-run all-failed |
|
/re-run all-failed |
|
/re-run all-failed |
对的,需要的,要在 |
|
/re-run all-failed |
zhwesky2010
left a comment
There was a problem hiding this comment.
Coverage无法通过的原因是test_addcmul无法运行通过,本地在GPU上测下addcmul吧。
同时尽可能减少skipif和atol/rtol的修改。
test/legacy_test/test_addcmul_op.py
Outdated
|
|
||
| cinn_loss = net_cinn(x, t1, t2) | ||
| np.testing.assert_allclose( | ||
| cinn_loss.numpy(), dy_loss.numpy(), rtol=1e-5, atol=1e-5 |
There was a problem hiding this comment.
这几个地方建议精简下case,避免atol/rtol的使用。
test/legacy_test/test_addcmul_op.py
Outdated
|
|
||
| cinn_loss = net_cinn(x, t1, t2) | ||
| np.testing.assert_allclose( | ||
| cinn_loss.numpy(), dy_loss.numpy(), rtol=1e-5, atol=1e-5 |
test/legacy_test/test_addcmul_op.py
Outdated
| dy_out = fn(*inputs) | ||
|
|
||
| np.testing.assert_allclose( | ||
| cinn_out.numpy(), dy_out.numpy(), rtol=1e-5, atol=1e-5 |
There was a problem hiding this comment.
cinn的计算结果与常规的应该是一样的,这里降低阈值的原因是
test/legacy_test/test_addcmul_op.py
Outdated
| paddle.enable_static() | ||
|
|
||
|
|
||
| @unittest.skipIf( |
There was a problem hiding this comment.
这里如果需要大量skipif,还是从CMakeLists.txt里面来控制吧。需尽量避免skipif的使用。
|
/re-run all-failed |
|
/re-run all-failed |
| main = paddle.static.Program() | ||
| startup = paddle.static.Program() | ||
| with base.program_guard(main, startup): | ||
| x = paddle.static.data(name="x", shape=self.shape, dtype=self.dtype) |
|
@Manfredss 这个PR的问题复现了吗 |
|
@Manfredss 这个尽快调试吧 |
|
|
/re-run all-failed |






PR Category
User Experience
PR Types
New features
Description
This PR implements the
addcmuloperator for PaddlePaddle, which performs element-wise multiplication of two tensors, multiplies the result by a scalar value, and adds it to an input tensor.Formula:
output = input + value * tensor1 * tensor2This operator provides users with a convenient operation for combined multiply-add computations.
Implementation Details
Core Components
C++ Kernels (
paddle/phi/kernels/)addcmul_kernel.hand implementations for CPU/GPUaddcmul_grad_kernel.hand implementations for CPU/GPUimpl/directory with templated functions for different ranks (0-6D)Operator Configuration (
paddle/phi/ops/yaml/)addcmuloperator definition inops.yamladdcmul_gradbackward operator inbackward.yamlShape Inference (
paddle/phi/infermeta/)AddcmulInferMetainternary.cc/hPIR Support (
paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/)AddcmulOpInferSymbolicShapefor new IR systemPython API (
python/paddle/tensor/)paddle.addcmul()function inmath.pyTensor.addcmul()method in__init__.pyTesting (
test/legacy_test/)Configuration (
test/white_list/)addcmulto FP64 gradient threshold whitelistFeatures
torch.addcmulTesting Results
All 52 tests pass successfully:
Test coverage includes:
valueparameters (positive, negative, default)tensor.addcmul())API Examples
Dynamic Graph Mode
Static Graph Mode
Broadcasting
Backward Compatibility
This PR adds new functionality without modifying existing APIs or behaviors. It is fully backward compatible.
Checklist
Related Issues
【启航计划】PaddlePaddle API兼容性增强 No.354
Additional Notes
MPTypeTraitfor numerical stabilityFiles Changed
New Files (9):
Modified Files (9):
是否引起精度变化
否