:mod:`fedlab_core.client.handler` ================================= .. py:module:: fedlab_core.client.handler Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: fedlab_core.client.handler.ClientBackendHandler fedlab_core.client.handler.ClientSGDHandler .. class:: ClientBackendHandler(model, cuda) Bases: :class:`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 :meth:`train` and a function called :meth:`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 :meth:`train` and :meth:`evaluate`. .. method:: model(self) :property: Get :class:`torch.nn.Module` .. method:: buffer(self) :property: Get serialized parameters .. method:: train(self) :abstractmethod: Please override this method. This function should manipulate :attr:`self._model` and :attr:`self._buffer` .. method:: evaluate(self, test_loader) :abstractmethod: Please override this method. Evaluate local model based on given test :class:`torch.DataLoader .. class:: ClientSGDHandler(model, data_loader, optimizer=None, criterion=None, cuda=True, logger_file='log/handler.txt', logger_name='handler') Bases: :class:`fedlab_core.client.handler.ClientBackendHandler` Client backend handler, this class provides data process method to upper layer. :param model: :type model: torch.nn.Module :param data_loader: :class:`DataLoader` for this client :type data_loader: torch.Dataloader :param optimizer: optimizer for this client's model. If set to ``None``, will use :type optimizer: torch.optim.Optimizer, optional :param :func:`torch.optim.SGD` with :attr:`lr` of 0.1 and :attr:`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 :func:`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: .. method:: train(self, epochs) Client trains its local model on local dataset. :param epochs: number of epoch for local training :type epochs: int .. method:: evaluate(self, test_loader, cuda) Evaluate local model based on given test :class:`torch.DataLoader`