Lightning-AI/pytorch-lightning · critical · ValueError
The instantiator {instantiator_path!r} from the checkpoint i
Error message
The instantiator {instantiator_path!r} from the checkpoint is not in the allowlist of trusted instantiators and was blocked to prevent arbitrary code execution. If you trust this checkpoint, add the path to `lightning.pytorch.core.saving._ALLOWED_INSTANTIATORS` before loading. What it means
Security guard in _load_state: checkpoints may embed an `_instantiator` entry naming a callable (module.path.to.fn) that Lightning will import and call to rebuild the object. Because that is arbitrary code execution, the path must appear in the explicit allowlist `lightning.pytorch.core.saving._ALLOWED_INSTANTIATORS` or loading aborts.
Source
Thrown at src/lightning/pytorch/core/saving.py:166
cls_kwargs_loaded.update(checkpoint.get(cls.CHECKPOINT_HYPER_PARAMS_KEY, {}))
# 3. Ensure that `cls_kwargs_old` has the right type, back compatibility between dict and Namespace
cls_kwargs_loaded = _convert_loaded_hparams(cls_kwargs_loaded, checkpoint.get(cls.CHECKPOINT_HYPER_PARAMS_TYPE))
# 4. Update cls_kwargs_new with cls_kwargs_old, such that new has higher priority
args_name = checkpoint.get(cls.CHECKPOINT_HYPER_PARAMS_NAME)
if args_name and args_name in cls_init_args_name:
cls_kwargs_loaded = {args_name: cls_kwargs_loaded}
_cls_kwargs = {}
_cls_kwargs.update(cls_kwargs_loaded)
_cls_kwargs.update(cls_kwargs_new)
instantiator = None
instantiator_path = _cls_kwargs.pop("_instantiator", None)
if instantiator_path is not None:
if instantiator_path not in _ALLOWED_INSTANTIATORS:
raise ValueError(
f"The instantiator {instantiator_path!r} from the checkpoint is not in the allowlist of trusted"
" instantiators and was blocked to prevent arbitrary code execution. If you trust this checkpoint,"
" add the path to `lightning.pytorch.core.saving._ALLOWED_INSTANTIATORS` before loading."
)
module_path, name = instantiator_path.rsplit(".", 1)
instantiator = getattr(__import__(module_path, fromlist=[name]), name)
if not cls_spec.varkw:
# filter kwargs according to class init unless it allows any argument via kwargs
_cls_kwargs = {k: v for k, v in _cls_kwargs.items() if k in cls_init_args_name}
obj = instantiator(cls, _cls_kwargs) if instantiator else cls(**_cls_kwargs)
if isinstance(obj, pl.LightningDataModule):
if obj.__class__.__qualname__ in checkpoint:
obj.load_state_dict(checkpoint[obj.__class__.__qualname__])
return obj
View on GitHub (pinned to 9fed5c27d2)
Solutions
- Inspect checkpoint['hyper_parameters']['_instantiator'] with torch.load to see the path
- If you trust the source, append the path: from lightning.pytorch.core.saving import _ALLOWED_INSTANTIATORS; _ALLOWED_INSTANTIATORS.add(path) before loading
- Otherwise strip the key: pop '_instantiator' from the checkpoint's hyper_parameters and load without it
Example fix
// before
model = MyModel.load_from_checkpoint(ckpt) # ValueError: instantiator blocked
// after
from lightning.pytorch.core.saving import _ALLOWED_INSTANTIATORS
_ALLOWED_INSTANTIATORS.add("litdata.streaming.ini")
model = MyModel.load_from_checkpoint(ckpt) Defensive patterns
Strategy: validation
Validate before calling
ckpt = torch.load(path, map_location="cpu", weights_only=False)
inst = ckpt.get("hyper_parameters", {}).get("_instantiator")
if inst is not None and inst not in _ALLOWED_INSTANTIATORS:
# decide: trust it or strip it
ckpt["hyper_parameters"].pop("_instantiator") Try / catch
from lightning.pytorch.core.saving import _ALLOWED_INSTANTIATORS
try:
model = cls.load_from_checkpoint(p)
except ValueError as e:
if "_ALLOWED_INSTANTIATORS" in str(e) and trust_source:
_ALLOWED_INSTANTIATORS.add(extract_path_from(e))
else:
raise Prevention
- Only load checkpoints from trusted sources
- Inspect _instantiator before loading untrusted checkpoints
- Keep the allowlist modification scoped and audited
When it happens
Trigger: Loading a checkpoint saved by Lightning AI's studio/app flows (or a crafted one) whose hyperparameters contain `_instantiator='some.module.fn'` where 'some.module.fn' is not in the allowlist.
Common situations: Downloading or receiving a checkpoint created elsewhere (studio export, another org, tutorial artifact) and calling load_from_checkpoint on it; the embedded instantiator path is not one Lightning trusts by default.
Related errors
- Could not find a distributed model in the provided checkpoin
- Found multiple distributed models in the given state. Loadin
- The path {str(path)!r} does not point to a valid checkpoint.
- Failed to load checkpoint directly into the model. The given
- The model contains a key '{full_param_name}' that does not e
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/de68aa0033e5e93b.
Report an issue: GitHub.