Skip to content

Commit 210b241

Browse files
committed
Formatting fixes
1 parent eb3c74a commit 210b241

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

pytorch_lightning/loggers/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ def _finalize_agg_metrics(self):
146146

147147
def agg_and_log_metrics(self, metrics: Dict[str, float], step: Optional[int] = None):
148148
"""
149+
Aggregates and records metrics. This method doesn't log the passed metrics instantaneously, but instead
150+
it aggregates them and logs only if metrics are ready to be logged.
151+
149152
.. deprecated:: v1.6
150153
This method is deprecated in v1.6 and will be removed in v1.8.
151154
Please use `LightningLoggerBase.log_metrics` instead.
152155
153-
Aggregates and records metrics. This method doesn't log the passed metrics instantaneously, but instead
154-
it aggregates them and logs only if metrics are ready to be logged.
155-
156156
Args:
157157
metrics: Dictionary with metric names as keys and measured quantities as values
158158
step: Step number at which the metrics should be recorded

pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def on_trainer_init(
6565
self.trainer.flush_logs_every_n_steps = flush_logs_every_n_steps
6666
self.trainer.log_every_n_steps = log_every_n_steps
6767
self.trainer.move_metrics_to_cpu = move_metrics_to_cpu
68-
if not isinstance(self.trainer.logger, LoggerCollection) and is_overridden("agg_and_log_metrics", self.trainer.logger, LightningLoggerBase):
68+
if not isinstance(self.trainer.logger, LoggerCollection) and is_overridden(
69+
"agg_and_log_metrics", self.trainer.logger, LightningLoggerBase
70+
):
6971
rank_zero_deprecation(
7072
"`LightningLoggerBase.agg_and_log_metrics` is deprecated in v1.6 and will be"
7173
" removed in v1.8. Please use `LightningLoggerBase.log_metrics` instead."
@@ -122,7 +124,9 @@ def log_metrics(self, metrics: _OUT_DICT, step: Optional[int] = None) -> None:
122124
step = self.trainer.global_step
123125

124126
# log actual metrics
125-
if not isinstance(self.trainer.logger, LoggerCollection) and is_overridden("agg_and_log_metrics", self.trainer.logger, LightningLoggerBase):
127+
if not isinstance(self.trainer.logger, LoggerCollection) and is_overridden(
128+
"agg_and_log_metrics", self.trainer.logger, LightningLoggerBase
129+
):
126130
self.trainer.logger.agg_and_log_metrics(metrics=scalar_metrics, step=step)
127131
else:
128132
self.trainer.logger.log_metrics(metrics=scalar_metrics, step=step)

tests/deprecated_api/test_remove_1-8.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from pytorch_lightning.utilities.apply_func import move_data_to_device
3737
from pytorch_lightning.utilities.enums import DeviceType, DistributedType
3838
from pytorch_lightning.utilities.imports import _TORCHTEXT_LEGACY
39-
from pytorch_lightning.utilities.rank_zero import rank_zero_warn, rank_zero_only
39+
from pytorch_lightning.utilities.rank_zero import rank_zero_only, rank_zero_warn
4040
from tests.helpers.boring_model import BoringDataModule, BoringModel
4141
from tests.helpers.runif import RunIf
4242
from tests.helpers.torchtext_utils import get_dummy_torchtext_data_iterator
@@ -502,6 +502,7 @@ def on_before_accelerator_backend_setup(self, *args, **kwargs):
502502
):
503503
trainer.fit(model)
504504

505+
505506
def test_v1_8_0_deprecated_agg_and_log_metrics_override(tmpdir):
506507
class AggregationLogger(CSVLogger):
507508
def __init__(self, *args, **kwargs):
@@ -521,5 +522,6 @@ def __init__(self, *args, **kwargs):
521522
match="`LightningLoggerBase.agg_and_log_metrics` is deprecated in v1.6 and will be"
522523
" removed in v1.8. Please use `LightningLoggerBase.log_metrics` instead."
523524
):
524-
trainer = Trainer(logger=logger)
525-
trainer2 = Trainer(logger=logger2)
525+
Trainer(logger=logger)
526+
# Should have no deprecation warning
527+
Trainer(logger=logger2)

0 commit comments

Comments
 (0)