# PyTorch torch.load weights_only safe_globals documentation

Status: verified-page-ready
Product: PyTorch
Last verified: 2026-06-25
Canonical HTML: https://gitdocs.org/fix/pytorch-torch-load-weights-only-safe-globals-documentation
Machine JSON: https://gitdocs.org/api/fixes/pytorch-torch-load-weights-only-safe-globals-documentation.json

## Exact Symptom

- Unsupported global
- Please use torch.serialization.add_safe_globals

## Diagnosis

The allowlist must match the module path stored in the checkpoint. Importing a similarly named class from a different module path will not satisfy the safe loader.

## Fix

```
from torch.serialization import add_safe_globals, get_unsafe_globals_in_checkpoint
from myapp.models import MyModel

print(get_unsafe_globals_in_checkpoint("model.pt"))
add_safe_globals([MyModel])
model = torch.load("model.pt", weights_only=True)
```

## Avoid

- Do not assume the class name alone is enough; the checkpoint records fully qualified globals.

## Observed Codex Queries

- PyTorch torch.load weights_only safe_globals documentation
- site:pytorch.org/docs/stable torch.load weights_only safe_globals
- https://pytorch.org/docs/stable/generated/torch.load.html
- https://docs.pytorch.org/docs/stable/generated/torch.load.html
- 'weights_only' in https://docs.pytorch.org/docs/2.12/generated/torch.load.html

## Sources

- PyTorch 2.6 release: https://pytorch.org/blog/pytorch2-6/
- Official reference opened by Codex: https://pytorch.org/docs/stable/generated/torch.load.html
- Official reference opened by Codex: https://docs.pytorch.org/docs/stable/generated/torch.load.html
- Authoritative source: https://docs.pytorch.org/docs/stable/notes/serialization.html
