p2pfl.learning.aggregators.aggregator moduleΒΆ

Abstract aggregator.

class p2pfl.learning.aggregators.aggregator.Aggregator(node_name='unknown')[source]ΒΆ

Bases: object

Class to manage the aggregation of models.

Parameters:

node_name (str) – String with the name of the node.

add_model(model)[source]ΒΆ

Add a model. The first model to be added starts the run method (timeout).

Parameters:

model (P2PFLModel) – Model to add.

Return type:

List[str]

Returns:

List of contributors.

aggregate(models)[source]ΒΆ

Aggregate the models.

Parameters:

models (List[P2PFLModel]) – Dictionary with the models to aggregate.

Return type:

P2PFLModel

clear()[source]ΒΆ

Clear the aggregation (remove trainset and release locks).

Return type:

None

get_aggregated_models()[source]ΒΆ

Get the list of aggregated models.

Return type:

List[str]

Returns:

Name of nodes that colaborated to get the model.

get_missing_models()[source]ΒΆ

Obtain missing models for the aggregation.

Return type:

set

Returns:

A set of missing models.

get_model(except_nodes)[source]ΒΆ

Get corresponding aggregation depending if aggregator supports partial aggregations.

Parameters:

except_nodes – List of nodes to exclude from the aggregation.

Return type:

P2PFLModel

get_required_callbacks()[source]ΒΆ

Get the required callbacks for the aggregation.

Return type:

List[str]

Returns:

List of required callbacks.

set_nodes_to_aggregate(nodes_to_aggregate)[source]ΒΆ

List with the name of nodes to aggregate. Be careful, by setting new nodes, the actual aggregation will be lost.

Parameters:

nodes_to_aggregate (List[str]) – List of nodes to aggregate. Empty for no aggregation.

Raises:

Exception – If the aggregation is running.

Return type:

None

wait_and_get_aggregation(timeout=300)[source]ΒΆ

Wait for aggregation to finish.

Parameters:

timeout (int) – Timeout in seconds.

Return type:

P2PFLModel

Returns:

Aggregated model.

Raises:

Exception – If waiting for an aggregated model and several models were received.

exception p2pfl.learning.aggregators.aggregator.NoModelsToAggregateError[source]ΒΆ

Bases: Exception

Exception raised when there are no models to aggregate.