nvflare.app_opt.pt.job_config.base_fed_job module

class BaseFedJob(initial_model: Module | None = None, name: str = 'fed_job', min_clients: int = 1, mandatory_clients: List[str] | None = None, key_metric: str = 'accuracy', validation_json_generator: ValidationJsonGenerator | None = None, model_selector: FLComponent | None = None, convert_to_fed_event: ConvertToFedEvent | None = None, analytics_receiver: AnalyticsReceiver | None = None, model_persistor: ModelPersistor | None = None, model_locator: ModelLocator | None = None)[source]

Bases: BaseFedJob

PyTorch BaseFedJob.

This is a backward-compatible wrapper around the unified BaseFedJob.

Configures ValidationJsonGenerator, model selector, AnalyticsReceiver, ConvertToFedEvent.

User must add controllers and executors.

Parameters:
  • initial_model (nn.Module, optional) – Initial PyTorch model. Defaults to None.

  • name (str, optional) – name of the job. Defaults to “fed_job”.

  • min_clients (int, optional) – the minimum number of clients for the job. Defaults to 1.

  • mandatory_clients (list[str] | None, optional) – mandatory clients to run the job. Default None.

  • key_metric (str, optional) – Metric used to determine if the model is globally best. if metrics are a dict, key_metric can select the metric used for global model selection. Defaults to “accuracy”.

  • validation_json_generator (ValidationJsonGenerator | None, optional) – A component for generating validation results. if not provided, a ValidationJsonGenerator will be configured.

  • model_selector – (FLComponent | None, optional): A component for selecting the best model during training. This event-driven component evaluates and tracks model performance across training rounds, handling workflow events such as BEFORE_AGGREGATION and BEFORE_CONTRIBUTION_ACCEPT. If not provided, an IntimeModelSelector will be configured based on key_metric.

  • convert_to_fed_event – (ConvertToFedEvent | None, optional): A component to convert certain events to fed events. if not provided, a ConvertToFedEvent object will be created.

  • analytics_receiver (AnalyticsReceiver | None, optional) – Component for receiving analytics data. If not provided, no analytics tracking will be enabled. For experiment tracking (e.g., TensorBoard), explicitly pass a TBAnalyticsReceiver instance.

  • model_persistor (ModelPersistor | None, optional) – how to persist the model.

  • model_locator (ModelLocator | None, optional) – how to locate the model.

Unified BaseFedJob for PyTorch, TensorFlow, and Scikit-learn.

Configures ValidationJsonGenerator, model selector, AnalyticsReceiver, ConvertToFedEvent. Framework-specific model setup should be handled by child classes or calling code (recipes).

User must add controllers and executors.

Parameters:
  • name – Name of the job. Defaults to “fed_job”.

  • min_clients – The minimum number of clients for the job. Defaults to 1.

  • mandatory_clients – Mandatory clients to run the job. Default None.

  • key_metric – Metric used to determine if the model is globally best. If metrics are a dict, key_metric can select the metric used for global model selection. Defaults to “accuracy”. Only used if model_selector is not provided.

  • validation_json_generator – A component for generating validation results. If not provided, a ValidationJsonGenerator will be configured.

  • model_selector

    A component for selecting the best model during training. This event-driven component evaluates and tracks model performance across training rounds, determining which model is globally best based on validation metrics. It handles workflow events such as BEFORE_AGGREGATION and BEFORE_CONTRIBUTION_ACCEPT. Common implementations:

    • IntimeModelSelector: selects based on a specified key metric

    • SimpleIntimeModelSelector: simplified version for basic selection

    If not provided and key_metric is specified, an IntimeModelSelector will be configured automatically.

  • convert_to_fed_event – A component to convert certain events to fed events. If not provided, a ConvertToFedEvent object will be created.

  • analytics_receiver – Receive analytics. If not provided, framework-specific child classes may provide defaults (e.g., TBAnalyticsReceiver for PT/TF).