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-81,C-102,C-103,C-105] Add type annotations for {fused_dropout_add,bfgs,lbfgs,math}.py in incubate APIs #67233

Merged
merged 6 commits into from
Aug 13, 2024

Conversation

Lans1ot
Copy link
Contributor

@Lans1ot Lans1ot commented Aug 8, 2024

PR Category

User Experience

PR Types

Improvements

Description

#65008
尝试添加函数类型信息

但有一个问题,scalar该如何标注,我这里是用的float。

Copy link

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

@paddle-bot paddle-bot bot added the contributor External developers label Aug 8, 2024
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Aug 9, 2024
def __init__(self, p=0.5, mode="upscale_in_train", name=None):
def __init__(
self,
p: int = 0.5,
Copy link
Contributor

Choose a reason for hiding this comment

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

???

def __init__(
self,
p: int = 0.5,
mode: str = "upscale_in_train",
Copy link
Contributor

Choose a reason for hiding this comment

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

Literal

@@ -12,10 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

from typing import TYPE_CHECKING, Callable
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 导入 Callable

dtype='float32',
name=None,
):
objective_func: Callable[[Tensor], float],
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
objective_func: Callable[[Tensor], float],
objective_func: Callable[[Tensor], Tensor],

应该是个标量形式的 Tensor ,具体类型还是 Tensor

tolerance_grad: float = 1e-7,
tolerance_change: float = 1e-9,
initial_inverse_hessian_estimate: Tensor | None = None,
line_search_fn: str = 'strong_wolfe',
Copy link
Contributor

Choose a reason for hiding this comment

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

Literal

line_search_fn: str = 'strong_wolfe',
max_line_search_iters: int = 50,
initial_step_length: float = 1.0,
dtype: str = 'float32',
Copy link
Contributor

Choose a reason for hiding this comment

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

Literal

@@ -12,6 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

from typing import TYPE_CHECKING, Callable
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

Comment on lines 35 to 47
objective_func: Callable[[Tensor], float],
initial_position: Tensor,
history_size: int = 100,
max_iters: int = 50,
tolerance_grad: float = 1e-8,
tolerance_change: float = 1e-8,
initial_inverse_hessian_estimate: Tensor | None = None,
line_search_fn: str = 'strong_wolfe',
max_line_search_iters: int = 50,
initial_step_length: int = 1.0,
dtype: str = 'float32',
name: str | None = None,
) -> tuple[bool, int, Tensor, Tensor, Tensor]:
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

tolerance_grad: float = 1e-7,
tolerance_change: float = 1e-9,
initial_inverse_hessian_estimate: Tensor | None = None,
line_search_fn: Literal['strong wolfe', 'Hager Zhang'] = 'strong_wolfe',
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
line_search_fn: Literal['strong wolfe', 'Hager Zhang'] = 'strong_wolfe',
line_search_fn: Literal['strong_wolfe'] = 'strong_wolfe',

tolerance_grad: float = 1e-8,
tolerance_change: float = 1e-8,
initial_inverse_hessian_estimate: Tensor | None = None,
line_search_fn: Literal['strong wolfe', 'Hager Zhang'] = 'strong wolfe',
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
line_search_fn: Literal['strong wolfe', 'Hager Zhang'] = 'strong wolfe',
line_search_fn: Literal['strong_wolfe'] = 'strong_wolfe',

tolerance_grad: float = 1e-7,
tolerance_change: float = 1e-9,
initial_inverse_hessian_estimate: Tensor | None = None,
line_search_fn: Literal['strong wolfe'] = 'strong_wolfe',
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
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 19 to 20
if TYPE_CHECKING:
from paddle import Tensor
Copy link
Member

@SigureMo SigureMo Aug 12, 2024

Choose a reason for hiding this comment

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

不要将 if TYPE_CHECKING: 块插在其它 import 中间

放在 23 行后

import numpy as np

import paddle

if TYPE_CHECKING:
Copy link
Member

Choose a reason for hiding this comment

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

同上


from typing import TYPE_CHECKING, Literal

if TYPE_CHECKING:
Copy link
Member

Choose a reason for hiding this comment

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

同上


from typing import TYPE_CHECKING

if TYPE_CHECKING:
Copy link
Member

Choose a reason for hiding this comment

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

同上

@SigureMo SigureMo changed the title [Typing][C-81,C-102,C-103,C-105] Add type annotations for fused_dropout_add.py, bfgs.py, lbfgs.py math.py [Typing][C-81,C-102,C-103,C-105] Add type annotations for {fused_dropout_add,bfgs,lbfgs,math}.py Aug 13, 2024
@SigureMo SigureMo changed the title [Typing][C-81,C-102,C-103,C-105] Add type annotations for {fused_dropout_add,bfgs,lbfgs,math}.py [Typing][C-81,C-102,C-103,C-105] Add type annotations for {fused_dropout_add,bfgs,lbfgs,math}.py for incubate APIs Aug 13, 2024
@SigureMo SigureMo changed the title [Typing][C-81,C-102,C-103,C-105] Add type annotations for {fused_dropout_add,bfgs,lbfgs,math}.py for incubate APIs [Typing][C-81,C-102,C-103,C-105] Add type annotations for {fused_dropout_add,bfgs,lbfgs,math}.py in incubate APIs Aug 13, 2024
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 a1d73ae into PaddlePaddle:develop Aug 13, 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