{"record":{"id":"a39eb3d97374e451","repo":"Lightning-AI/pytorch-lightning","slug":"the-configure-serialization-method-needs-to-be-o","errorCode":null,"errorMessage":"The `configure_serialization` method needs to be overridden.","messagePattern":"The `configure_serialization` method needs to be overridden\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/serve/servable_module_validator.py","lineNumber":90,"sourceCode":"        self.exit_on_failure = exit_on_failure\n        self.resp: Optional[requests.Response] = None\n\n    @override\n    @rank_zero_only\n    def on_train_start(self, trainer: \"pl.Trainer\", servable_module: \"pl.LightningModule\") -> None:\n        if isinstance(trainer.strategy, _NOT_SUPPORTED_STRATEGIES):\n            raise Exception(\n                f\"The current strategy {trainer.strategy.__class__.__qualname__} used \"\n                \"by the trainer isn't supported for sanity serving yet.\"\n            )\n\n        if not isinstance(servable_module, ServableModule):\n            raise TypeError(f\"The provided model should be subclass of {ServableModule.__qualname__}.\")\n\n        if not is_overridden(\"configure_payload\", servable_module, ServableModule):\n            raise NotImplementedError(\"The `configure_payload` method needs to be overridden.\")\n        if not is_overridden(\"configure_serialization\", servable_module, ServableModule):\n            raise NotImplementedError(\"The `configure_serialization` method needs to be overridden.\")\n        if not is_overridden(\"serve_step\", servable_module, ServableModule):\n            raise NotImplementedError(\"The `serve_step` method needs to be overridden.\")\n\n        # Note: The Trainer needs to be detached from the pl_module before starting the process.\n        # This would fail during the deepcopy with DDP.\n        servable_module.trainer = None\n\n        process = Process(target=self._start_server, args=(servable_module, self.host, self.port, self.optimization))\n        process.start()\n\n        servable_module.trainer = trainer\n\n        ready = False\n        t0 = time.time()\n        while not ready:\n            with contextlib.suppress(requests.exceptions.ConnectionError):\n                resp = requests.get(f\"http://{self.host}:{self.port}/ping\")\n                ready = resp.status_code == 200","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/serve/servable_module_validator.py#L72-L108","documentation":"ServableModuleValidator requires configure_serialization to be overridden so it knows how to deserialize inputs and serialize outputs for the serving endpoint. Without it, is_overridden fails in on_train_start and a NotImplementedError is raised before the server process starts.","triggerScenarios":"Model subclasses ServableModule but leaves configure_serialization at its default (not overridden); ServableModuleValidator callback runs on_train_start.","commonSituations":"Migrating a LightningModule to the serving API and forgetting the (de)serializers, or returning None / not returning the (input_deserializers, output_serializers) pair.","solutions":["Implement configure_serialization returning a tuple of input deserializer dict and output serializer dict, e.g. (lambda x: torch.tensor(x), lambda t: t.tolist())","Verify the method is defined directly on your class (is_overridden checks against ServableModule)","Remove ServableModuleValidator from callbacks if you don't intend to validate serving"],"exampleFix":"// before\nclass MyModel(ServableModule):\n    def configure_payload(self): ...\n    def serve_step(self, **kwargs): ...\n// after\nclass MyModel(ServableModule):\n    def configure_serialization(self):\n        return ({\"x\": lambda x: torch.tensor(x)}, {\"output\": lambda t: t.tolist()})\n    def configure_payload(self): ...\n    def serve_step(self, **kwargs): ...","handlingStrategy":"validation","validationCode":"from lightning.pytorch.utilities import is_overridden\nfrom lightning.pytorch.serve import ServableModule\n\nassert is_overridden(\"configure_serialization\", model, ServableModule), \\\n    \"configure_serialization must be overridden\"","typeGuard":"def has_serialization(m) -> bool:\n    return is_overridden(\"configure_serialization\", m, ServableModule)","tryCatchPattern":null,"preventionTips":["Return a (input_deserializers, output_serializers) pair whose keys match payload and serve_step outputs","Unit-test configure_serialization output types locally"],"tags":["lightning","serving","serialization","not-implemented"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}