Source code for p2pfl.learning.frameworks.pytorch.lightning_logger
## This file is part of the federated_learning_p2p (p2pfl) distribution# (see https://github.com/pguijas/p2pfl).# Copyright (c) 2022 Pedro Guijas Bravo.## This program is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, version 3.## This program is distributed in the hope that it will be useful, but# WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program. If not, see <http://www.gnu.org/licenses/>.#"""Lightning Logger for P2PFL."""frompytorch_lightning.loggers.loggerimportLoggerfromp2pfl.management.loggerimportloggerasP2PLogger
[docs]classFederatedLogger(Logger):""" Pytorch Lightning Logger for Federated Learning. Handles local training loggin. Args: node_name: Name of the node. """def__init__(self,addr:str)->None:"""Initialize the logger."""super().__init__()self.__addr=addr@propertydefname(self)->None:"""Name of the logger."""pass@propertydefversion(self)->None:"""Version of the logger."""pass
[docs]deflog_metrics(self,metrics:dict,step:int)->None:"""Log metrics (in a pytorch format)."""fork,vinmetrics.items():P2PLogger.log_metric(self.__addr,k,v,step)
[docs]defsave(self)->None:"""Save the logger."""pass
[docs]deffinalize(self,status:str)->None:"""Finalize the logger."""pass