-
Notifications
You must be signed in to change notification settings - Fork 214
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
Support optimizers with different parameters #96
Conversation
I am wondering whether it is necessary to change the exposed parameters. To resolve this issue, why not just change the argument of |
what is your opinion? @DavdGao @rayrayraykk @yxdyc @xieyxclack |
Agreed, we could use a filter to pass the args:
This function can be applied to optimizers too. |
d7df661
to
7631c25
Compare
The solution is updated accordingly. |
The solution is updated accordingly. |
This configuring mechanism looks cool to me! Could you provide a test case for it? |
Thanks, the unittest is added. |
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, plz see the inline comments
dataset_name=self._cfg.data.type, | ||
fl_local_update_num=self._cfg.federate.local_update_steps, | ||
fl_type_optimizer=self._cfg.fedopt.type_optimizer, | ||
fl_type_optimizer=self._cfg.fedopt.optimizer.type, |
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.
Should we ensure forward compatibility? That is, both optimizer.grad_clip or grad.grad_clip are ok. Otherwise, we may have to exhaustively modify the historical codes to ensure that the previous experiments still work correctly
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.
- @yxdyc Thanks, I have checked the historical codes and make sure that all unittest works well.
- As for gradient clipping, since it is not a common parameter in general optimizers (like the learning rate), maybe we should consider it as an independent operation and separate it from the optimizer.
- Since we have set
cfg.optimizer = CN(new_allowed=True)
, our modification also supportsoptimizer.grad_clip
as a parameter for customized optimziers.
fl_lr=self._cfg.optimizer.lr, | ||
batch_size=100) | ||
|
||
# self.optimizer = get_optimizer(type=self._cfg.fedopt.type_optimizer, model=self.model,lr=self._cfg.fedopt.lr_server) | ||
# self.optimizer = get_optimizer(type=self._cfg.fedopt.type_optimizer, model=self.model,lr=self._cfg.fedopt.optimizer.lr) |
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.
The same problem as "optimizer.grad_clip vs. grad.grad_clip" above.
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
cfg.optimizer
andcfg.fedopt.optimizer
. :get_optimizer
is as followscfg.optimizer
as an example, the original config file is as followsnew_allowed=True
incfg.optimizer
, we allow the users to add new parameters according to the type of their optimizers. For example, if I want to use the optimizer registered asmyoptimizer
, as well as its new parametersmylr
andmynorm
. I just need to write the yaml file as follows, and the new parameters will be added automatically.