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

[Feature] Refactor FedRunner, optimize trainer module and optimize CI #415

Merged
merged 22 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
roll back optimizer
  • Loading branch information
rayrayraykk committed Oct 31, 2022
commit e1a0a327e247ec1517be5b96eadaccde58686f2a
2 changes: 1 addition & 1 deletion federatedscope/attack/privacy_attacks/passive_PIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _get_parameter_updates(self, model, previous_para, x_batch, y_batch):
# get last phase model parameters
model.load_state_dict(previous_para, strict=False)

optimizer = get_optimizer(opt_type=self.fl_type_optimizer,
optimizer = get_optimizer(type=self.fl_type_optimizer,
model=model,
lr=self.fl_lr)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def __init__(self,
batch_size=100)

# self.optimizer = get_optimizer(
# opt_type=self._cfg.fedopt.type_optimizer, model=self.model,
# type=self._cfg.fedopt.type_optimizer, model=self.model,
# lr=self._cfg.fedopt.optimizer.lr)
# print(self.optimizer)
def callback_funcs_model_para(self, message: Message):
Expand Down
18 changes: 9 additions & 9 deletions federatedscope/core/auxiliaries/optimizer_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
f'available.')


def get_optimizer(model, opt_type, lr, **kwargs):
def get_optimizer(model, type, lr, **kwargs):
"""
This function returns an instantiated optimizer to optimize the model.

Args:
model: model to be optimized
opt_type: type of optimizer, see \
type: type of optimizer, see \
https://pytorch.org/docs/stable/optim.html
lr: learning rate
**kwargs: kwargs dict
Expand All @@ -43,19 +43,19 @@ def get_optimizer(model, opt_type, lr, **kwargs):
del tmp_kwargs['is_ready_for_run']

for func in register.optimizer_dict.values():
optimizer = func(model, opt_type, lr, **tmp_kwargs)
optimizer = func(model, type, lr, **tmp_kwargs)
if optimizer is not None:
return optimizer

if isinstance(opt_type, str):
if hasattr(torch.optim, opt_type):
if isinstance(type, str):
if hasattr(torch.optim, type):
if isinstance(model, torch.nn.Module):
return getattr(torch.optim, opt_type)(model.parameters(), lr,
**tmp_kwargs)
return getattr(torch.optim, type)(model.parameters(), lr,
**tmp_kwargs)
else:
return getattr(torch.optim, opt_type)(model, lr, **tmp_kwargs)
return getattr(torch.optim, type)(model, lr, **tmp_kwargs)
else:
raise NotImplementedError(
'Optimizer {} not implement'.format(opt_type))
'Optimizer {} not implement'.format(type))
else:
raise TypeError()