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.
Recipe parameters become part of the generated job definition and must never contain actual secret values. Read secrets from site environment variables or mounted files; references are supported only where documented in
nvflare.recipe.secrets.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.
- Security contract – no secrets in recipe parameters:
Recipe parameters (
train_args,task_args,eval_args,per_site_config, config overrides, dicts passed toadd_client_config/add_server_config, exec params, etc.) can be written in clear text into generated job configuration. These parameters and their nested values must never contain actual passwords, API keys, tokens, private keys, or other credentials. Instead, read secrets from site environment variables or mounted secret files inside your code, or pass a placeholder created withnvflare.recipe.secrets.secret_ref()ornvflare.recipe.secrets.secret_file_ref()at a supported runtime boundary. Seenvflare.recipe.secretsfor the supported parameter locations.Before export or run, recipes scan their parameters with heuristics and emit
nvflare.recipe.secrets.PotentialSecretWarningwhen a value looks like an actual secret. The scan is best-effort: absence of a warning does not prove a parameter is safe to share.
- Parameters:
job – the job that implements the recipe.