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

Set initial_parameters as non-optional for FedAvgM (#2369) #2416

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

DanielCardeal
Copy link

Issue

#2369

Description

The constructor parameter initial_parameters of the FedAvgM strategy is typed as Optional, but is required whenever server-side optimization is enabled. This can be misleading, since server-side optimization is enabled "automatically" and in a non-transparent way.

Related issues/PRs

Proposal

Change type of intial_parameters from Optional[Parameters] to Parameters in FedAvgM. Also, documents which conditions must be met for server-side optimization to be enabled.

Explanation

This change aims to better communicate to users the necessity of initial_parameters in case of server-side optimization, as well as expose which conditions must be met to enable server-side optimization.

Checklist

  • Implement proposed change
  • Write tests
  • Update documentation
  • Update changelog
  • Make CI checks pass
  • Ping maintainers on Slack (channel #contributions)

Any other comments?

@jafermarq
Copy link
Contributor

jafermarq commented Sep 22, 2023

Hey @DanielCardeal, thanks for helping with the issue! The proposed change sounds reasonable. Would it make sense to keep it as optional and, in the first round, override the configure_fit() to initialise a local copy of the global parameters? (for context, when the initial_parameters are not set, the sever will sample one random client for its model parameters and those will become the initial state of the global model.)

I presume it's easier for people to not worry with the conversion of their model (e.g. PyTorch) to the parameters type when instantiating their strategy. I think this is more user-friendly. On the other hand, the solution you propose seems cleaner.

Any thoughts on this @danieljanes @charlesbvll @adam-narozniak @panh99 @gubertoli

@gubertoli
Copy link
Contributor

@jafermarq, I aggree that from a user perspective retrieving the parameters from a random client would be much easier.

If possible (probably as a new issue) doing the same for FedOpt would also be great. Initializing these parameters is a recurrent question in Slack.

@DanielCardeal
Copy link
Author

DanielCardeal commented Sep 23, 2023

@jafermarq @gubertoli Great idea!

I will try to add this changes in the the next couple of days :)

This change aims to better communicate to users the necessity of
`initial_parameters` in case of server-side optimization, as well as
expose which conditions must be met to enable server-side optimization.
This change makes so that FedAvgM uses the sampled global parameters of
the server when no `initial_parameters` are passed in the constructor.
@adam-narozniak
Copy link
Member

Hi, great catch. I'm in favor of @jafermarq 's idea.

I think we should also add a warning saying if at least one of the default values for momentum_vector or server_learning_rate is not changed, then it is just a vanilla FedAvg running. I think this will help the users to understand that aspect too.

@DanielCardeal
Copy link
Author

Hi

I added the following changes to the PR:

  • Automatic initialization of intial_parameters using the global model
  • Warn users when either server_momentum and server_learning_rate are set to default values and server side optimization is disabled.

Are there any further changes that need to be implemented?

@jafermarq jafermarq self-assigned this Nov 16, 2023
Copy link
Contributor

@jafermarq jafermarq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @DanielCardeal,

just a minor comment. I think we still want to not force users to pass initial_parameters.

I like the WARNING_NO_SERVER_OPT message you wrote to alert users. Do we want it to be displayed right upon strategy instantiation? Maybe yes? thoughts @adam-narozniak @danieljanes
It looks something like the below:

python run.py
WARNING flwr 2023-11-16 16:11:34,348 | fedavgm.py:132 | 
Setting both `server_momentum` and `server_learning_rate` to default values
cause FedAvgM to work as a vanilla FedAvg strategy. Server optimization with
momentum is enabled if either `server_momentum` is set to a value greater than
0.0 or `server_learning_rate` is set to a value lower than 1.0.

INFO flwr 2023-11-16 16:11:34,349 | app.py:178 | Starting Flower simulation, config: ...
....

src/py/flwr/server/strategy/fedavgm.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants