-
Notifications
You must be signed in to change notification settings - Fork 5.9k
API improvement for F.pad 易用性提升 #65903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
2是兼容性升级的,直接升级就行吧,无需捆绑pad_from_first_axis。兼容性升级你对齐torch。 只有不兼容升级,才用pad_from_first_axis这个参数降低影响,因此别弄那么复杂,这个参数不要捆绑那么多情况,只针对情况1时的不兼容升级,其他情况直接忽略该参数。 |
|
@NKNaN 关注上述评论 |
|
Sorry to inform you that 2feee53's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
|
好的,我再改一下 |
更新一下PR描述 |
已更新 |
| name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: ``'None'``. | ||
| the input data when: 1. mode is any of ``'reflect'``, ``'replicate'`` or ``'circular'``; or 2. the input ``'pad'`` is a tensor; | ||
| or 3. the length of ``'pad'`` is ``2*(x.ndim - 2)``. Default: ``'NCHW'``. | ||
| pad_from_first_axis (bool, optional): When mode is ``'constant'`` and the input ``'pad'`` is a list or tuple and the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
先写一下,仅当什么情况下生效。
非constant其他mode下为何不生效?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改,仅当 mode 是 constant,且 pad 是 list/tuple,且 pad 长度是 2*x.ndim 时生效。
其他 mode 支持的 pad 长度是 2(N-2)。
| paddings = pad | ||
| pad_value = value | ||
|
|
||
| padding_len = len(paddings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kernel内部好修改吗
| ) | ||
|
|
||
| # since the kernel pad from first axis, if we want to pad from last axis, we need to reverse the paddings | ||
| if not (len(pad) == x_dim * 2 and pad_from_first_axis): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在kernel内部好修改吗,目前主要是通过在Python层面组合适配的,导致kernel内部计算结果差异较大,可能导致推理等场景出现问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我试一下吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个改动看起来挺大的,能否先抽出一部分逻辑,将除 len(pad) == 2 * x.ndim 之外的情况修改先合入。
即:
F.pad 不支持除了 len(pad) == 2 * x.ndim 或 len(pad) == 2 * (x.ndim - 2) 以外的情况
然后pad_from_first_axis命名为pad_from_left_axis吧,之前的另外一种轻量实现你还在吗,也提一个PR吧,两个综合对比下看哪个更好,因为下放到c++ kernel来实现的影响确实比较大,之前疏忽了,没考虑到这一点抱歉。
|
Sorry to inform you that d7457e5's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |


PR Category
User Experience
PR Types
Improvements
Description
解决的问题:
len(pad) == 2 * x.ndim时,axis 左对齐,需改为 axis 右对齐len(pad) == 2 * x.ndim或len(pad) == 2 * (x.ndim - 2)以外的情况修改方法:
添加 pad_from_first_axis 参数,默认为 True。只在
len(pad) == 2 * x.ndim时起作用。修改后 F.pad 的行为是:
len(pad) == 2 * x.ndim时,默认 axis 左对齐,可以通过设置 pad_from_first_axis 参数为 False 改为右对齐;len(pad) != 2 * (x.ndim - 2)时,axis 右对齐;len(pad) == 2 * (x.ndim - 2)时,x.ndim 只能是 3、4、5,从 [D, H, W]的最后一个维度开始填充,也是axis右对齐。