florist.api.clients.clients module

Implementation of the clients and the Client enumeration.

class Client(value)[source]

Bases: Enum

Enumeration of supported clients.

FEDAVG = 'FedAvg'
FEDPROX = 'FedProx'
get_client_class()[source]

Return the class for this client.

Return type:

type[LocalDataClient]

Returns:

(type[LocalDataClient]) A subclass of LocalDataClient corresponding to the this client.

Raises:

ValueError – if the client is not supported.

classmethod list()[source]

List all the supported clients.

Return type:

list[str]

Returns:

(list[str]) a list of supported clients.

classmethod list_by_strategy(strategy)[source]

List all the supported clients given a strategy.

Parameters:

strategy (Strategy) – (Strategy) the strategy to find the supported clients.

Return type:

List[str]

Returns:

(list[str]) a list of supported clients for the given strategy.

class FedProxLocalDataClient(data_path, metrics, device, loss_meter_type=LossMeterType.AVERAGE, checkpoint_and_state_module=None, reporters=None, progress_bar=False, client_name=None)[source]

Bases: FedProxClient, LocalDataClient

Implementation of the FedProx client that uses a model with data stored locally.

get_data_loaders(config)[source]

Return the data loader for FedProx on model with data stored locally.

Parameters:

config (Dict[str, Union[bool, bytes, float, int, str]]) – (Config) the Config object for this client.

Return type:

tuple[DataLoader[TensorDataset], DataLoader[TensorDataset]]

Returns:

(Tuple[DataLoader[TensorDataset], DataLoader[TensorDataset]]) a tuple with the train data loader and validation data loader respectively.

class LocalDataClient(data_path, metrics, device, loss_meter_type=LossMeterType.AVERAGE, checkpoint_and_state_module=None, reporters=None, progress_bar=False, client_name=None)[source]

Bases: BasicClient

Implementation of a client that uses a model with data stored locally.

get_criterion(config)[source]

Return the loss for the model.

Parameters:

config (Dict[str, Union[bool, bytes, float, int, str]]) – (Config) the Config object for this client.

Return type:

_Loss

Returns:

(torch.nn.modules.loss._Loss) an instance of torch.nn.modules.loss._Loss that has been defined by the local model.

get_data_loaders(config)[source]

Return the data loader for the model with local data.

Parameters:

config (Dict[str, Union[bool, bytes, float, int, str]]) – (Config) the Config object for this client.

Return type:

tuple[DataLoader[TensorDataset], DataLoader[TensorDataset]]

Returns:

(Tuple[DataLoader[TensorDataset], DataLoader[TensorDataset]]) a tuple with the train data loader and validation data loader respectively.

get_model(config)[source]

Return the model for training with local data.

Parameters:

config (Dict[str, Union[bool, bytes, float, int, str]]) – (Config) the Config object for this client.

Return type:

Module

Returns:

(torch.nn.Module) An instance of the model.

get_optimizer(config)[source]

Return the optimizer for the model.

Parameters:

config (Dict[str, Union[bool, bytes, float, int, str]]) – (Config) the Config object for this client.

Return type:

Optimizer

Returns:

(torch.optim.Optimizer) An instance of torch.optim.Optimizer with the configurations defined by self.optimizer_type.

set_model(model)[source]

Set the model to be used for training with local data.

Parameters:

model (LocalDataModel) – (LocalModel) An instance of the model to be used for training.

Return type:

None

set_optimizer_type(optimizer_type)[source]

Set the type of the optimizer to be used for training.

Parameters:

optimizer_type (Optimizer) – (Optimizer) A value of the Optimizer enumeration with the type of the optimizer to be used for training.

Return type:

None