p2pfl.learning.frameworks.p2pfl_model moduleΒΆ

P2PFL model abstraction.

class p2pfl.learning.frameworks.p2pfl_model.P2PFLModel(model, params=None, num_samples=None, contributors=None, additional_info=None)[source]ΒΆ

Bases: object

P2PFL model abstraction.

This class encapsulates the different models across all the possible frameworks.

The key concept is the extraction of the model weights in a common format for all the frameworks.

Parameters:

model (Any) – The model to encapsulate.

:: note :: The model type is ANY because the different frameworks do not share a common model type.

add_info(callback, info)[source]ΒΆ

Add additional information to the learner state.

Parameters:
  • callback (str) – The callback to add the information

  • info (Any) – The information for the callback.

Return type:

None

build_copy(**kwargs)[source]ΒΆ

Build a copy of the model.

Parameters:

**kwargs – Parameters of the model initialization.

Return type:

P2PFLModel

Returns:

A copy of the model.

decode_parameters(data)[source]ΒΆ

Decode the parameters of the model.

Parameters:

data (bytes) – The parameters of the model.

Return type:

Tuple[List[ndarray], Dict[str, Any]]

encode_parameters(params=None)[source]ΒΆ

Encode the parameters of the model.

Parameters:

params (Optional[List[ndarray]]) – The parameters of the model.

Return type:

bytes

get_contributors()[source]ΒΆ

Get the contributors of the model.

Return type:

List[str]

get_framework()[source]ΒΆ

Retrieve the model framework name.

Return type:

str

Returns:

The name of the model framework.

get_info(callback=None)[source]ΒΆ

Get additional information from the learner state.

Parameters:
  • callback (Optional[str]) – The callback to add the information

  • key – The key of the information.

Return type:

Any

get_model()[source]ΒΆ

Get the model.

Return type:

Any

get_num_samples()[source]ΒΆ

Get the number of samples used to train this model.

Return type:

int

get_parameters()[source]ΒΆ

Get the parameters of the model.

Return type:

List[ndarray]

Returns:

The parameters of the model

set_contribution(contributors, num_samples)[source]ΒΆ

Set the contribution of the model.

Parameters:
  • contributors (List[str]) – The contributors of the model.

  • num_samples (int) – The number of samples used to train this model.

Return type:

None

set_parameters(params)[source]ΒΆ

Set the parameters of the model.

Parameters:

params (Union[List[ndarray], bytes]) – The parameters of the model.

Raises:

ModelNotMatchingError – If parameters don’t match the model.

Return type:

None