Lightning-AI/pytorch-lightning · error · RuntimeError
f"Logging inside `{fx_name}` is not implemented." " Please,
Error message
f"Logging inside `{fx_name}` is not implemented." " Please, open an issue in `https://github.com/Lightning-AI/pytorch-lightning/issues`." What it means
The _FxValidator maintains a whitelist of hooks where self.log() is permitted (e.g. training_step, validation_step). check_logging raises a RuntimeError when the hook name is entirely absent from that registry, meaning Lightning hit a logging call in a code path it does not account for — this is effectively an internal invariant/Lightning bug rather than a user config error.
Source
Thrown at src/lightning/pytorch/trainer/connectors/logger_connector/fx_validator.py:155
"predict_step": None,
"configure_optimizers": None,
"train_dataloader": None,
"val_dataloader": None,
"test_dataloader": None,
"prepare_data": None,
"configure_callbacks": None,
"on_validation_model_zero_grad": None,
"on_validation_model_eval": None,
"on_test_model_eval": None,
"on_validation_model_train": None,
"on_test_model_train": None,
}
@classmethod
def check_logging(cls, fx_name: str) -> None:
"""Check if the given hook is allowed to log."""
if fx_name not in cls.functions:
raise RuntimeError(
f"Logging inside `{fx_name}` is not implemented."
" Please, open an issue in `https://github.com/Lightning-AI/pytorch-lightning/issues`."
)
if cls.functions[fx_name] is None:
raise MisconfigurationException(
f"You can't `self.log()` inside `{fx_name}`. HINT: You can still log directly to the logger by using"
" `self.logger.experiment`."
)
@classmethod
def get_default_logging_levels(
cls, fx_name: str, on_step: Optional[bool], on_epoch: Optional[bool]
) -> tuple[bool, bool]:
"""Return default logging levels for given hook."""
fx_config = cls.functions[fx_name]
assert fx_config is not None
on_step = fx_config["default_on_step"] if on_step is None else on_stepView on GitHub (pinned to 9fed5c27d2)
Solutions
- Update/align Lightning versions so internal hook names match the registry (pip install -U pytorch-lightning)
- If you monkey-patched or subclassed Trainer loops, stop passing custom fx_name values into the logging API; use standard hooks like training_step
- Open an issue at https://github.com/Lightning-AI/pytorch-lightning/issues with a reproduction, as the message requests
- As a workaround, log directly via self.logger.experiment instead of self.log()
Defensive patterns
Strategy: try-catch
Validate before calling
from lightning.pytorch.trainer.connectors.logger_connector.fx_validator import _FxValidator
assert hook_name in _FxValidator.functions, f"unregistered hook {hook_name}" Try / catch
try:
self.log(name, value)
except RuntimeError as e:
if "not implemented" in str(e):
self.logger.experiment.log_metric(name, value) # fallback
else:
raise Prevention
- Only call self.log inside standard Lightning hooks
- Pin Lightning versions in CI to catch registry changes
- Log via self.logger.experiment for non-standard code paths
When it happens
Trigger: self.log(...) executing in a context whose fx_name is not a key in _FxValidator.functions, typically from a custom loop/callback triggering logging under an unrecognized hook name, or after renaming/adding hooks in a fork or outdated monkey-patch of Lightning internals.
Common situations: Upgrading PyTorch Lightning where hook names changed while a custom subclass/monkey-patch still passes old names; calling the logging result machinery manually with an arbitrary fx_name string; forks of Lightning adding new hooks without registering them.
Related errors
- you tried to log {v} which is currently not supported. Try a
- You are trying to `self.log()` but the loop's result collect
- You are trying to `self.log()` but it is not managed by the
- ReduceLROnPlateau conditioned on metric {monitor_key} which
- f"You can't `self.log()` inside `{fx_name}`. HINT: You can s
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/3848e878c3be7276.
Report an issue: GitHub.