NumPyClient#

class NumPyClient[source]#

Bases: ABC

Abstract base class for Flower clients using NumPy.

Methods

evaluate(parameters, config)

Evaluate the provided parameters using the locally held dataset.

fit(parameters, config)

Train the provided parameters using the locally held dataset.

get_context()

Get the run context from this client.

get_parameters(config)

Return the current local model parameters.

get_properties(config)

Return a client's set of properties.

set_context(context)

Apply a run context to this client.

to_client()

Convert to object to Client type and return it.

Attributes

context

evaluate(parameters: List[ndarray[Any, dtype[Any]]], config: Dict[str, bool | bytes | float | int | str]) Tuple[float, int, Dict[str, bool | bytes | float | int | str]][source]#

Evaluate the provided parameters using the locally held dataset.

Parameters:
  • parameters (NDArrays) – The current (global) model parameters.

  • config (Dict[str, Scalar]) – Configuration parameters which allow the server to influence evaluation on the client. It can be used to communicate arbitrary values from the server to the client, for example, to influence the number of examples used for evaluation.

Returns:

  • loss (float) – The evaluation loss of the model on the local dataset.

  • num_examples (int) – The number of examples used for evaluation.

  • metrics (Dict[str, Scalar]) – A dictionary mapping arbitrary string keys to values of type bool, bytes, float, int, or str. It can be used to communicate arbitrary values back to the server.

Warning

The previous return type format (int, float, float) and the extended format (int, float, float, Dict[str, Scalar]) have been deprecated and removed since Flower 0.19.

fit(parameters: List[ndarray[Any, dtype[Any]]], config: Dict[str, bool | bytes | float | int | str]) Tuple[List[ndarray[Any, dtype[Any]]], int, Dict[str, bool | bytes | float | int | str]][source]#

Train the provided parameters using the locally held dataset.

Parameters:
  • parameters (NDArrays) – The current (global) model parameters.

  • config (Dict[str, Scalar]) – Configuration parameters which allow the server to influence training on the client. It can be used to communicate arbitrary values from the server to the client, for example, to set the number of (local) training epochs.

Returns:

  • parameters (NDArrays) – The locally updated model parameters.

  • num_examples (int) – The number of examples used for training.

  • metrics (Dict[str, Scalar]) – A dictionary mapping arbitrary string keys to values of type bool, bytes, float, int, or str. It can be used to communicate arbitrary values back to the server.

get_context() Context[source]#

Get the run context from this client.

get_parameters(config: Dict[str, bool | bytes | float | int | str]) List[ndarray[Any, dtype[Any]]][source]#

Return the current local model parameters.

Parameters:

config (Config) – Configuration parameters requested by the server. This can be used to tell the client which parameters are needed along with some Scalar attributes.

Returns:

parameters – The local model parameters as a list of NumPy ndarrays.

Return type:

NDArrays

get_properties(config: Dict[str, bool | bytes | float | int | str]) Dict[str, bool | bytes | float | int | str][source]#

Return a client’s set of properties.

Parameters:

config (Config) – Configuration parameters requested by the server. This can be used to tell the client which properties are needed along with some Scalar attributes.

Returns:

properties – A dictionary mapping arbitrary string keys to values of type bool, bytes, float, int, or str. It can be used to communicate arbitrary property values back to the server.

Return type:

Dict[str, Scalar]

set_context(context: Context) None[source]#

Apply a run context to this client.

to_client() Client[source]#

Convert to object to Client type and return it.