{"record":{"id":"3d4d0e1d46a86cdb","repo":"Lightning-AI/pytorch-lightning","slug":"unsupported-cls","errorCode":null,"errorMessage":"Unsupported {cls}","messagePattern":"Unsupported (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/core/saving.py","lineNumber":109,"sourceCode":"    # for past checkpoint need to add the new key\n    checkpoint.setdefault(cls.CHECKPOINT_HYPER_PARAMS_KEY, {})\n    # override the hparams with values that were passed in\n    checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY].update(kwargs)\n\n    if issubclass(cls, pl.LightningDataModule):\n        return _load_state(cls, checkpoint, **kwargs)\n    if issubclass(cls, pl.LightningModule):\n        model = _load_state(cls, checkpoint, strict=strict, **kwargs)\n        state_dict = checkpoint[\"state_dict\"]\n        if not state_dict:\n            rank_zero_warn(f\"The state dict in {checkpoint_path!r} contains no parameters.\")\n            return model\n\n        device = next((t for t in state_dict.values() if isinstance(t, torch.Tensor)), torch.tensor(0)).device\n        assert isinstance(model, pl.LightningModule)\n        return model.to(device)\n\n    raise NotImplementedError(f\"Unsupported {cls}\")\n\n\ndef _default_map_location(storage: \"UntypedStorage\", location: str) -> Optional[\"UntypedStorage\"]:\n    if (\n        location.startswith(\"mps\")\n        and not MPSAccelerator.is_available()\n        or location.startswith(\"cuda\")\n        and not CUDAAccelerator.is_available()\n        or location.startswith(\"xla\")\n        and not XLAAccelerator.is_available()\n    ):\n        return storage.cpu()\n    return None  # default behavior by `torch.load()`\n\n\ndef _load_state(\n    cls: Union[type[\"pl.LightningModule\"], type[\"pl.LightningDataModule\"]],\n    checkpoint: dict[str, Any],","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/core/saving.py#L91-L127","documentation":"NotImplementedError raised at the end of _load_from_checkpoint when the class being loaded is neither a pl.LightningModule nor a pl.LightningModule subclass handled by the earlier branches. The function only knows how to instantiate and hydrate Lightning modules; anything else falls through to this raise.","triggerScenarios":"Calling load_from_checkpoint where cls is a plain nn.Module, a Callback, or a class that doesn't inherit from LightningModule; also if a custom __init__ returns an object of a different type via a patched constructor.","commonSituations":"Trying to reuse the checkpoint-loading convenience API on non-Lightning classes, or refactoring a LightningModule into a plain module while old loader code remains.","solutions":["Make the class inherit from lightning.pytorch.LightningModule","Or load manually with torch.load(ckpt) and model.load_state_dict(state_dict)","Check that cls is the class you intended (not accidentally the metaclass or a factory)"],"exampleFix":"// before\nclass MyModel(nn.Module): ...\nmodel = MyModel.load_from_checkpoint(ckpt)\n// after\nclass MyModel(pl.LightningModule): ...\nmodel = MyModel.load_from_checkpoint(ckpt)","handlingStrategy":"type-guard","validationCode":"import lightning.pytorch as pl\nassert issubclass(cls, pl.LightningModule), \"load_from_checkpoint requires a LightningModule\"","typeGuard":"def is_lightning_module(cls) -> bool:\n    import lightning.pytorch as pl\n    return isinstance(cls, type) and issubclass(cls, pl.LightningModule)","tryCatchPattern":"try:\n    model = cls.load_from_checkpoint(ckpt)\nexcept NotImplementedError:\n    state = torch.load(ckpt, map_location=\"cpu\")[\"state_dict\"]\n    model = cls(); model.load_state_dict(state)","preventionTips":["Only call load_from_checkpoint on LightningModule subclasses","Keep manual torch.load fallback for plain nn.Module classes"],"tags":["lightning","checkpoint","not-implemented","lightningmodule"],"backgroundTag":"unsupported-class-type","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}