nvflare.app_common.aggregators package

Submodules

Module contents

class AccumulateWeightedAggregator(*args, **kwargs)[source]

Bases: InTimeAccumulateWeightedAggregator

Perform accumulated weighted aggregation.

This is often used as the default aggregation method and can be used for FedAvg. It parses the shareable and aggregates the contained DXO(s).

Parameters
  • exclude_vars (Union[str, Dict[str, str]], optional) – Regular expression string to match excluded vars during aggregation. Defaults to None. Can be one string or a dict of {dxo_name: regex strings} corresponding to each aggregated DXO when processing a DXO of DataKind.COLLECTION.

  • aggregation_weights (Union[Dict[str, Any], Dict[str, Dict[str, Any]]], optional) – Aggregation weight for each contributor. Defaults to None. Can be one dict of {contrib_name: aggr_weight} or a dict of dicts corresponding to each aggregated DXO when processing a DXO of DataKind.COLLECTION.

  • expected_data_kind (Union[DataKind, Dict[str, DataKind]]) – DataKind for DXO. Defaults to DataKind.WEIGHT_DIFF Can be one DataKind or a dict of {dxo_name: DataKind} corresponding to each aggregated DXO when processing a DXO of DataKind.COLLECTION. Only the keys in this dict will be processed.

class InTimeAccumulateWeightedAggregator(exclude_vars: Optional[Union[str, Dict[str, str]]] = None, aggregation_weights: Optional[Union[Dict[str, Any], Dict[str, Dict[str, Any]]]] = None, expected_data_kind: Union[DataKind, Dict[str, DataKind]] = 'WEIGHT_DIFF')[source]

Bases: Aggregator

Perform accumulated weighted aggregation.

This is often used as the default aggregation method and can be used for FedAvg. It parses the shareable and aggregates the contained DXO(s).

Parameters
  • exclude_vars (Union[str, Dict[str, str]], optional) – Regular expression string to match excluded vars during aggregation. Defaults to None. Can be one string or a dict of {dxo_name: regex strings} corresponding to each aggregated DXO when processing a DXO of DataKind.COLLECTION.

  • aggregation_weights (Union[Dict[str, Any], Dict[str, Dict[str, Any]]], optional) – Aggregation weight for each contributor. Defaults to None. Can be one dict of {contrib_name: aggr_weight} or a dict of dicts corresponding to each aggregated DXO when processing a DXO of DataKind.COLLECTION.

  • expected_data_kind (Union[DataKind, Dict[str, DataKind]]) – DataKind for DXO. Defaults to DataKind.WEIGHT_DIFF Can be one DataKind or a dict of {dxo_name: DataKind} corresponding to each aggregated DXO when processing a DXO of DataKind.COLLECTION. Only the keys in this dict will be processed.

accept(shareable: Shareable, fl_ctx: FLContext) bool[source]

Store shareable and update aggregator’s internal state

Parameters
  • shareable – information from contributor

  • fl_ctx – context provided by workflow

Returns

The first boolean indicates if this shareable is accepted. The second boolean indicates if aggregate can be called.

aggregate(fl_ctx: FLContext) Shareable[source]

Called when workflow determines to generate shareable to send back to contributors

Parameters

fl_ctx (FLContext) – context provided by workflow

Returns

the weighted mean of accepted shareables from contributors

Return type

Shareable