nvflare.recipe.fed_task module
- class FedTaskRecipe(*, name: str = 'fed_task', task_name: str = 'task', min_clients: int, num_clients: int | None = None, min_responses: int | None = None, timeout: int = 0, task_data: dict | None = None, task_meta: dict | None = None, task_script: str, task_args: str = '', launch_external_process: bool = False, command: str = 'python3 -u', framework: FrameworkType = FrameworkType.RAW, server_expected_format: ExchangeFormat = ExchangeFormat.RAW, params_transfer_type: TransferType = TransferType.FULL, launch_once: bool = True, shutdown_timeout: float = 0.0, client_memory_gc_rounds: int = 0, cuda_empty_cache: bool = False)[source]
Bases:
RecipeA model-free recipe for running one federated task on participating clients.
This recipe is intended for one-round workflows that do not have a global model lifecycle, such as embedding extraction, preprocessing, feature generation, local evaluation, or other client-side jobs coordinated by the server.
Users are responsible for ensuring that
task_scriptaccepts the suppliedtask_argsand anytask_dataortask_metapayloads it consumes.- Parameters:
name – Name of the federated job. Defaults to “fed_task”.
task_name – Name of the task sent to clients. Defaults to “task”.
min_clients – Minimum number of clients required to start the job.
num_clients – Number of clients to sample for the task. If None, all available clients are used.
min_responses – Minimum number of task results to wait for. If None, waits for all selected clients.
timeout – Task timeout in seconds. Defaults to 0, meaning no timeout.
task_data – Optional params dict sent to each client as
FLModel.params.task_meta – Optional metadata dict sent to each client as
FLModel.meta.task_script – Path to the client script.
task_args – Command line arguments passed to the client script.
launch_external_process – Whether to launch the script in an external process.
command – Command used when
launch_external_processis True.framework – Framework used by
ScriptRunnerfor parameter exchange. Defaults to RAW.server_expected_format – Server-side expected parameter format. Defaults to RAW.
params_transfer_type – Parameter transfer type. Defaults to FULL.
launch_once – Whether an external process is launched once for the whole job.
shutdown_timeout – Seconds to wait before external process shutdown.
client_memory_gc_rounds – Run client memory cleanup every N rounds. Set 0 to disable.
cuda_empty_cache – Whether client memory cleanup also empties the CUDA cache.
Example
>>> from nvflare.recipe import FedTaskRecipe, SimEnv >>> >>> recipe = FedTaskRecipe( ... name="extract_embeddings", ... task_name="embed", ... min_clients=2, ... task_script="client.py", ... task_args="--data-root /data --out /tmp/embeddings", ... ) >>> run = recipe.execute(SimEnv(num_clients=2))
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.