Repository navigation
[Typing][C-43, C-44][BUAA] Add type annotations for python/paddle/distributed/fleet/* - #67469
Merged
Merged
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Contributor
|
关联 #65008 |
python/paddle/distributed/fleet/python/paddle/distributed/fleet/*
megemini
reviewed
Aug 16, 2024
| from collections.abc import MutableSet | ||
|
|
||
| from paddle.base.framework import Block | ||
| from paddle.distributed.auto_parallel import Strategy |
Comment on lines
+63
to
+64
| self.role_maker: None | PaddleCloudRoleMaker = None | ||
| self.dist_strategy: None | Strategy = None |
| def all_reduce(self, input, mode="sum", comm_world="worker"): | ||
| def all_reduce( | ||
| self, | ||
| input: list | tuple | np.array, |
Contributor
There was a problem hiding this comment.
Suggested change
| input: list | tuple | np.array, | |
| input: NestedNumbericSequence | npt.NDArray[Any], |
| def all_reduce( | ||
| self, | ||
| input: list | tuple | np.array, | ||
| mode: str = "sum", |
| self, | ||
| input: list | tuple | np.array, | ||
| mode: str = "sum", | ||
| comm_world: str = "worker", |
Comment on lines
+452
to
+461
| 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]]]: |
| def reader(batch_size, fn, dim): | ||
| def _params_check( | ||
| self, config: Any | ||
| ) -> list | list[np.array[Any]] | Literal[False]: |
Contributor
There was a problem hiding this comment.
Suggested change
| ) -> list | list[np.array[Any]] | Literal[False]: | |
| ) -> list[Tensor] | list[npt.NDArray[Any]] | Literal[False]: |
Comment on lines
+507
to
+509
| def check_not_expected_ops( | ||
| prog: Program, not_expected_op_types: list | ||
| ) -> MutableSet: |
| # 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: |
Contributor
There was a problem hiding this comment.
参考示例格式
>>> [("words", ["1926", "08", "17"]), ("label", ["1"])]
>>> or (("words", ["1926", "08", "17"]), ("label", ["1"]))|
|
||
| class MultiSlotDataGenerator(DataGenerator): | ||
| def _gen_str(self, line): | ||
| def _gen_str(self, line: str) -> str: |
megemini
reviewed
Aug 19, 2024
| from typing import TYPE_CHECKING, Any, Literal | ||
|
|
||
| import numpy as np | ||
| import numpy.typing as npt |
| self.dist_strategy: DistributedStrategy | None = None | ||
|
|
||
| def _set_strategy(self, dist_strategy): | ||
| def _set_strategy(self, dist_strategy: None | DistributedStrategy) -> None: |
Contributor
There was a problem hiding this comment.
None 放到后面 ... ... 别说哪儿改哪儿啊 ~ 相关的问题都要修改 ~
| def all_reduce(self, input, mode="sum", comm_world="worker"): | ||
| def all_reduce( | ||
| self, | ||
| input: NestedNumbericSequence | np.NDArray[Any], |
Contributor
There was a problem hiding this comment.
Suggested change
| input: NestedNumbericSequence | np.NDArray[Any], | |
| input: NestedNumbericSequence | npt.NDArray[Any], |
| class MultiSlotStringDataGenerator(DataGenerator): | ||
| def _gen_str(self, line): | ||
| def _gen_str( | ||
| self, line: tuple[tuple[str, list[str]]] | list[tuple[str, list[str]]] |
Contributor
There was a problem hiding this comment.
Suggested change
| 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]]]
| class MultiSlotDataGenerator(DataGenerator): | ||
| def _gen_str(self, line): | ||
| def _gen_str( | ||
| self, line: tuple[tuple[str, list[int]]] | list[tuple[str, list[int]]] |
Contributor
There was a problem hiding this comment.
同上。另外,应该是 list[float]
the type of element{type(elem)} must be in int or float
megemini
reviewed
Aug 20, 2024
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| from typing import Sequence |
| def _gen_str( | ||
| self, | ||
| line: ( | ||
| Sequence[tuple[str, list[str]], ...] | list[tuple[str, list[str]]] |
Contributor
There was a problem hiding this comment.
Suggested change
| 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]]], |
Contributor
There was a problem hiding this comment.
Suggested change
| line: Sequence[tuple[str, list[float]]] | list[tuple[str, list[float]]], | |
| line: Sequence[tuple[str, list[float]]], |
luotao1
approved these changes
Aug 21, 2024
This was referenced Aug 23, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Category
User Experience
PR Types
Improvements
Description
类型标注:
Related links
@SigureMo @megemini