-
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-43, C-44][BUAA] Add type annotations for python/paddle/distributed/fleet/*
#67469
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
关联 #65008 |
python/paddle/distributed/fleet/
python/paddle/distributed/fleet/*
from collections.abc import MutableSet | ||
|
||
from paddle.base.framework import Block | ||
from paddle.distributed.auto_parallel import Strategy |
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.
是 DistributedStrategy
self.role_maker: None | PaddleCloudRoleMaker = None | ||
self.dist_strategy: None | Strategy = 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
放到后面
def all_reduce(self, input, mode="sum", comm_world="worker"): | ||
def all_reduce( | ||
self, | ||
input: list | tuple | np.array, |
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.
input: list | tuple | np.array, | |
input: NestedNumbericSequence | npt.NDArray[Any], |
def all_reduce( | ||
self, | ||
input: list | tuple | np.array, | ||
mode: str = "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.
用 Literal
self, | ||
input: list | tuple | np.array, | ||
mode: str = "sum", | ||
comm_world: str = "worker", |
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.
用 Literal
def feed_gen( | ||
batch_size: int, | ||
feeded_vars_dims: list[int], | ||
feeded_vars_filelist: list[str], | ||
) -> list[list[np.array[list[float]]]]: | ||
def reader( | ||
batch_size: int, | ||
fn: str, | ||
dim: list[float] | tuple[float] | float, | ||
) -> list[np.array[list[float]]]: |
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 reader(batch_size, fn, dim): | ||
def _params_check( | ||
self, config: Any | ||
) -> list | list[np.array[Any]] | Literal[False]: |
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.
) -> list | list[np.array[Any]] | Literal[False]: | |
) -> list[Tensor] | list[npt.NDArray[Any]] | Literal[False]: |
def check_not_expected_ops( | ||
prog: Program, not_expected_op_types: list | ||
) -> MutableSet: |
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.
不用标注
@@ -230,7 +230,7 @@ def local_iter(): | |||
# add more generalized DataGenerator that can adapt user-defined slot | |||
# for example, [(name, float_list), (name, str_list), (name, int_list)] | |||
class MultiSlotStringDataGenerator(DataGenerator): | |||
def _gen_str(self, line): | |||
def _gen_str(self, line: str) -> str: |
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.
参考示例格式
>>> [("words", ["1926", "08", "17"]), ("label", ["1"])]
>>> or (("words", ["1926", "08", "17"]), ("label", ["1"]))
@@ -275,7 +275,7 @@ def _gen_str(self, line): | |||
|
|||
|
|||
class MultiSlotDataGenerator(DataGenerator): | |||
def _gen_str(self, line): | |||
def _gen_str(self, line: str) -> str: |
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.
同上,看一下示例代码 ~
|
||
import numpy as np | ||
import numpy.typing as npt |
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.
放到 TYPE_CHECKING
里面
|
||
def _set_strategy(self, dist_strategy): | ||
def _set_strategy(self, dist_strategy: None | DistributedStrategy) -> 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
放到后面 ... ... 别说哪儿改哪儿啊 ~ 相关的问题都要修改 ~
def all_reduce(self, input, mode="sum", comm_world="worker"): | ||
def all_reduce( | ||
self, | ||
input: NestedNumbericSequence | np.NDArray[Any], |
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.
input: NestedNumbericSequence | np.NDArray[Any], | |
input: NestedNumbericSequence | npt.NDArray[Any], |
@@ -230,7 +231,9 @@ def local_iter(): | |||
# add more generalized DataGenerator that can adapt user-defined slot | |||
# for example, [(name, float_list), (name, str_list), (name, int_list)] | |||
class MultiSlotStringDataGenerator(DataGenerator): | |||
def _gen_str(self, line): | |||
def _gen_str( | |||
self, line: tuple[tuple[str, list[str]]] | list[tuple[str, list[str]]] |
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.
self, line: tuple[tuple[str, list[str]]] | list[tuple[str, list[str]]] | |
self, line: tuple[tuple[str, list[str]], ...] | list[tuple[str, list[str]]] |
用 Sequence
,Sequence[tuple[str, list[str]]]
@@ -275,7 +278,9 @@ def _gen_str(self, line): | |||
|
|||
|
|||
class MultiSlotDataGenerator(DataGenerator): | |||
def _gen_str(self, line): | |||
def _gen_str( | |||
self, line: tuple[tuple[str, list[int]]] | list[tuple[str, list[int]]] |
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.
同上。另外,应该是 list[float]
the type of element{type(elem)} must be in int or float
@@ -14,6 +14,7 @@ | |||
from __future__ import annotations | |||
|
|||
import sys | |||
from typing import Sequence |
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.
从 collections.abc
导入
def _gen_str( | ||
self, | ||
line: ( | ||
Sequence[tuple[str, list[str]], ...] | list[tuple[str, list[str]]] |
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.
Sequence[tuple[str, list[str]], ...] | list[tuple[str, list[str]]] | |
Sequence[tuple[str, list[str]]] |
了解一下 list
与 Sequence
的关系
def _gen_str(self, line): | ||
def _gen_str( | ||
self, | ||
line: Sequence[tuple[str, list[float]]] | list[tuple[str, list[float]]], |
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.
line: Sequence[tuple[str, list[float]]] | list[tuple[str, list[float]]], | |
line: Sequence[tuple[str, list[float]]], |
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.
LGTM
PR Category
User Experience
PR Types
Improvements
Description
类型标注:
Related links
@SigureMo @megemini