diff --git a/CHANGELOG.md b/CHANGELOG.md index d2590a70e021e..a296edccb324c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - + +- Added support for calling unknown methods with `DummyLogger` ([#13224](https://github.com/PyTorchLightning/pytorch-lightning/pull/13224)) + ### Changed - Enable validation during overfitting ([#12527](https://github.com/PyTorchLightning/pytorch-lightning/pull/12527)) diff --git a/src/pytorch_lightning/loggers/logger.py b/src/pytorch_lightning/loggers/logger.py index e9f7c165d07ed..c1eecb93fc8bf 100644 --- a/src/pytorch_lightning/loggers/logger.py +++ b/src/pytorch_lightning/loggers/logger.py @@ -346,6 +346,14 @@ def __iter__(self): # if DummyLogger is substituting a logger collection, pretend it is empty yield from () + def __getattr__(self, name: str) -> Callable: + """Allows the DummyLogger to be called with arbitrary methods, to avoid AttributeErrors.""" + + def method(*args, **kwargs): + return None + + return method + def merge_dicts( dicts: Sequence[Mapping], diff --git a/src/pytorch_lightning/trainer/trainer.py b/src/pytorch_lightning/trainer/trainer.py index 85de7acbe352a..adedad4111ca3 100644 --- a/src/pytorch_lightning/trainer/trainer.py +++ b/src/pytorch_lightning/trainer/trainer.py @@ -589,7 +589,10 @@ def _init_debugging_flags( self.check_val_every_n_epoch = 1 self.loggers = [DummyLogger()] if self.loggers else [] - rank_zero_info(f"Running in fast_dev_run mode: will run the requested loop using {num_batches} batch(es).") + rank_zero_info( + f"Running in `fast_dev_run` mode: will run the requested loop using {num_batches} batch(es). " + "Logging and checkpointing is suppressed." + ) self.limit_train_batches = _determine_batch_limits(limit_train_batches, "limit_train_batches") self.limit_val_batches = _determine_batch_limits(limit_val_batches, "limit_val_batches") diff --git a/tests/tests_pytorch/loggers/test_logger.py b/tests/tests_pytorch/loggers/test_logger.py index 0f63655b1fb68..d9a59b98125e8 100644 --- a/tests/tests_pytorch/loggers/test_logger.py +++ b/tests/tests_pytorch/loggers/test_logger.py @@ -257,6 +257,14 @@ def test_dummylogger_noop_method_calls(): logger.log_metrics("1", 2, three="three") +def test_dummlogger_arbitrary_method_calls(): + """Test that the DummyLogger can be called with non existing methods.""" + logger = DummyLogger() + # Example method from WandbLogger + assert hasattr(logger, "log_text") + assert callable(logger.log_text) + + def test_dummyexperiment_support_item_assignment(): """Test that the DummyExperiment supports item assignment.""" experiment = DummyExperiment()