:mod:`fedlab_core.client.topology` ================================== .. py:module:: fedlab_core.client.topology Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: fedlab_core.client.topology.ClientCommunicationTopology fedlab_core.client.topology.ClientSyncTop .. class:: ClientCommunicationTopology(backend_handler, server_addr, world_size, rank, dist_backend) Bases: :class:`torch.multiprocessing.Process` Abstract class If you want to define your own Network Topology, please be sure your class should subclass it and OVERRIDE its methods. .. rubric:: Example please read the code of :class:`ClientSyncTop` .. method:: run(self) :abstractmethod: Please override this function .. method:: on_receive(self, sender, message_code, payload) :abstractmethod: Please override this function .. method:: synchronize(self) :abstractmethod: Please override this function .. class:: ClientSyncTop(backend_handler, server_addr, world_size, rank, dist_backend='gloo', logger_file='clientLog', logger_name='') Bases: :class:`fedlab_core.client.topology.ClientCommunicationTopology` Synchronise communication class This is the top class in our framework which is mainly responsible for network communication of CLIENT! Synchronize with server following agreements defined in :meth:`run`. :param backend_handler: Subclass of ClientBackendHandler, manages training and evaluation of local model on each :param client.: :param server_addr: Address of server in form of ``(SERVER_ADDR, SERVER_IP)`` :type server_addr: tuple :param world_size: Number of client processes participating in the job for ``torch.distributed`` initialization :type world_size: int :param rank: Rank of the current client process for ``torch.distributed`` initialization :type rank: int :param dist_backend: :attr:`backend` of ``torch.distributed``. Valid values include ``mpi``, ``gloo``, :type dist_backend: str or Backend :param and ``nccl``. Default: ``"gloo"`` :param logger_file: Path to the log file for all clients of :class:`ClientSyncTop` class. Default: ``"clientLog"`` :type logger_file: str, optional :param logger_name: Class name to initialize logger :type logger_name: str, optional :raises Errors raised by :func:`torch.distributed.init_process_group`: .. rubric:: Example TODO .. method:: run(self) Main procedure of each client is defined here: 1. client waits for data from server 2. after receiving data, client will train local model 3. client will synchronize with server actively .. method:: on_receive(self, sender, message_code, payload) Actions to perform on receiving new message, including local training :param sender: Index of sender :type sender: int :param message_code: Agreements code defined in :class:`MessageCode` class :type message_code: MessageCode :param payload: Serialized model parameters :type payload: torch.Tensor .. method:: synchronize(self) Synchronize local model with server actively :param buffer: Serialized model parameters :returns: None :raises None: .. method:: _waiting(self)