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][B-41,B-48][BUAA] Add type annotations for python/paddle/autograd/ir_backward.py,python/paddle/cost_model/cost_model.py #66890

Merged
merged 8 commits into from
Aug 16, 2024

Conversation

Luohongzhige
Copy link
Contributor

@Luohongzhige Luohongzhige commented Aug 1, 2024

PR Category

User Experience

PR Types

Improvements

Description

#65008
B-41,B-48

Copy link

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

@luotao1 luotao1 added contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 labels Aug 1, 2024
@Luohongzhige Luohongzhige changed the title [Typing][B-41,B-48] Add type annotations for python/paddle/autograd/ir_backward.py,python/paddle/cost_model/cost_model.py [Typing][B-41,B-48][BUAA] Add type annotations for python/paddle/autograd/ir_backward.py,python/paddle/cost_model/cost_model.py Aug 5, 2024
@luotao1
Copy link
Contributor

luotao1 commented Aug 7, 2024

@SigureMo @megemini 这个PR可以review了

inputs: Value | Sequence[Value],
grad_outputs: Value | Sequence[Value | None] | None = None,
no_grad_set: set[Value] | None = None,
) -> dict[Value, list[Value]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
) -> dict[Value, list[Value]]:
) -> ValueDict:

if TYPE_CHECKING:
from typing import Sequence

from paddle.base.libpaddle.pir import Value
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from paddle.base.libpaddle.pir import Value
from paddle.pir import Value

inputs: Value | Sequence[Value],
grad_outputs: Value | Sequence[Value | None] | None = None,
no_grad_set: set[Value] | None = None,
) -> list[Value]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
) -> list[Value]:
) -> list[Value | None]:

only_inputs: bool | None = True,
allow_unused: bool | None = False,
no_grad_vars: Value | Sequence[Value] | None = None,
) -> list[Value]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
) -> list[Value]:
) -> list[Value | None]:

create_graph: bool | None = False,
only_inputs: bool | None = True,
allow_unused: bool | None = False,
no_grad_vars: Value | Sequence[Value] | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
no_grad_vars: Value | Sequence[Value] | None = None,
no_grad_vars: Value | Sequence[Value] | set[Value] | None = None,

if TYPE_CHECKING:
from paddle.base.compiler import CompiledProgram
from paddle.base.framework import Program


class CostModel:
def __init__(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def __init__(self):
def __init__(self) -> None:

startup_program: Program | CompiledProgram,
main_program: Program | CompiledProgram,
device: str = 'gpu',
fetch_cost_list: Sequence = ['time'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fetch_cost_list: Sequence = ['time'],
fetch_cost_list: Sequence[???] = ['time'],


import json
import os
from typing import TYPE_CHECKING, Sequence
Copy link
Contributor

Choose a reason for hiding this comment

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

collections.abc 导入 Sequence

@@ -59,6 +60,11 @@
"""
__all__ = ['grad', 'calc_gradient', 'calc_gradient_helper']

if TYPE_CHECKING:
from typing import Sequence
Copy link
Contributor

Choose a reason for hiding this comment

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

collections.abc 导入

@megemini
Copy link
Contributor

megemini commented Aug 7, 2024

@Luohongzhige 请按照 PR 模板提交,不然 tracking issue 跟踪不到,无法 review ~

@megemini
Copy link
Contributor

megemini commented Aug 7, 2024

关联 #65008

@Luohongzhige
Copy link
Contributor Author

@Luohongzhige 请按照 PR 模板提交,不然 tracking issue 跟踪不到,无法 review ~

已修改

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.

LGTM ~

Comment on lines 63 to 66
if TYPE_CHECKING:
from collections.abc import Sequence

from paddle.pir import Value
Copy link
Member

Choose a reason for hiding this comment

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

要紧随其它 import,放在 55 行,不要放在这里

Copy link
Contributor Author

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.

LGTMeow 🐾

@luotao1 luotao1 merged commit 0210252 into PaddlePaddle:develop Aug 16, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants