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, compression=None)[source]ΒΆ
Bases:
objectP2PFL 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.
- Parameters:
params (
list[ndarray] |bytes|None)num_samples (
int|None)contributors (
list[str] |None)additional_info (
dict[str,Any] |None)compression (
dict[str,dict[str,Any]] |None)
- add_info(callback, info)[source]ΒΆ
Add additional information to the learner state.
- Parameters:
callback (
str) β The callback to add the informationinfo (
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:
- 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 (
list[ndarray] |None) β The parameters of the model.- Return type:
bytes
- 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 (
str|None) β The callback to add the informationkey β The key of the information.
- Return type:
Any
- 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 (
list[ndarray] |bytes) β The parameters of the model.- Raises:
ModelNotMatchingError β If parameters donβt match the model.
- Return type:
None