-
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-107] Add type annotations for python/paddle/base/compiler.py
#67699
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
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.
没有全部 review 完,这个文件里面需要标注的是
- "CompiledProgram",
- "IpuCompiledProgram",
- "IpuStrategy"
这三个类,标注其中类的实例参数、公共方法、魔法方法 ~
目前有很多地方都有标注不全的情况 ~
@@ -147,7 +155,7 @@ def __init__(self, program_or_graph, build_strategy=None): | |||
self._places = None | |||
self._build_strategy = build_strategy | |||
|
|||
def _with_inference_optimize(self, config): | |||
def _with_inference_optimize(self, config) -> 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.
私有方法不用标注 ~ 如果要标注,也漏掉了 config
,而且,返回的是 Self
~
另外,__init__
等魔法方法需要标注,上面漏掉了 ~
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.
好的,我再仔细看看🤔
@@ -446,7 +454,7 @@ def func_compile(): | |||
return concrete_program | |||
|
|||
@staticmethod | |||
def patch_program_cache(ipu_strategy): | |||
def patch_program_cache(ipu_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.
上面的 __init__
和 convert_concrete_program
没有标注
if TYPE_CHECKING: | ||
from typing_extensions import TypeAlias | ||
|
||
_ClassInfo: TypeAlias = Union[type[Any], Tuple["_ClassInfo", ...]] |
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.
有不少漏的吧……比如 register_patch
if TYPE_CHECKING: | ||
from typing_extensions import TypeAlias | ||
|
||
_ClassInfo: TypeAlias = Union[type[Any], Tuple["_ClassInfo", ...]] |
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.
这个文件有些地方我还没看太明白,我再仔细看看。
@@ -147,7 +155,7 @@ def __init__(self, program_or_graph, build_strategy=None): | |||
self._places = None | |||
self._build_strategy = build_strategy | |||
|
|||
def _with_inference_optimize(self, config): | |||
def _with_inference_optimize(self, config) -> 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.
你要不会标,这些下划线开头的非公开 API 就不要标了,标个 Any
和没标一样
@@ -272,7 +280,7 @@ def _compile_data_parallel(self, places, use_device, scope=None): | |||
def _compile_inference(self): | |||
return core.create_paddle_predictor(self._infer_config) | |||
|
|||
def _compile(self, scope, place): | |||
def _compile(self, scope, place) -> 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.
同上
@@ -615,7 +623,7 @@ def release_patch(self): | |||
""" | |||
IpuDynamicPatcher.release_patch() | |||
|
|||
def set_optimizer(self, optimizer): | |||
def set_optimizer(self, optimizer: Any) -> 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.
optimizer
怎么会是 Any
?
@@ -647,7 +655,7 @@ def set_optimizer(self, optimizer): | |||
else: | |||
raise RuntimeError("Only needs to set optimizer in dynamic mode.") | |||
|
|||
def parse_optimizer(self, optimizer): | |||
def parse_optimizer(self, optimizer: Any) -> 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.
怎么全是 Any
?
num_ipus=1, | ||
is_training=True, | ||
num_ipus: int = 1, | ||
is_training: bool = True, | ||
micro_batch_size=1, |
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.
这个怎么不标?
@@ -859,7 +871,7 @@ def add_custom_op( | |||
if not self.has_custom_ops: | |||
self.has_custom_ops = True | |||
|
|||
def set_options(self, options): | |||
def set_options(self, options: dict[str, Any]) -> 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.
这个 options
用 TypedDict
标注下
@@ -889,15 +901,15 @@ def set_options(self, options): | |||
if options.keys() - recompile_white_list: | |||
self.need_compile = True | |||
|
|||
def get_option(self, option): | |||
def get_option(self, option: str) -> 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.
同样用 TypedDict
@haoyu2022 由于需要结项,我这里就把这个任务接过来了 #67767 不好意思 ~ 🤟 |
PR Category
User Experience
PR Types
Improvements
Description
类型标注:
Related links
@SigureMo @megemini