-
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][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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
): | ||
tensor: Tensor, | ||
tensor_list: list[Tensor], | ||
op: ReduceOp = ReduceOp.SUM, |
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.
这里类型不是 ReduceOp
,参考 https://github.com/PaddlePaddle/Paddle/pull/66803/files
合一下代码,从那里导入 _ReduceOp
吧 ~
): | ||
output: Tensor, | ||
input: Tensor, | ||
op: ReduceOp = ReduceOp.SUM, |
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 scatter(tensor, tensor_list=None, src=0, group=None, sync_op=True): | ||
def scatter( | ||
tensor: Tensor, | ||
tensor_list: list[Tensor] | tuple[Tensor] | 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.
这里 tuple
缺少 ...
~ 用 Sequence
吧 ~
Co-authored-by: megemini <megemini@outlook.com>
… into develop+type_hint_2
@megemini 请问一下,static-check里提示 |
Co-authored-by: megemini <megemini@outlook.com>
out_object_list: list[Any], | ||
in_object_list: list[Any] | 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.
没有导入 Any
group: Group | None = None, | ||
sync_op: bool = True, | ||
use_calc_stream: bool = False, | ||
) -> task: |
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.
) -> 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: |
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.
) -> task: | |
) -> None: |
dst: int = 0, | ||
group: Group | None = None, | ||
sync_op: bool = True, | ||
) -> task: |
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.
) -> 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: |
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 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: |
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.
) -> None: | |
) -> task | None: |
task
记得 import
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``." | ||
) |
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.
这是因为我之前做其他任务的时候,有类似的情况。
就是参数只能在特定值中间进行选择,不然就会抛出一个错误
所以我这里就根据python/paddle/distributed/communication/batch_isend_irecv.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.
PR Category
User Experience
PR Types
Improvements
Description
#65008
尝试添加函数类型信息