fedlab_core.client.handler
¶
Module Contents¶
Classes¶
An abstract class representing handler for a client backend. |
|
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 calledevaluate()
.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()
andevaluate()
.-
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
andself._buffer
-
property
-
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 clientoptimizer (torch.optim.Optimizer, optional) – optimizer for this client’s model. If set to
None
, will use
:param
torch.optim.SGD()
withlr
of 0.1 andmomentum
of 0.9 as default.: :param criterion: loss function used in local training process. If set toNone
, will use :type criterion: optional :paramnn.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