syft.federated.federated_client

Module Contents

class syft.federated.federated_client.FederatedClient(datasets=None)

Bases: syft.generic.object_storage.ObjectStorage

A Client able to execute federated learning in local datasets.

add_dataset(self, dataset, key: str)
remove_dataset(self, key: str)
set_obj(self, obj: object)

Registers objects checking if which objects it should cache.

Parameters

obj – An object to be registered.

_check_train_config(self)
_build_optimizer(self, optimizer_name: str, model, optimizer_args: dict)

Build an optimizer if needed.

Parameters
  • optimizer_name – A string indicating the optimizer name.

  • optimizer_args – A dict containing the args used to initialize the optimizer.

Returns

A Torch Optimizer.

fit(self, dataset_key: str, device: str = 'cpu', **kwargs)

Fits a model on the local dataset as specified in the local TrainConfig object.

Parameters
  • dataset_key – Identifier of the local dataset that shall be used for training.

  • **kwargs – Unused.

Returns

Training loss on the last batch of training data.

Return type

loss

_create_data_loader(self, dataset_key: str, shuffle: bool = False)
_fit(self, model, dataset_key, loss_fn, device='cpu')
evaluate(self, dataset_key: str, return_histograms: bool = False, nr_bins: int = -1, return_loss: bool = True, return_raw_accuracy: bool = True, device: str = 'cpu')

Evaluates a model on the local dataset as specified in the local TrainConfig object.

Parameters
  • dataset_key – Identifier of the local dataset that shall be used for training.

  • return_histograms – If True, calculate the histograms of predicted classes.

  • nr_bins – Used together with calculate_histograms. Provide the number of classes/bins.

  • return_loss – If True, loss is calculated additionally.

  • return_raw_accuracy – If True, return nr_correct_predictions and nr_predictions

Returns

  • loss: avg loss on data set, None if not calculated.

  • nr_correct_predictions: number of correct predictions.

  • nr_predictions: total number of predictions.

  • histogram_predictions: histogram of predictions.

  • histogram_target: histogram of target values in the dataset.

Return type

Dictionary containing depending on the provided flags