-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Typing][A-54,A-55,A-56] Add type annotations for paddle/nn/functional/{activation.py, common.py, conv.py}
#65191
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
def softmax( | ||
x: Tensor, | ||
axis: int = -1, | ||
dtype: Literal['bfloat16', 'float16', 'float32', 'float64'] | None = None, |
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.
不支持 paddle.dtype
形式么?支持的话统一使用 DTypeLike
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.
这里没说支持int和complex和bool
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.
这个是没关系的,我们不可能每次将所有支持的数据类型都枚举出来,这部分工作只能由运行时来做,至少我们需要保证该支持的传进来类型检查不会报错,目前这类 API 应该统一使用 DTypeLike
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.
修改下这里就没其它的问题了,这里明显是支持 paddle.dtype / np.dtype
的
Paddle/python/paddle/nn/functional/activation.py
Lines 1198 to 1203 in 8f8bd44
if ( | |
(dtype is not None) | |
and (not isinstance(dtype, core.VarDesc.VarType)) | |
and (not isinstance(dtype, core.DataType)) | |
): | |
dtype = convert_np_dtype_to_dtype_(dtype) |
def softmax_( | ||
x: Tensor, | ||
axis: int = -1, | ||
dtype: Literal['bfloat16', 'float16', 'float32', 'float64'] | None = None, |
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.
这里没说支持int和complex和bool
def log_softmax( | ||
x: Tensor, | ||
axis: int = -1, | ||
dtype: Literal['float32', 'float64'] | None = None, |
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.
同上
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.
#65197 发现了 DataLayout2D 里的一个 typo,可以麻烦先改一下么?
-DataLayout2D: TypeAlias = Literal["NCHW", "NHCW"]
+DataLayout2D: TypeAlias = Literal["NCHW", "NHWC"]
夜猫子好评 >_< |
@gsq7474741 CI 里面 fail 的,看看是不是 numpy 版本与 opencv 兼容问题 ~ 可以重新构建一下 ~ |
x: Tensor, | ||
size: ShapeLike | None = None, | ||
scale_factor: ShapeLike | None = None, | ||
mode: Literal[ |
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.
放到 _typing 里面吧,加个类似 PaddingMode
的类型,叫做 InterpolateMode
吧 ~ 其他地方也会用到 ~
另外,Literal["NCW", "NWC", "NCHW", "NHWC", "NCDHW", "NDHWC"]
这个也改成 DataLayoutNDVariant
吧,类似 DataLayout1DVariant
~ 在 _typing.layout.py
下面 ~
@SigureMo 后面是不是可以反馈一下,把这个统一一下 ~
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.
确认下其他地方有没有用,没有用的话不建议一股脑丢到 _typing
,部分类型可以按照模块本来的 import 关系管理,比如 functional 里定义一个 TypeAlias,layer 里引用,那就完全没必要塞到 _typing
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.
] = 'nearest', | ||
align_corners: bool = False, | ||
align_mode: int = 0, | ||
data_format: Literal["NCW", "NWC", "NCHW", "NHWC", "NCDHW", "NDHWC"] = None, |
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.
同上~
def pad( | ||
x: Tensor, | ||
pad: ShapeLike, | ||
mode: Literal["constant", "reflect", "replicate", "circular"] = 'constant', |
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.
刚翻了一下 numpy 的处理方式,numpy 是把这类东西叫做 _ModeKind
,私有的,所以放到各个模块中 ~
由此,后面类似的处理方式可以有两种:
- numpy 的方式
- 统一放到 _typing 中,但是名称有区分
如果采用后者,这个也放到 _typing
里面,感觉这个叫 PaddingMode
, conv 里面的那个叫 ConvPaddingMode
~ 如何?
@SigureMo 帮忙看看
我不确定,我看之前的子任务都是用的
HappyOpenSource
@luotao1 确认下? @gsq7474741 不过这个会有什么影响吗? |
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.
…al/{activation.py, common.py, conv.py}` (PaddlePaddle#65191) --------- Co-authored-by: SigureMo <sigure.qaq@gmail.com>
PR Category
User Experience
PR Types
Improvements
Description
类型标注:
Related links
@SigureMo @megemini