fedlab_core.client.handler

Module Contents

Classes

ClientBackendHandler

An abstract class representing handler for a client backend.

ClientSGDHandler

Client backend handler, this class provides data process method to upper layer.

class fedlab_core.client.handler.ClientBackendHandler(model, cuda)

Bases: object

An abstract class representing handler for a client backend.

In our framework, we define the backend of client handler show manage its local model and buffer. It should have a function to update its model called train() and a function called evaluate().

If you use our framework to define the activities of client, please make sure that your self-defined class should subclass it. All subclasses should overwrite train() and evaluate().

property model(self)

Get torch.nn.Module

property buffer(self)

Get serialized parameters

abstract train(self)

Please override this method. This function should manipulate self._model and self._buffer

abstract evaluate(self, test_loader)

Please override this method. Evaluate local model based on given test :class:`torch.DataLoader

class fedlab_core.client.handler.ClientSGDHandler(model, data_loader, optimizer=None, criterion=None, cuda=True, logger_file='log/handler.txt', logger_name='handler')

Bases: fedlab_core.client.handler.ClientBackendHandler

Client backend handler, this class provides data process method to upper layer.

Parameters
  • model (torch.nn.Module) –

  • data_loader (torch.Dataloader) – DataLoader for this client

  • optimizer (torch.optim.Optimizer, optional) – optimizer for this client’s model. If set to None, will use

:param torch.optim.SGD() with lr of 0.1 and momentum of 0.9 as default.: :param criterion: loss function used in local training process. If set to None, will use :type criterion: optional :param nn.CrossEntropyLoss() as default.: :param cuda: use GPUs or not. Default: True :type cuda: bool, optional :param LOGGER: utils class to output debug information to file and command line

Raises

None

train(self, epochs)

Client trains its local model on local dataset.

Parameters

epochs (int) – number of epoch for local training

evaluate(self, test_loader, cuda)

Evaluate local model based on given test torch.DataLoader