Skip to content
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

Merged
merged 5 commits into from
Jul 23, 2024

Conversation

BHmingyang
Copy link
Contributor

PR Category

User Experience

PR Types

Improvements

Description

类型标注
python/paddle/distributed/communication/gather.py

Copy link

paddle-bot bot commented Jul 19, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Jul 19, 2024
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Jul 19, 2024
def gather(tensor, gather_list=None, dst=0, group=None, sync_op=True):
def gather(
tensor: Tensor,
gather_list: list = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gather_list: list = None,
gather_list: list[Tensor] = None,

泛型必须写明参数类型

dst: int = 0,
group: Group | None = None,
sync_op: bool = True,
) -> task | None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返回值是 Union 的情况优先考虑使用 overload 进行区分,这里可以使用 sync_op 来进行区分

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可参考 python/paddle/tensor/linalg.pylu 函数

Copy link
Contributor Author

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就行?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overload 就是要写多个的

@SigureMo SigureMo changed the title [Typing][C-17] Add type annotations for python/paddle/distributed/communication/gather.py [Typing][C-17] Add type annotations for python/paddle/distributed/communication/gather.py Jul 21, 2024
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

@SigureMo SigureMo merged commit b4e3e9f into PaddlePaddle:develop Jul 23, 2024
31 checks passed
@BHmingyang BHmingyang deleted the wendang branch July 25, 2024 06:00
inaomIIsfarell pushed a commit to inaomIIsfarell/Paddle that referenced this pull request Jul 31, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants