Skip to content

Commit

Permalink
adding hint to the logger's error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Al3xDo committed Dec 13, 2022
1 parent 53ceb15 commit 84709bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def check_logging(cls, fx_name: str) -> None:
)

if cls.functions[fx_name] is None:
raise MisconfigurationException(f"You can't `self.log()` inside `{fx_name}`.")
raise MisconfigurationException(f"You can alternatively log with `logger.experiment` inside `{fx_name}`.")

@classmethod
def get_default_logging_levels(
Expand Down
56 changes: 28 additions & 28 deletions tests/tests_pytorch/trainer/logging_/test_logger_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_fx_validator():
validator.check_logging_levels(fx_name=func_name, on_step=True, on_epoch=on_epoch)
else:
assert func_name in not_supported
with pytest.raises(MisconfigurationException, match="You can't"):
with pytest.raises(MisconfigurationException, match="You can alternatively log with"):
validator.check_logging(fx_name=func_name)

with pytest.raises(RuntimeError, match="Logging inside `foo` is not implemented"):
Expand Down Expand Up @@ -188,29 +188,29 @@ def test_fx_validator_integration(tmpdir):
"""Tries to log inside all `LightningModule` and `Callback` hooks to check any expected errors."""
not_supported = {
None: "`self.trainer` reference is not registered",
"setup": "You can't",
"configure_sharded_model": "You can't",
"configure_optimizers": "You can't",
"on_fit_start": "You can't",
"train_dataloader": "You can't",
"val_dataloader": "You can't",
"on_before_batch_transfer": "You can't",
"transfer_batch_to_device": "You can't",
"on_after_batch_transfer": "You can't",
"on_validation_end": "You can't",
"on_train_end": "You can't",
"on_fit_end": "You can't",
"teardown": "You can't",
"on_sanity_check_start": "You can't",
"on_sanity_check_end": "You can't",
"prepare_data": "You can't",
"configure_callbacks": "You can't",
"on_validation_model_eval": "You can't",
"on_validation_model_train": "You can't",
"lr_scheduler_step": "You can't",
"on_save_checkpoint": "You can't",
"on_load_checkpoint": "You can't",
"on_exception": "You can't",
"setup": "You can alternatively log with",
"configure_sharded_model": "You can alternatively log with",
"configure_optimizers": "You can alternatively log with",
"on_fit_start": "You can alternatively log with",
"train_dataloader": "You can alternatively log with",
"val_dataloader": "You can alternatively log with",
"on_before_batch_transfer": "You can alternatively log with",
"transfer_batch_to_device": "You can alternatively log with",
"on_after_batch_transfer": "You can alternatively log with",
"on_validation_end": "You can alternatively log with",
"on_train_end": "You can alternatively log with",
"on_fit_end": "You can alternatively log with",
"teardown": "You can alternatively log with",
"on_sanity_check_start": "You can alternatively log with",
"on_sanity_check_end": "You can alternatively log with",
"prepare_data": "You can alternatively log with",
"configure_callbacks": "You can alternatively log with",
"on_validation_model_eval": "You can alternatively log with",
"on_validation_model_train": "You can alternatively log with",
"lr_scheduler_step": "You can alternatively log with",
"on_save_checkpoint": "You can alternatively log with",
"on_load_checkpoint": "You can alternatively log with",
"on_exception": "You can alternatively log with",
}
model = HookedModel(not_supported)

Expand All @@ -232,10 +232,10 @@ def test_fx_validator_integration(tmpdir):
not_supported.update(
{
# `lightning_module` ref is now present from the `fit` call
"test_dataloader": "You can't",
"on_test_model_eval": "You can't",
"on_test_model_train": "You can't",
"on_test_end": "You can't",
"test_dataloader": "You can alternatively log with",
"on_test_model_eval": "You can alternatively log with",
"on_test_model_train": "You can alternatively log with",
"on_test_end": "You can alternatively log with",
}
)
trainer.test(model, verbose=False)
Expand Down

0 comments on commit 84709bb

Please sign in to comment.