{"record":{"id":"3848e878c3be7276","repo":"Lightning-AI/pytorch-lightning","slug":"f-logging-inside-fx-name-is-not-implemented","errorCode":null,"errorMessage":"f\"Logging inside `{fx_name}` is not implemented.\" \" Please, open an issue in `https://github.com/Lightning-AI/pytorch-lightning/issues`.\"","messagePattern":"f\"Logging inside `(.+?)` is not implemented\\.\" \" Please, open an issue in `https://github\\.com/Lightning-AI/pytorch-lightning/issues`\\.\"","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/logger_connector/fx_validator.py","lineNumber":155,"sourceCode":"        \"predict_step\": None,\n        \"configure_optimizers\": None,\n        \"train_dataloader\": None,\n        \"val_dataloader\": None,\n        \"test_dataloader\": None,\n        \"prepare_data\": None,\n        \"configure_callbacks\": None,\n        \"on_validation_model_zero_grad\": None,\n        \"on_validation_model_eval\": None,\n        \"on_test_model_eval\": None,\n        \"on_validation_model_train\": None,\n        \"on_test_model_train\": None,\n    }\n\n    @classmethod\n    def check_logging(cls, fx_name: str) -> None:\n        \"\"\"Check if the given hook is allowed to log.\"\"\"\n        if fx_name not in cls.functions:\n            raise RuntimeError(\n                f\"Logging inside `{fx_name}` is not implemented.\"\n                \" Please, open an issue in `https://github.com/Lightning-AI/pytorch-lightning/issues`.\"\n            )\n\n        if cls.functions[fx_name] is None:\n            raise MisconfigurationException(\n                f\"You can't `self.log()` inside `{fx_name}`. HINT: You can still log directly to the logger by using\"\n                \" `self.logger.experiment`.\"\n            )\n\n    @classmethod\n    def get_default_logging_levels(\n        cls, fx_name: str, on_step: Optional[bool], on_epoch: Optional[bool]\n    ) -> tuple[bool, bool]:\n        \"\"\"Return default logging levels for given hook.\"\"\"\n        fx_config = cls.functions[fx_name]\n        assert fx_config is not None\n        on_step = fx_config[\"default_on_step\"] if on_step is None else on_step","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/logger_connector/fx_validator.py#L137-L173","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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()"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from lightning.pytorch.trainer.connectors.logger_connector.fx_validator import _FxValidator\nassert hook_name in _FxValidator.functions, f\"unregistered hook {hook_name}\"","typeGuard":null,"tryCatchPattern":"try:\n    self.log(name, value)\nexcept RuntimeError as e:\n    if \"not implemented\" in str(e):\n        self.logger.experiment.log_metric(name, value)  # fallback\n    else:\n        raise","preventionTips":["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"],"tags":["pytorch-lightning","logging","internal-error","runtimeerror"],"backgroundTag":"logging-outside-allowed-hook","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}