fedn.network.combiner.aggregators package

The aggregator package is responsible for aggregating models from multiple clients. It’s called both in fedn.network.combiner.Combiner and fedn.network.controller.Controller to aggregate models from clients.

Submodules

fedn.network.combiner.aggregators.aggregatorbase module

class fedn.network.combiner.aggregators.aggregatorbase.AggregatorBase(storage, server, modelservice, control)[source]

Bases: ABC

Abstract class defining an aggregator.

Parameters:
  • id (str) – A reference to id of :class: fedn.network.combiner.Combiner

  • storage (class: fedn.common.storage.s3.s3repo.S3ModelRepository) – Model repository for :class: fedn.network.combiner.Combiner

  • server (class: fedn.network.combiner.Combiner) – A handle to the Combiner class :class: fedn.network.combiner.Combiner

  • modelservice (class: fedn.network.combiner.modelservice.ModelService) – A handle to the model service :class: fedn.network.combiner.modelservice.ModelService

  • control (class: fedn.network.combiner.round.RoundController) – A handle to the :class: fedn.network.combiner.round.RoundController

abstract combine_models(nr_expected_models=None, nr_required_models=1, helper=None, timeout=180, delete_models=True)[source]

Routine for combining model updates. Implemented in subclass.

Parameters:
  • nr_expected_models (int) – Number of expected models. If None, wait for all models.

  • nr_required_models (int) – Number of required models to combine.

  • helper – A helper object.

  • timeout (int) – Timeout in seconds to wait for models to be combined.

  • delete_models (bool) – Delete client models after combining.

Returns:

A combined model.

get_state()[source]

Get the state of the aggregator’s queue, including the number of model updates.

next_model_update(helper)[source]

Get the next model update from the queue.

Parameters:

helper (object) – A helper object.

Returns:

A tuple containing the model update, metadata and model id.

Return type:

tuple

on_model_update(model_update)[source]
Callback when a new client model update is recieved.

Performs (optional) pre-processing and then puts the update id on the aggregation queue. Override in subclass as needed.

Parameters:

model_update – A ModelUpdate message.

fedn.network.combiner.aggregators.aggregatorbase.get_aggregator(aggregator_module_name, storage, server, modelservice, control)[source]

Return an instance of the helper class.

Parameters:
  • helper_module_name (str) – The name of the helper plugin module.

  • storage (class: fedn.common.storage.s3.s3repo.S3ModelRepository) – Model repository for :class: fedn.network.combiner.Combiner

  • server (class: fedn.network.combiner.Combiner) – A handle to the Combiner class :class: fedn.network.combiner.Combiner

  • modelservice (class: fedn.network.combiner.modelservice.ModelService) – A handle to the model service :class: fedn.network.combiner.modelservice.ModelService

  • control (class: fedn.network.combiner.round.RoundController) – A handle to the :class: fedn.network.combiner.round.RoundController

Returns:

An aggregator instance.

Return type:

class: fedn.combiner.aggregators.AggregatorBase

fedn.network.combiner.aggregators.fedavg module

class fedn.network.combiner.aggregators.fedavg.Aggregator(storage, server, modelservice, control)[source]

Bases: AggregatorBase

Local SGD / Federated Averaging (FedAvg) aggregator. Computes a weighted mean

of parameter updates.

Parameters:
  • id (str) – A reference to id of :class: fedn.network.combiner.Combiner

  • storage (class: fedn.common.storage.s3.s3repo.S3ModelRepository) – Model repository for :class: fedn.network.combiner.Combiner

  • server (class: fedn.network.combiner.Combiner) – A handle to the Combiner class :class: fedn.network.combiner.Combiner

  • modelservice (class: fedn.network.combiner.modelservice.ModelService) – A handle to the model service :class: fedn.network.combiner.modelservice.ModelService

  • control (class: fedn.network.combiner.round.RoundController) – A handle to the :class: fedn.network.combiner.round.RoundController

combine_models(helper=None, time_window=180, max_nr_models=100, delete_models=True)[source]
Aggregate model updates in the queue by computing an incremental

weighted average of parameters.

Parameters:
  • helper (class: fedn.utils.helpers.HelperBase, optional) – An instance of :class: fedn.utils.helpers.HelperBase, ML framework specific helper, defaults to None

  • time_window (int, optional) – The time window for model aggregation, defaults to 180

  • max_nr_models (int, optional) – The maximum number of updates aggregated, defaults to 100

  • delete_models (bool, optional) – Delete models from storage after aggregation, defaults to True

Returns:

The global model and metadata

Return type:

tuple