-
-
Notifications
You must be signed in to change notification settings - Fork 620
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
Make metrics serializable #3001
Make metrics serializable #3001
Conversation
Shall I add |
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.
Thanks for the PR @sadra-barikbin !
The approach looks OK to me, let's update all metrics.
…ble' into Feature-make-metrics-serializable
|
||
to_save = {'trainer': trainer, 'model': model, 'optimizer': optimizer, 'lr_scheduler': lr_scheduler} | ||
to_save = {'trainer': trainer, 'model': model, 'optimizer': optimizer, 'lr_scheduler': lr_scheduler, 'metric': metric} |
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.
Ideally, we would like to get that in a more automatic way. Also if we want to save multiple metrics adding them one by one to save/load can be a pain.
Let's propose something in a follow-up 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.
Could you please reiterate what you mean? If we have multiple metrics, is it cumbersome to do:
to_save = {..., 'metric1': metric1, 'metric2': metric2, 'metric3': metric3}
?
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.
Yes, it is too verbose, let's try to find a way to simplify that.
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, thanks @sadra-barikbin
@@ -87,6 +87,9 @@ def log_running_avg_metrics(): | |||
""" | |||
|
|||
required_output_keys = None | |||
# TODO Shall we put `src` here? Then we should add a new branch for metric-typed attributes in `state_dict` | |||
# and `load_state_dict`. Examples; This class; `Rouge` which has a `List[_BaseRouge]`. | |||
_state_dict_all_req_keys = ("_value",) |
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.
@vfdev-5 , What's your thoughts on this?
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.
Let's add src
and in state_dict/load_state_dict put an explicit check for isinstance(attr, Metric)
and call state[attr_name].update(attr.state_dict)
or something like that.
Do you have any other options ?
Fixes #2999