-
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-81,C-102,C-103,C-105] Add type annotations for {fused_dropout_add,bfgs,lbfgs,math}.py
in incubate APIs
#67233
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
def __init__(self, p=0.5, mode="upscale_in_train", name=None): | ||
def __init__( | ||
self, | ||
p: int = 0.5, |
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.
???
def __init__( | ||
self, | ||
p: int = 0.5, | ||
mode: str = "upscale_in_train", |
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.
用 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 |
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.
从 collections.abc
导入 Callable
dtype='float32', | ||
name=None, | ||
): | ||
objective_func: Callable[[Tensor], float], |
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.
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', |
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.
Literal
line_search_fn: str = 'strong_wolfe', | ||
max_line_search_iters: int = 50, | ||
initial_step_length: float = 1.0, | ||
dtype: str = 'float32', |
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.
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 |
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.
同上
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]: |
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.
同上
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', |
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.
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', |
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.
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', |
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.
LGTM ~
if TYPE_CHECKING: | ||
from paddle import Tensor |
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.
不要将 if TYPE_CHECKING:
块插在其它 import 中间
放在 23 行后
import numpy as np | ||
|
||
import paddle | ||
|
||
if TYPE_CHECKING: |
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.
同上
|
||
from typing import TYPE_CHECKING, Literal | ||
|
||
if TYPE_CHECKING: |
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.
同上
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: |
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.
同上
fused_dropout_add.py, bfgs.py, lbfgs.py math.py
{fused_dropout_add,bfgs,lbfgs,math}.py
{fused_dropout_add,bfgs,lbfgs,math}.py
{fused_dropout_add,bfgs,lbfgs,math}.py
for incubate APIs
{fused_dropout_add,bfgs,lbfgs,math}.py
for incubate APIs{fused_dropout_add,bfgs,lbfgs,math}.py
in incubate APIs
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.
PR Category
User Experience
PR Types
Improvements
Description
#65008
尝试添加函数类型信息
但有一个问题,scalar该如何标注,我这里是用的float。