[API Compatibility] Support legacy reduction args for BCE/MSE/multi_margin/nll_loss#78574
[API Compatibility] Support legacy reduction args for BCE/MSE/multi_margin/nll_loss#78574Aidenwu0209 wants to merge 4 commits intoPaddlePaddle:developfrom
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (77.77%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #78574 +/- ##
==========================================
Coverage ? 77.77%
==========================================
Files ? 1
Lines ? 36
Branches ? 0
==========================================
Hits ? 28
Misses ? 8
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
python/paddle/nn/functional/loss.py
Outdated
| kIgnoreIndex = -100 | ||
|
|
||
|
|
||
| def _resolve_legacy_reduction_args( |
There was a problem hiding this comment.
这个你修改原来的legacy_reduction_decorator、legacy_reduction_special_decorator,原本的代码上是warning,你改成直接设置size_average/reduce
| return size_average, ignore_index, reduce, reduction | ||
|
|
||
|
|
||
| def dice_loss( |
There was a problem hiding this comment.
只加装饰器,不改API签名,这两个废弃参数避免直接加到API上。
test/legacy_test/test_bce_loss.py
Outdated
| @@ -299,6 +300,157 @@ def test_BCELoss_target_alias_static(self): | |||
| ) | |||
|
|
|||
|
|
|||
| class TestBCELossLegacyReductionArgs(unittest.TestCase): | |||
There was a problem hiding this comment.
legacy_reduction_decorator、legacy_reduction_special_decorator涉及的十几个API都同等情况处理size_average/reduce测试,都加下
| is_method = len(param_names) > 0 and param_names[0] == 'self' | ||
|
|
||
| @functools.wraps(init_func) | ||
| def wrapper(*args: _InputT.args, **kwargs: _InputT.kwargs) -> _RetT: |
|
|
||
| wrapper.__signature__ = inspect.signature(init_func) | ||
| return wrapper | ||
| return _legacy_reduction_wrapper(init_func, special=True) |
python/paddle/nn/functional/loss.py
Outdated
|
|
||
|
|
||
| @legacy_reduction_decorator | ||
| @param_one_alias(["label", "target"]) |
There was a problem hiding this comment.
这些别名装饰器融合到legacy_reduction_decorator里,每个API只配置一个装饰器

PR Category
User Experience
PR Types
New features
Description
Complete the functional-loss alignment needed for PaConvert prefix-only conversion on these APIs:
paddle.nn.functional.binary_cross_entropypaddle.nn.functional.mse_losspaddle.nn.functional.multi_margin_losspaddle.nn.functional.nll_lossThis PR:
size_average/reducecompatibility while keeping Paddle's historical positional reduction calls availabletargetalias usage aligned for these functional lossesRelated issue: #76301 (No.154 / No.186 / No.187 / No.188)
????????
?