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

feat(framework) Include default number of server rounds in templates #3821

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion src/py/flwr/cli/new/templates/app/code/server.hf.py.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ from flwr.server import ServerApp, ServerAppComponents, ServerConfig


def server_fn(context: Context):
# Read from config
num_rounds = int(context.run_config["num-server-rounds"])

# Define strategy
strategy = FedAvg(
fraction_fit=1.0,
fraction_evaluate=1.0,
)
config = ServerConfig(num_rounds=3)
config = ServerConfig(num_rounds=num_rounds)

return ServerAppComponents(strategy=strategy, config=config)

Expand Down
5 changes: 4 additions & 1 deletion src/py/flwr/cli/new/templates/app/code/server.jax.py.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ from flwr.server import ServerApp, ServerAppComponents, ServerConfig


def server_fn(context: Context):
# Read from config
num_rounds = int(context.run_config["num-server-rounds"])

# Define strategy
strategy = FedAvg()
config = ServerConfig(num_rounds=3)
config = ServerConfig(num_rounds=num_rounds)

return ServerAppComponents(strategy=strategy, config=config)

Expand Down
5 changes: 4 additions & 1 deletion src/py/flwr/cli/new/templates/app/code/server.mlx.py.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ from flwr.server.strategy import FedAvg


def server_fn(context: Context):
# Read from config
num_rounds = int(context.run_config["num-server-rounds"])

# Define strategy
strategy = FedAvg()
config = ServerConfig(num_rounds=3)
config = ServerConfig(num_rounds=num_rounds)

return ServerAppComponents(strategy=strategy, config=config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ from flwr.server.strategy import FedAvg


def server_fn(context: Context):
# Read from config
num_rounds = int(context.run_config["num-server-rounds"])

# Define strategy
strategy = FedAvg()
config = ServerConfig(num_rounds=3)
config = ServerConfig(num_rounds=num_rounds)

return ServerAppComponents(strategy=strategy, config=config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ ndarrays = get_weights(Net())
parameters = ndarrays_to_parameters(ndarrays)

def server_fn(context: Context):
# Read from config
num_rounds = int(context.run_config["num-server-rounds"])

# Define strategy
strategy = FedAvg(
fraction_fit=1.0,
fraction_evaluate=1.0,
min_available_clients=2,
initial_parameters=parameters,
)
config = ServerConfig(num_rounds=3)
config = ServerConfig(num_rounds=num_rounds)

return ServerAppComponents(strategy=strategy, config=config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ from flwr.server.strategy import FedAvg


def server_fn(context: Context):
# Read from config
num_rounds = int(context.run_config["num-server-rounds"])

# Define strategy
strategy = FedAvg(
fraction_fit=1.0,
fraction_evaluate=1.0,
min_available_clients=2,
)
config = ServerConfig(num_rounds=3)
config = ServerConfig(num_rounds=num_rounds)

return ServerAppComponents(strategy=strategy, config=config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ config = ServerConfig(num_rounds=3)
parameters = ndarrays_to_parameters(load_model().get_weights())

def server_fn(context: Context):
# Read from config
num_rounds = int(context.run_config["num-server-rounds"])

# Define strategy
strategy = strategy = FedAvg(
fraction_fit=1.0,
fraction_evaluate=1.0,
min_available_clients=2,
initial_parameters=parameters,
)
config = ServerConfig(num_rounds=3)
config = ServerConfig(num_rounds=num_rounds)

return ServerAppComponents(strategy=strategy, config=config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ publisher = "$username"
serverapp = "$import_name.app:server"
clientapp = "$import_name.app:client"

[tool.flwr.app.config]
num-server-rounds = "3"

[tool.flwr.federations]
default = "localhost"

Expand Down
3 changes: 3 additions & 0 deletions src/py/flwr/cli/new/templates/app/pyproject.hf.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ publisher = "$username"
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[tool.flwr.app.config]
num-server-rounds = "3"

[tool.flwr.federations]
default = "localhost"

Expand Down
3 changes: 3 additions & 0 deletions src/py/flwr/cli/new/templates/app/pyproject.jax.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ publisher = "$username"
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[tool.flwr.app.config]
num-server-rounds = "3"

[tool.flwr.federations]
default = "localhost"

Expand Down
3 changes: 3 additions & 0 deletions src/py/flwr/cli/new/templates/app/pyproject.mlx.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ publisher = "$username"
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[tool.flwr.app.config]
num-server-rounds = "3"

[tool.flwr.federations]
default = "localhost"

Expand Down
3 changes: 3 additions & 0 deletions src/py/flwr/cli/new/templates/app/pyproject.numpy.toml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ publisher = "$username"
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[tool.flwr.app.config]
num-server-rounds = "3"

[tool.flwr.federations]
default = "localhost"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ publisher = "$username"
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[tool.flwr.app.config]
num-server-rounds = "3"

[tool.flwr.federations]
default = "localhost"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ publisher = "$username"
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[tool.flwr.app.config]
num-server-rounds = "3"

[tool.flwr.federations]
default = "localhost"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ publisher = "$username"
serverapp = "$import_name.server:app"
clientapp = "$import_name.client:app"

[tool.flwr.app.config]
num-server-rounds = "3"

[tool.flwr.federations]
default = "localhost"

Expand Down