nvflare.app_common.np.recipes.lr.fedavg module
- class FedAvgLrRecipe(*, name: str = 'lr_fedavg', min_clients: int, num_rounds: int = 2, damping_factor=0.8, num_features=13, initial_ckpt: str | None = None, train_script: str, train_args: str = '', launch_external_process=False, command: str = 'python3 -u', client_memory_gc_rounds: int = 0, cuda_empty_cache: bool = False)[source]
Bases:
RecipeA recipe for implementing Federated Averaging (FedAvg) for Logistic Regression with Newton Raphson.
FedAvg is a fundamental federated learning algorithm that aggregates model updates from multiple clients by computing a weighted average based on the amount of local training data. This recipe sets up a complete federated learning workflow using the FedAvgLR controller specifically designed for logistic regression.
The recipe configures: - A federated job with logistic regression model - FedAvgLR controller for Newton-Raphson based aggregation - Script runners for client-side training execution
- Parameters:
name – Name of the federated learning job. Defaults to “lr_fedavg”.
min_clients – Minimum number of clients required to start a training round.
num_rounds – Number of federated training rounds to execute. Defaults to 2.
damping_factor – default to 0.8
num_features – Number of features for the logistic regression. Defaults to 13.
initial_ckpt – Absolute path to a pre-trained checkpoint file (.npy). The file may not exist locally as it could be on the server. Used to resume training from previously saved weights.
train_script – Path to the training script that will be executed on each client.
train_args – Command line arguments to pass to the training script.
launch_external_process (bool) – Whether to launch the script in external process. Defaults to False.
command (str) – If launch_external_process=True, command to run script (prepended to script). Defaults to “python3”.
Example
- ```python
- recipe = FedAvgLrRecipe(min_clients=2,
num_rounds=num_rounds, damping_factor=0.8, num_features=13, train_script=”client.py”, train_args=f”–data_root {data_root}”)
This is base class of a recipe. Recipes are implemented by jobs. A concrete recipe must provide the job for recipe implementation.
- Parameters:
job – the job that implements the recipe.