flwr.server package

Flower Server.

class flwr.server.History[source]

Bases: object

History class for training and/or evaluation metrics collection.

add_accuracy_centralized(rnd: int, acc: float) → None[source]

Add one accuracy entry (from centralized evaluation).

add_accuracy_distributed(rnd: int, acc: float) → None[source]

Add one accuray entry (from distributed evaluation).

add_loss_centralized(rnd: int, loss: float) → None[source]

Add one loss entry (from centralized evaluation).

add_loss_distributed(rnd: int, loss: float) → None[source]

Add one loss entry (from distributed evaluation).

class flwr.server.Server(client_manager: flwr.server.client_manager.ClientManager, strategy: Optional[flwr.server.strategy.strategy.Strategy] = None)[source]

Bases: object

Flower server.

client_manager()flwr.server.client_manager.ClientManager[source]

Return ClientManager.

evaluate(rnd: int) → Optional[Tuple[Optional[float], Tuple[List[Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.EvaluateRes]], List[BaseException]]]][source]

Validate current global model on a number of clients.

fit(num_rounds: int)flwr.server.history.History[source]

Run federated averaging for a number of rounds.

fit_round(rnd: int) → Optional[List[numpy.ndarray]][source]

Perform a single round of federated averaging.

class flwr.server.SimpleClientManager[source]

Bases: flwr.server.client_manager.ClientManager

Provides a pool of available clients.

all() → Dict[str, flwr.server.client_proxy.ClientProxy][source]

Return all available clients.

num_available() → int[source]

Return the number of available clients.

register(client: flwr.server.client_proxy.ClientProxy) → bool[source]

Register Flower ClientProxy instance.

Returns

Indicating if registration was successful. False if ClientProxy is

already registered or can not be registered for any reason

Return type

bool

sample(num_clients: int, min_num_clients: Optional[int] = None, criterion: Optional[flwr.server.criterion.Criterion] = None) → List[flwr.server.client_proxy.ClientProxy][source]

Sample a number of Flower ClientProxy instances.

unregister(client: flwr.server.client_proxy.ClientProxy) → None[source]

Unregister Flower ClientProxy instance.

This method is idempotent.

wait_for(num_clients: int, timeout: int = 86400) → bool[source]

Block until at least num_clients are available or until a timeout is reached.

Current timeout default: 1 day.

flwr.server.start_server(server_address: str = '[::]:8080', server: Optional[flwr.server.server.Server] = None, config: Optional[Dict[str, int]] = None, strategy: Optional[flwr.server.strategy.strategy.Strategy] = None, grpc_max_message_length: int = 536870912) → None[source]

Start a Flower server using the gRPC transport layer.

Parameters
  • server_address – Optional[str] (default: “[::]:8080”). The IPv6 address of the server.

  • server – Optional[flwr.server.Server] (default: None). An implementation of the abstract base class flwr.server.Server. If no instance is provided, then start_server will create one.

  • config – Optional[Dict[str, int]] (default: None). The only currently supported values is num_rounds, so a full configuration object instructing the server to perform three rounds of federated learning looks like the following: {“num_rounds”: 3}.

  • strategy – Optional[flwr.server.Strategy] (default: None). An implementation of the abstract base class flwr.server.Strategy. If no strategy is provided, then start_server will use flwr.server.strategy.FedAvg.

  • grpc_max_message_length – int (default: 536_870_912, this equals 512MB). The maximum length of gRPC messages that can be exchanged with the Flower clients. The default should be sufficient for most models. Users who train very large models might need to increase this value. Note that the Flower clients needs to started with the same value (see flwr.client.start_client), otherwise clients will not know about the increased limit and block larger messages.

Returns

None.

Submodules

flwr.server.app module

Flower server app.

flwr.server.app.start_server(server_address: str = '[::]:8080', server: Optional[flwr.server.server.Server] = None, config: Optional[Dict[str, int]] = None, strategy: Optional[flwr.server.strategy.strategy.Strategy] = None, grpc_max_message_length: int = 536870912) → None[source]

Start a Flower server using the gRPC transport layer.

Parameters
  • server_address – Optional[str] (default: “[::]:8080”). The IPv6 address of the server.

  • server – Optional[flwr.server.Server] (default: None). An implementation of the abstract base class flwr.server.Server. If no instance is provided, then start_server will create one.

  • config – Optional[Dict[str, int]] (default: None). The only currently supported values is num_rounds, so a full configuration object instructing the server to perform three rounds of federated learning looks like the following: {“num_rounds”: 3}.

  • strategy – Optional[flwr.server.Strategy] (default: None). An implementation of the abstract base class flwr.server.Strategy. If no strategy is provided, then start_server will use flwr.server.strategy.FedAvg.

  • grpc_max_message_length – int (default: 536_870_912, this equals 512MB). The maximum length of gRPC messages that can be exchanged with the Flower clients. The default should be sufficient for most models. Users who train very large models might need to increase this value. Note that the Flower clients needs to started with the same value (see flwr.client.start_client), otherwise clients will not know about the increased limit and block larger messages.

Returns

None.

flwr.server.client_manager module

Flower ClientManager.

class flwr.server.client_manager.ClientManager[source]

Bases: abc.ABC

Abstract base class for managing Flower clients.

abstract all() → Dict[str, flwr.server.client_proxy.ClientProxy][source]

Return all available clients.

abstract num_available() → int[source]

Return the number of available clients.

abstract register(client: flwr.server.client_proxy.ClientProxy) → bool[source]

Register Flower ClientProxy instance.

Returns

Indicating if registration was successful

Return type

bool

abstract sample(num_clients: int, min_num_clients: Optional[int] = None, criterion: Optional[flwr.server.criterion.Criterion] = None) → List[flwr.server.client_proxy.ClientProxy][source]

Sample a number of Flower ClientProxy instances.

abstract unregister(client: flwr.server.client_proxy.ClientProxy) → None[source]

Unregister Flower ClientProxy instance.

abstract wait_for(num_clients: int, timeout: int) → bool[source]

Wait until at least num_clients are available.

class flwr.server.client_manager.SimpleClientManager[source]

Bases: flwr.server.client_manager.ClientManager

Provides a pool of available clients.

all() → Dict[str, flwr.server.client_proxy.ClientProxy][source]

Return all available clients.

num_available() → int[source]

Return the number of available clients.

register(client: flwr.server.client_proxy.ClientProxy) → bool[source]

Register Flower ClientProxy instance.

Returns

Indicating if registration was successful. False if ClientProxy is

already registered or can not be registered for any reason

Return type

bool

sample(num_clients: int, min_num_clients: Optional[int] = None, criterion: Optional[flwr.server.criterion.Criterion] = None) → List[flwr.server.client_proxy.ClientProxy][source]

Sample a number of Flower ClientProxy instances.

unregister(client: flwr.server.client_proxy.ClientProxy) → None[source]

Unregister Flower ClientProxy instance.

This method is idempotent.

wait_for(num_clients: int, timeout: int = 86400) → bool[source]

Block until at least num_clients are available or until a timeout is reached.

Current timeout default: 1 day.

flwr.server.client_proxy module

Flower client (abstract base class).

class flwr.server.client_proxy.ClientProxy(cid: str)[source]

Bases: abc.ABC

Abstract base class for Flower client proxies.

abstract evaluate(ins: flwr.common.typing.EvaluateIns)flwr.common.typing.EvaluateRes[source]

Evaluate the provided weights using the locally held dataset.

abstract fit(ins: flwr.common.typing.FitIns)flwr.common.typing.FitRes[source]

Refine the provided weights using the locally held dataset.

abstract get_parameters()flwr.common.typing.ParametersRes[source]

Return the current local model parameters.

abstract reconnect(reconnect: flwr.common.typing.Reconnect)flwr.common.typing.Disconnect[source]

Disconnect and (optionally) reconnect later.

flwr.server.criterion module

Abstract class for criterion sampling.

class flwr.server.criterion.Criterion[source]

Bases: abc.ABC

Abstract class which allows subclasses to implement criterion sampling.

abstract select(client: flwr.server.client_proxy.ClientProxy) → bool[source]

Decide whether a client should be eligible for sampling or not.

flwr.server.history module

Training history.

class flwr.server.history.History[source]

Bases: object

History class for training and/or evaluation metrics collection.

add_accuracy_centralized(rnd: int, acc: float) → None[source]

Add one accuracy entry (from centralized evaluation).

add_accuracy_distributed(rnd: int, acc: float) → None[source]

Add one accuray entry (from distributed evaluation).

add_loss_centralized(rnd: int, loss: float) → None[source]

Add one loss entry (from centralized evaluation).

add_loss_distributed(rnd: int, loss: float) → None[source]

Add one loss entry (from distributed evaluation).

flwr.server.server module

Flower server.

class flwr.server.server.Server(client_manager: flwr.server.client_manager.ClientManager, strategy: Optional[flwr.server.strategy.strategy.Strategy] = None)[source]

Bases: object

Flower server.

client_manager()flwr.server.client_manager.ClientManager[source]

Return ClientManager.

evaluate(rnd: int) → Optional[Tuple[Optional[float], Tuple[List[Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.EvaluateRes]], List[BaseException]]]][source]

Validate current global model on a number of clients.

fit(num_rounds: int)flwr.server.history.History[source]

Run federated averaging for a number of rounds.

fit_round(rnd: int) → Optional[List[numpy.ndarray]][source]

Perform a single round of federated averaging.

flwr.server.server.evaluate_client(client: flwr.server.client_proxy.ClientProxy, ins: flwr.common.typing.EvaluateIns) → Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.EvaluateRes][source]

Evaluate weights on a single client.

flwr.server.server.evaluate_clients(client_instructions: List[Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.EvaluateIns]]) → Tuple[List[Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.EvaluateRes]], List[BaseException]][source]

Evaluate weights concurrently on all selected clients.

flwr.server.server.fit_client(client: flwr.server.client_proxy.ClientProxy, ins: flwr.common.typing.FitIns) → Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.FitRes][source]

Refine weights on a single client.

flwr.server.server.fit_clients(client_instructions: List[Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.FitIns]]) → Tuple[List[Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.FitRes]], List[BaseException]][source]

Refine weights concurrently on all selected clients.

flwr.server.server.reconnect_client(client: flwr.server.client_proxy.ClientProxy, reconnect: flwr.common.typing.Reconnect) → Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.Disconnect][source]

Instruct a single client to disconnect and (optionally) reconnect later.

flwr.server.server.set_strategy(strategy: Optional[flwr.server.strategy.strategy.Strategy])flwr.server.strategy.strategy.Strategy[source]

Return Strategy.

flwr.server.server.shutdown(clients: List[flwr.server.client_proxy.ClientProxy]) → Tuple[List[Tuple[flwr.server.client_proxy.ClientProxy, flwr.common.typing.Disconnect]], List[BaseException]][source]

Instruct clients to disconnect and never reconnect.