CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Typing][A-96, B-43] Add type annotations for python/paddle/hapi/callbacks.py
, python/paddle/framework/framework.py
#65777
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
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.
python/paddle/hapi/callbacks.py
Outdated
) -> CallbackList: | ||
_cbks = callbacks or [] | ||
cbks: list[Callback] = list( | ||
_cbks if isinstance(_cbks, Sequence) else [_cbks] |
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.
(list, tuple)
不等于 Sequence
,如:
In [1]: from typing import Sequence
In [2]: a = 'asdfads'
In [3]: isinstance(a, Sequence)
Out[3]: True
python/paddle/hapi/callbacks.py
Outdated
self._check_mode(mode) | ||
name = f'on_{mode}_end' | ||
self._call(name, logs) | ||
|
||
def on_epoch_begin(self, epoch=None, logs=None): | ||
def on_epoch_begin( | ||
self, epoch=None, logs: _CallbackLogs | None = None |
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.
epoch ?
python/paddle/hapi/callbacks.py
Outdated
self._call('on_epoch_begin', epoch, logs) | ||
|
||
def on_epoch_end(self, epoch=None, logs=None): | ||
def on_epoch_end( | ||
self, epoch=None, logs: _CallbackLogs | None = None |
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.
epoch ?
logs = logs or {} | ||
self.train_step += 1 | ||
|
||
if self._is_write(): | ||
self._updates(logs, 'train') | ||
|
||
def on_eval_begin(self, logs=None): | ||
def on_eval_begin(self, logs: _CallbackLogs | None = None) -> None: |
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.
参考下面的代码:
self.eval_steps = logs.get('steps', None)
self.eval_metrics = logs.get('metrics', [])
class _CallbackLogs(TypedDict):
loss: float
metrics: list[float]
batch_size: int
跟定义不符?
python/paddle/hapi/callbacks.py
Outdated
|
||
class _CallbackLogs(TypedDict): | ||
loss: float | ||
metrics: list[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.
如:
def on_eval_begin(self, logs=None):
"""Called at the start of evaluation.
Args:
logs (dict): The logs is a dict or None. The keys of logs
passed by paddle.Model contains 'steps' and 'metrics',
The `steps` is number of total steps of validation dataset.
The `metrics` is a list of str including 'loss' and the names
of paddle.metric.Metric.
"""
list[str]
?
python/paddle/hapi/callbacks.py
Outdated
self.save_freq = save_freq | ||
self.save_dir = save_dir | ||
|
||
def on_epoch_begin(self, epoch=None, logs=None): | ||
def on_epoch_begin( | ||
self, epoch=None, logs: _CallbackLogs | None = None |
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.
epoch ?
python/paddle/hapi/callbacks.py
Outdated
@@ -69,60 +93,80 @@ def config_callbacks( | |||
|
|||
|
|||
class CallbackList: | |||
def __init__(self, callbacks=None): | |||
def __init__(self, callbacks: Sequence[Callback] | None = None): |
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, callbacks: Sequence[Callback] | None = None): | |
def __init__(self, callbacks: Sequence[Callback] | None = None) -> None: |
python/paddle/hapi/callbacks.py
Outdated
self.callbacks: list[Callback] = ( | ||
list(callbacks) if isinstance(callbacks, Sequence) else [] | ||
) |
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/hapi/callbacks.py
Outdated
verbose: int | ||
log_freq: int | ||
|
||
def __init__(self, log_freq: int = 1, verbose: int = 2): |
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, log_freq: int = 1, verbose: int = 2): | |
def __init__(self, log_freq: int = 1, verbose: int = 2) -> None: |
PR Category
User Experience
PR Types
Improvements
Description
类型标注:
python/paddle/hapi/callbacks.py
python/paddle/framework/framework.py
Related links
@SigureMo @megemini