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-107] Add type annotations for python/paddle/base/compiler.py #67699

Closed
wants to merge 1 commit into from

Conversation

haoyu2022
Copy link
Contributor

@haoyu2022 haoyu2022 commented Aug 25, 2024

PR Category

User Experience

PR Types

Improvements

Description

类型标注:

  • python/paddle/base/compiler.py

Related links

@SigureMo @megemini

Copy link

paddle-bot bot commented Aug 25, 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.

Copy link
Contributor

@megemini megemini left a 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:
Copy link
Contributor

Choose a reason for hiding this comment

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

私有方法不用标注 ~ 如果要标注,也漏掉了 config ,而且,返回的是 Self

另外,__init__ 等魔法方法需要标注,上面漏掉了 ~

Copy link
Contributor Author

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:
Copy link
Contributor

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", ...]]
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

有不少漏的吧……比如 register_patch

if TYPE_CHECKING:
from typing_extensions import TypeAlias

_ClassInfo: TypeAlias = Union[type[Any], Tuple["_ClassInfo", ...]]
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.

这个文件有些地方我还没看太明白,我再仔细看看。

@@ -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:
Copy link
Member

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:
Copy link
Member

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:
Copy link
Member

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:
Copy link
Member

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,
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

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

这个 optionsTypedDict 标注下

@@ -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:
Copy link
Member

Choose a reason for hiding this comment

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

同样用 TypedDict

@paddle-bot paddle-bot bot added the contributor External developers label Aug 25, 2024
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Aug 26, 2024
@megemini
Copy link
Contributor

@haoyu2022 由于需要结项,我这里就把这个任务接过来了 #67767

不好意思 ~ 🤟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants