p2pfl.learning.frameworks.flax.flax_model moduleΒΆ

Flax Model for P2PFL.

class p2pfl.learning.frameworks.flax.flax_model.FlaxModel(model, init_params, params=None, num_samples=None, contributors=None, additional_info=None, compression=None)[source]ΒΆ

Bases: P2PFLModel

P2PFL model abstraction for Flax.

Parameters:
  • model (Module)

  • init_params (dict[str, Any])

  • 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)

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 (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_parameters()[source]ΒΆ

Get the parameters of the model.

Return type:

list[ndarray]

Returns:

The parameters of the model as a list of NumPy arrays.

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