Skip to content
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][C-21,C-22,C-23,C-24] Add type annotations for python/paddle/distributed/communication/{reduce_scatter.py, scatter.py, send.py, all_gather.py} #66864

Merged
merged 12 commits into from
Aug 6, 2024

Conversation

Lans1ot
Copy link
Contributor

@Lans1ot Lans1ot commented Jul 31, 2024

PR Category

User Experience

PR Types

Improvements

Description

#65008
尝试添加函数类型信息

Copy link

paddle-bot bot commented Jul 31, 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.

):
tensor: Tensor,
tensor_list: list[Tensor],
op: ReduceOp = ReduceOp.SUM,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里类型不是 ReduceOp ,参考 https://github.com/PaddlePaddle/Paddle/pull/66803/files

合一下代码,从那里导入 _ReduceOp 吧 ~

):
output: Tensor,
input: Tensor,
op: ReduceOp = ReduceOp.SUM,
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

def scatter(tensor, tensor_list=None, src=0, group=None, sync_op=True):
def scatter(
tensor: Tensor,
tensor_list: list[Tensor] | tuple[Tensor] | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里 tuple 缺少 ... ~ 用 Sequence 吧 ~

@luotao1 luotao1 added contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 labels Jul 31, 2024
@Lans1ot
Copy link
Contributor Author

Lans1ot commented Aug 2, 2024

@megemini 请问一下,static-check里提示error: Argument 2 to "scatter_object_list" has incompatible type "List[Dict[str, List[int]]]"; expected "Optional[List[object]]" [arg-type],但是我看paddle的api文档是list[Any],我修改的代码写的是list[object],请问为什么会出现这个情况呢

Co-authored-by: megemini <megemini@outlook.com>
Comment on lines +89 to +90
out_object_list: list[Any],
in_object_list: list[Any] | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

没有导入 Any

group: Group | None = None,
sync_op: bool = True,
use_calc_stream: bool = False,
) -> task:
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
) -> task:
) -> task | None:

def _all_gather_in_static_mode(tensor_list, tensor, group, sync_op):
def _all_gather_in_static_mode(
tensor_list: list[Tensor], tensor: Tensor, group: Group, sync_op: bool
) -> task:
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
) -> task:
) -> None:

dst: int = 0,
group: Group | None = None,
sync_op: bool = True,
) -> task:
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
) -> task:
) -> task | None:

@@ -51,7 +65,7 @@ def send(tensor, dst=0, group=None, sync_op=True):
)


def isend(tensor, dst, group=None):
def isend(tensor: Tensor, dst: int, group: Group | None = None) -> task:
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
def isend(tensor: Tensor, dst: int, group: Group | None = None) -> task:
def isend(tensor: Tensor, dst: int, group: Group | None = None) -> task | None:

src: int = 0,
group: Group | None = None,
sync_op: bool = True,
) -> 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
) -> None:
) -> task | None:

task 记得 import

Comment on lines +79 to +88
if op not in [
ReduceOp.AVG,
ReduceOp.MAX,
ReduceOp.MIN,
ReduceOp.PROD,
ReduceOp.SUM,
]:
raise RuntimeError(
"Invalid ``op`` function. Expected ``op`` to be of type ``ReduceOp.SUM``, ``ReduceOp.Max``, ``ReduceOp.MIN``, ``ReduceOp.PROD`` or ``ReduceOp.AVG``."
)
Copy link
Member

Choose a reason for hiding this comment

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

这里还有下面的检查代码是为了解决什么呢?如果没什么特别需要解决的问题最好还是不要加,因为本任务只涉及类型提示修改,不涉及运行时逻辑修改

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这是因为我之前做其他任务的时候,有类似的情况。
就是参数只能在特定值中间进行选择,不然就会抛出一个错误
所以我这里就根据python/paddle/distributed/communication/batch_isend_irecv.py仿写了一段

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 58f7899 into PaddlePaddle:develop Aug 6, 2024
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants