nvflare.app_opt.pt.job_config.fed_avg module

class FedAvgJob(initial_model: Module, n_clients: int, num_rounds: int, name: str = 'fed_job', min_clients: int = 1, mandatory_clients: List[str] | None = None, key_metric: str = 'accuracy', convert_to_fed_event: bool | ConvertToFedEvent | None = None, analytics_receiver: bool | ConvertToFedEvent | None = None)[source]

Bases: BaseFedJob

PyTorch FedAvg Job.

Configures server side FedAvg controller, persistor with initial model, and widgets.

User must add executors.

Parameters:
  • initial_model (nn.Module) – initial PyTorch Model

  • n_clients (int) – number of clients for this job

  • num_rounds (int) – number of rounds for FedAvg

  • name (name, 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], 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”.

  • convert_to_fed_event (Union[bool, ConvertToFedEvent, None]) – A component to convert certain events to fed events. If not provided, a ConvertToFedEvent object will be created and add to Client If provided, a ConvertToFedEvent object will be add to Client If set to True, a ConvertToFedEvent object will be created and add to Client If set to False, no ConvertToFedEvent will be created.

  • analytics_receiver (Union[bool, AnalyticsReceiver, None]) – A component to receive analytics. If not provided, a TBAnalyticsReceiver object will be created and add to seerver If provided, a AnalyticsReceiver object will be add to Server If set to True, a TBAnalyticsReceiver object will be created and add to seerver If set to False, no AnalyticsReceiver will be created.