[API Compatibility] align the loss apis --part#78811
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
zhwesky2010
left a comment
There was a problem hiding this comment.
这些没对齐的关键是 https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/utils/decorator_utils.py#L801
Pytorch支持size_average、reduce的用法,用PaConvert先测试看看。
| np.testing.assert_allclose(fetches[0], fetches[i], rtol=1e-5) | ||
|
|
||
|
|
||
| class TestL1LossAPI(unittest.TestCase): |
There was a problem hiding this comment.
测下这些用法:size_average、reduce
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #78811 +/- ##
==========================================
Coverage ? 97.19%
==========================================
Files ? 3
Lines ? 107
Branches ? 0
==========================================
Hits ? 104
Misses ? 3
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/re-run all-failed |
| @@ -865,37 +989,87 @@ def legacy_reduction_special_decorator( | |||
There was a problem hiding this comment.
这些装饰器体系有些复杂了,尽可能把这些装饰器合起来,代码复用:
- 别名装饰器通过配置来解决,每个API只能有一个装饰器
- func和layer的装饰器能否合并?
| _consume_legacy_positional_args(cls_name, args, kwargs) | ||
| ) | ||
| ): | ||
| raise_deprecated_error(cls_name, reduce_val, size_avg_val) |
There was a problem hiding this comment.
看一看怎么在之前的基础上进行最小改动:只在之前的基础上设置下suggested,将raise_deprecated_error换个名字。
|
/re-run all-failed |
|
Paddle 与 PyTorch 在 loss API 上的不对齐主要分 5 类:
想法是把第 (1)(2)(3) 类一次性折叠到一个机制里:在 第 (4) 类靠 |
方案基本没问题,可以再简化下:
|
…h<->Paddle 参数别名 合并到一张 ``LEGACY_POS`` 表中,由 ``legacy_reduction_decorator`` 一次性完成位置 -> 关键字、关键字别名重命名、``size_average/reduce`` → ``reduction`` 的全部转换;同时移除,loss API 上多余的 ``@param_one_alias`` / ``@param_two_alias`` / ``@ParamAliasDecorator`` 装饰器
|
/re-run all-failed |
… indexed slot only when the value is a bool
|
/re-run all-failed |
1 similar comment
|
/re-run all-failed |
There was a problem hiding this comment.
减少下注释吧。风格参考:
https://github.com/pytorch/pytorch/blob/main/CLAUDE.md#coding-style-guidelines
代码自身即为注释
| return decorator | ||
|
|
||
|
|
||
| # PyTorch positional layout for each loss API. Each entry maps the API |
There was a problem hiding this comment.
注释可以不用写太多(只写必要的注释),从代码可读性与简洁的角度来设计代码,参考
https://github.com/pytorch/pytorch/blob/main/CLAUDE.md#coding-style-guidelines
| return len(use_args) > idx and use_args[idx] in allowed | ||
|
|
||
|
|
||
| def legacy_reduction_decorator(fn=None, *, is_method=True): |
There was a problem hiding this comment.
这个实现看起来也挺复杂的,那还是用第一版实现吧:
不用维护_SA0_RD1这些信息了,每个loss API维护一个args_list+kwargs_change,直接按args_list匹配然后pop掉size_average/reduce,设置reduction,修改别名即可。
相当于paconvert的逻辑搬过来
| """ | ||
|
|
||
| @legacy_reduction_decorator | ||
| @param_one_alias(["epsilon", "eps"]) |
PR Category
User Experience
PR Types
New features
Description
align the loss apis in
nn.layerandnn.functional是否引起精度变化
否