Lightning-AI/pytorch-lightning · error · NotImplementedError
Unsupported {cls}
Error message
Unsupported {cls} What it means
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.
Source
Thrown at src/lightning/pytorch/core/saving.py:109
# for past checkpoint need to add the new key
checkpoint.setdefault(cls.CHECKPOINT_HYPER_PARAMS_KEY, {})
# override the hparams with values that were passed in
checkpoint[cls.CHECKPOINT_HYPER_PARAMS_KEY].update(kwargs)
if issubclass(cls, pl.LightningDataModule):
return _load_state(cls, checkpoint, **kwargs)
if issubclass(cls, pl.LightningModule):
model = _load_state(cls, checkpoint, strict=strict, **kwargs)
state_dict = checkpoint["state_dict"]
if not state_dict:
rank_zero_warn(f"The state dict in {checkpoint_path!r} contains no parameters.")
return model
device = next((t for t in state_dict.values() if isinstance(t, torch.Tensor)), torch.tensor(0)).device
assert isinstance(model, pl.LightningModule)
return model.to(device)
raise NotImplementedError(f"Unsupported {cls}")
def _default_map_location(storage: "UntypedStorage", location: str) -> Optional["UntypedStorage"]:
if (
location.startswith("mps")
and not MPSAccelerator.is_available()
or location.startswith("cuda")
and not CUDAAccelerator.is_available()
or location.startswith("xla")
and not XLAAccelerator.is_available()
):
return storage.cpu()
return None # default behavior by `torch.load()`
def _load_state(
cls: Union[type["pl.LightningModule"], type["pl.LightningDataModule"]],
checkpoint: dict[str, Any],View on GitHub (pinned to 9fed5c27d2)
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)
Example fix
// before class MyModel(nn.Module): ... model = MyModel.load_from_checkpoint(ckpt) // after class MyModel(pl.LightningModule): ... model = MyModel.load_from_checkpoint(ckpt)
Defensive patterns
Strategy: type-guard
Validate before calling
import lightning.pytorch as pl assert issubclass(cls, pl.LightningModule), "load_from_checkpoint requires a LightningModule"
Type guard
def is_lightning_module(cls) -> bool:
import lightning.pytorch as pl
return isinstance(cls, type) and issubclass(cls, pl.LightningModule) Try / catch
try:
model = cls.load_from_checkpoint(ckpt)
except NotImplementedError:
state = torch.load(ckpt, map_location="cpu")["state_dict"]
model = cls(); model.load_state_dict(state) Prevention
- Only call load_from_checkpoint on LightningModule subclasses
- Keep manual torch.load fallback for plain nn.Module classes
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The `{type(self).__name__}` does not use the `CheckpointIO`
- The `{type(self).__name__}` does not support setting a `Chec
- Loading a single optimizer object from a checkpoint is not s
- Could not find a distributed model in the provided checkpoin
- Found multiple distributed models in the given state. Loadin
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/3d4d0e1d46a86cdb.
Report an issue: GitHub.