-
-
Notifications
You must be signed in to change notification settings - Fork 617
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
Paramscheduler emahandler #2326
Conversation
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 @fco-dv ! I left few comments
@@ -13,6 +15,9 @@ class StateParamScheduler(BaseParamScheduler): | |||
param_name: name of parameter to update. | |||
save_history: whether to log the parameter values to | |||
`engine.state.param_history`, (default=False). | |||
create_new: in case `param_name` already exists in `engine.state`, whether to authorize `StateParamScheduler` |
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.
@fco-dv please use double-ticks ```` instead of single-tick when addresses code. Here and above.
create_new: in case `param_name` already exists in `engine.state`, whether to authorize `StateParamScheduler` | |
create_new: in case ``param_name`` already exists in ``engine.state``, whether to authorize ``StateParamScheduler`` |
f"This may be a conflict between multiple StateParameterScheduler handlers." | ||
f"Please choose another name." | ||
) | ||
if not self.create_new: |
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.
I do not quite understand this if/else clauses, especially "else" one.
I was thinking about the following logic:
param_name
NOT inengine.state
AND create_new is True => simply create new attributeparam_name
NOT inengine.state
AND create_new is False => warn that we will create new attribute, but to remove this warning, create_new should be Trueparam_name
inengine.state
AND create_new is True => raise error as we can not create new attribute as it already exists in the state.param_name
inengine.state
AND create_new is False => silently override existing attribute
What do you think ?
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.
Oh yes , I've misunderstood the case 3, thought we were handling the creation of state parameter in that case ... So yes Indeed, it's better and simpler ! Thanks
Co-authored-by: vfdev <vfdev.5@gmail.com>
Co-authored-by: vfdev <vfdev.5@gmail.com>
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 update @fco-dv
Can you improve tests a bit. Thanks !
def test_param_scheduler_with_ema_handler_attach_exception(): | ||
import torch.nn as nn | ||
|
||
from ignite.handlers import EMAHandler | ||
|
||
data = torch.rand(100, 2) | ||
model = nn.Linear(2, 1) | ||
trainer = Engine(lambda e, b: model(b)) | ||
param_name = "ema_decay" | ||
save_history = True | ||
create_new = True | ||
|
||
ema_handler = EMAHandler(model) | ||
ema_handler.attach(trainer, name=param_name, event=Events.ITERATION_COMPLETED) | ||
ema_decay_scheduler = PiecewiseLinearStateScheduler( | ||
param_name=param_name, | ||
milestones_values=[(0, 0.0), (10 * len(data), 0.999)], | ||
save_history=save_history, | ||
create_new=create_new, | ||
) |
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.
I think you do not need to add EMAHandler to check ValueError
.
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.
Can we add a working test with EMAHandler and PiecewiseLinearStateScheduler like in the issue ?
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 sure , thanks for your comments @vfdev-5 !
* pytorch#2090 make work EMAHandler with StateParamScheduler * pytorch#2295 update docstring for parameter `create_new` * pytorch#2295 fixing attach method logic and update associated tests * pytorch#2295 fix unused import / remove useless test * pytorch#2295 fix tests * pytorch#2295 rm else statement * Update ignite/handlers/state_param_scheduler.py Co-authored-by: vfdev <vfdev.5@gmail.com> * Update ignite/handlers/state_param_scheduler.py Co-authored-by: vfdev <vfdev.5@gmail.com> * pytorch#2295 update tests assert messages * pytorch#2295 update tests, add working example with EMAHandler Co-authored-by: vfdev <vfdev.5@gmail.com>
* pytorch#2090 make work EMAHandler with StateParamScheduler * pytorch#2295 update docstring for parameter `create_new` * pytorch#2295 fixing attach method logic and update associated tests * pytorch#2295 fix unused import / remove useless test * pytorch#2295 fix tests * pytorch#2295 rm else statement * Update ignite/handlers/state_param_scheduler.py Co-authored-by: vfdev <vfdev.5@gmail.com> * Update ignite/handlers/state_param_scheduler.py Co-authored-by: vfdev <vfdev.5@gmail.com> * pytorch#2295 update tests assert messages * pytorch#2295 update tests, add working example with EMAHandler Co-authored-by: vfdev <vfdev.5@gmail.com>
Fixes #2295
Description:
Add
create_new
parameter toattach
method . This flag is used to createparam_name
onengine.state
and is taking into account whetherparam_name
attribute already exists or not onengine.state
. Overrides existing attribute by default.Check list: