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][A-44] Add type annotations for paddle/optimizer/lbfgs.py #65308

Merged
merged 10 commits into from
Jun 25, 2024

Conversation

enkilee
Copy link
Contributor

@enkilee enkilee commented Jun 20, 2024

PR Category

User Experience

PR Types

Improvements

Description

Copy link

paddle-bot bot commented Jun 20, 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.

@SigureMo SigureMo added the HappyOpenSource 快乐开源活动issue与PR label Jun 21, 2024
@SigureMo SigureMo self-assigned this Jun 21, 2024
Copy link
Contributor

@megemini megemini Jun 22, 2024

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 次,但是类里面的方法其实都需要修改 ~ 可以参考官网有哪些接口,宁缺勿漏 宁多勿漏 吧 ~ 🤟🤟🤟

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到

@@ -452,7 +462,7 @@ def __init__(

self._numel_cache = None

def state_dict(self):
def state_dict(self) -> dict[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

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

Choose a reason for hiding this comment

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

这个应该是 Tensor?

@@ -778,7 +788,7 @@ def obj_func(x, alpha, d):

def minimize(
self, loss, startup_program=None, parameters=None, no_grad_set=None
):
) -> Any:
Copy link
Member

Choose a reason for hiding this comment

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

用 NoReturn

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

Choose a reason for hiding this comment

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

我这里说的不是 NoReturn 吗?

Comment on lines 38 to 45
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]
Copy link
Member

Choose a reason for hiding this comment

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

再看看?这里不是这样的吧?

Comment on lines 38 to 48
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
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.

他这个是返回state的值吧?state里面打印出来这些参数

Copy link
Member

Choose a reason for hiding this comment

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

这也不是 state 里啊

__all__ = []


class _LbfgsStateDict(TypedDict):
state: str
packed_state: _LbfgsStateDict
Copy link
Member

Choose a reason for hiding this comment

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

image

啊?为什么会写成这样?我不能理解啊……

Copy link
Contributor Author

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的键的值

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 🐾

@SigureMo SigureMo merged commit cda661e into PaddlePaddle:develop Jun 25, 2024
32 of 34 checks passed
@enkilee enkilee deleted the typing-a44-lbfgs branch June 25, 2024 02:09
co63oc pushed a commit to co63oc/Paddle that referenced this pull request Jun 25, 2024
…addlePaddle#65308)


---------

Co-authored-by: SigureMo <sigure.qaq@gmail.com>
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.

3 participants