nvflare.app_opt.pt.recipes.cyclic module

class CyclicRecipe(*, name: str = 'cyclic', model: Any | dict[str, Any] | None = None, initial_ckpt: str | None = None, num_rounds: int = 2, min_clients: int = 2, train_script: str, train_args: str = '', launch_external_process: bool = False, command: str = 'python3 -u', framework: FrameworkType = FrameworkType.PYTORCH, server_expected_format: ExchangeFormat = ExchangeFormat.NUMPY, params_transfer_type: TransferType = TransferType.FULL, server_memory_gc_rounds: int = 1, client_memory_gc_rounds: int = 0, cuda_empty_cache: bool = False, task_assignment_timeout: int = 10, shutdown_timeout: float = 0.0, server_config_overrides: Dict[str, Any] | None = None, client_config_overrides: Dict[str, Any] | None = None)[source]

Bases: CyclicRecipe

PyTorch-specific Cyclic federated learning recipe.

Recipe parameters, including train_args and config override dictionaries, 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.

Parameters:
  • name – Name identifier for the federated learning job. Defaults to “cyclic”.

  • model – Starting model object to begin training. Can be: - nn.Module instance - Dict config: {“path”: “module.ClassName”, “args”: {“param”: value}} - PTModel instance (already wrapped) - None: no initial model

  • initial_ckpt – Path to a pre-trained checkpoint file. Can be: - Relative path: file will be bundled into the job’s custom/ directory. - Absolute path: treated as a server-side path, used as-is at runtime. Note: PyTorch requires model when using initial_ckpt (for architecture).

  • num_rounds – Number of complete training rounds to execute. Defaults to 2.

  • min_clients – Minimum number of clients required to participate. Must be >= 2.

  • train_script – Path to the client training script to execute.

  • train_args – Additional command-line arguments to pass to the training script.

  • launch_external_process – Whether to run training in a separate process. Defaults to False.

  • command – Shell command to execute the training script. Defaults to “python3 -u”.

  • framework – ML framework type for compatibility. Defaults to FrameworkType.PYTORCH.

  • server_expected_format – Data exchange format between server and clients.

  • params_transfer_type – Method for transferring model parameters.

  • server_memory_gc_rounds – Run memory cleanup every N rounds on server. Defaults to 1.

  • task_assignment_timeout – Seconds to wait for the assigned client to request its task.

  • shutdown_timeout – Seconds to wait for an external client process during shutdown.

  • server_config_overrides – Advanced shallow overrides for the server controller.

  • client_config_overrides – Advanced shallow overrides for the client script runner.

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 to add_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 with nvflare.recipe.secrets.secret_ref() or nvflare.recipe.secrets.secret_file_ref() at a supported runtime boundary. See nvflare.recipe.secrets for the supported parameter locations.

Before export or run, recipes scan their parameters with heuristics and emit nvflare.recipe.secrets.PotentialSecretWarning when 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.