-
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][A-44] Add type annotations for paddle/optimizer/lbfgs.py
#65308
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.
还有几个 api 别漏了哈 ~ state_dict
step
minimize
~~~
咱们这次主要是关注 公开 api
,重点关注不以 _
开头的那些函数或者方法 ~
另外,ISSUE 里面统计的每个文件中 api 数量可能不准,比如,有的是一个类,只统计了 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.
收到
…into typing-a44-lbfgs
python/paddle/optimizer/lbfgs.py
Outdated
@@ -452,7 +462,7 @@ def __init__( | |||
|
|||
self._numel_cache = None | |||
|
|||
def state_dict(self): | |||
def state_dict(self) -> dict[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
python/paddle/optimizer/lbfgs.py
Outdated
@@ -553,7 +563,7 @@ def _directional_evaluate(self, closure, x, alpha, d): | |||
return loss, flat_grad | |||
|
|||
@framework.non_static_only | |||
def step(self, closure): | |||
def step(self, closure) -> 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.
这个应该是 Tensor?
python/paddle/optimizer/lbfgs.py
Outdated
@@ -778,7 +788,7 @@ def obj_func(x, alpha, d): | |||
|
|||
def minimize( | |||
self, loss, startup_program=None, parameters=None, no_grad_set=None | |||
): | |||
) -> 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.
用 NoReturn
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.
我这里说的不是 NoReturn
吗?
python/paddle/optimizer/lbfgs.py
Outdated
class _LbfgsStateDict(TypedDict): | ||
learning_rate: float | ||
max_iter: int | ||
max_eval: NotRequired[int] | ||
tolerance_grad: float | ||
tolerance_change: float | ||
history_size: int | ||
line_search_fn: NotRequired[str] |
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.
再看看?这里不是这样的吧?
python/paddle/optimizer/lbfgs.py
Outdated
func_evals: int | ||
n_iter: int | ||
d: Tensor | ||
alpha: int | ||
old_yk: list[Tensor] | ||
old_sk: list[Tensor] | ||
ro: Tensor | ||
H_diag: Tensor | ||
prev_flat_grad: Tensor | ||
prev_loss: float | ||
al: 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.
会有这些么?
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.
他这个是返回state的值吧?state里面打印出来这些参数
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.
这也不是 state 里啊
python/paddle/optimizer/lbfgs.py
Outdated
__all__ = [] | ||
|
||
|
||
class _LbfgsStateDict(TypedDict): | ||
state: str | ||
packed_state: _LbfgsStateDict |
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.
啊哈哈,我没看明白,他代码返回的是dict,然后dict里面给了键 state, 和state对应的dict的键的值
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.
…addlePaddle#65308) --------- Co-authored-by: SigureMo <sigure.qaq@gmail.com>
PR Category
User Experience
PR Types
Improvements
Description
A44