-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Typing][C-17] Add type annotations for python/paddle/distributed/communication/gather.py
#66276
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
def gather(tensor, gather_list=None, dst=0, group=None, sync_op=True): | ||
def gather( | ||
tensor: Tensor, | ||
gather_list: list = 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.
gather_list: list = None, | |
gather_list: list[Tensor] = None, |
泛型必须写明参数类型
dst: int = 0, | ||
group: Group | None = None, | ||
sync_op: bool = True, | ||
) -> task | 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.
返回值是 Union 的情况优先考虑使用 overload 进行区分,这里可以使用 sync_op
来进行区分
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.
可参考 python/paddle/tensor/linalg.py
的 lu
函数
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.
@overload
def lu(
x: Tensor,
pivot: bool = ...,
get_infos: Literal[True] = ...,
name: str | None = ...,
) -> tuple[Tensor, Tensor, Tensor]:
...
@overload
def lu(
x: Tensor, pivot: bool = ..., get_infos: bool = ..., name: str | None = ...
) -> tuple[Tensor, Tensor] | tuple[Tensor, Tensor, Tensor]:
...
def lu(
x, pivot=True, get_infos=False, name=None
) -> tuple[Tensor, Tensor] | tuple[Tensor, Tensor, Tensor]:
是也要像这样写多了def lu()吗?还是把返回值改成tuple就行?
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.
overload 就是要写多个的
python/paddle/distributed/communication/gather.py
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.
…mmunication/gather.py` (PaddlePaddle#66276)
PR Category
User Experience
PR Types
Improvements
Description
类型标注
python/paddle/distributed/communication/gather.py