PyTorch Model / Checkpoint
AI & Machine LearningPT is used for PyTorch data, but may contain a state dictionary, entire model, checkpoint or other payload. Identify the save method and required model definitions rather than guessing from the suffix.
- What it is used for
- Model weights, checkpoints and other saved data
- What the file contains
- Binary data
All sections, questions and sources
Content reviewed: · Editor:Kai
Opening steps
Choose your environment or purpose to see its steps.
Menu labels and support vary by app, OS and version. Preserve the original before making changes.
Troubleshooting by symptom
- Key/shape mismatch: compare architecture, version and parameter names.
- Missing class: whole-model serialization can depend on the original definitions.
- Restricted loading fails: identify the format/origin rather than disabling protections.
- No CUDA available: consider supported CPU mapping rather than restoring to the saved GPU.
- Restricted loading rejects it: identify serialization and objects instead of disabling it blindly.
- Ignoring keys with strict=False: investigate architectural differences before accepting unloaded layers.
Use PT weights / export to ONNX or another format
- Load trusted weights into the correct architecture and validate inputs/results.
- Use a supported exporter and compare outputs, precision and memory requirements.
- Compare output shapes, values and timing with the same input before/after export; retain definitions and export settings.
Weights without an architecture may be insufficient; renaming PT to GGUF is not conversion.
Why the save code matters
The suffix can cover weight dictionaries, training checkpoints, whole models and TorchScript; choosing a loader by suffix can misidentify the artifact.
Obtain definitions and a loading example from the producer when save code is unavailable; avoid executing unknown files by trial and error.
Source for these steps:PyTorch Project · Saving and Loading Models / PyTorch Project · torch.load / PyTorch Project · Serialization semantics
Why loaded weights can give different predictions
Check evaluation behavior, preprocessing and label order; readable weights do not establish correct inference.
Retain architecture, versions, test input and output; training resumption also needs appropriate optimizer and other state.
Source for these steps:PyTorch Project · Saving and Loading Models / PyTorch Project · torch.load / PyTorch Project · Serialization semantics
Related-format differences
| Format | Main role | What to check |
|---|---|---|
| PT / PTH | Conventional PyTorch suffixes | Identify the save API |
| PT2 | Export/compiled package | Use the appropriate specialized loader |
| SAFETENSORS | Tensor storage | Distinct from complete training state |
Handling and security
Loading serialized data can involve code-execution risks depending on its format. Do not load untrusted PT; weights_only alone is not a complete safety guarantee.
Questions and answers
Is every PT a weight file?
It may hold weights, a whole model, checkpoints or other data.
Can weights alone run inference?
The correct architecture, configuration and preprocessing are needed.
Should I disable protections to fix loading?
No; inspect origin and save method first.
Is PT structurally different from PTH?
They are naming conventions; identify the format from the save API and documentation.
Does CPU mapping convert the model format?
It changes storage placement, not architecture or serialization format.
Format facts: name, steward and MIME type
- Formal name
- PyTorch checkpoint or producer-specific data
- Steward / specification
- PyTorch project / producing application
- MIME type
- Depends on the producer or server; an extension alone does not establish a MIME type.
Primary and official sources
- Project documentationSaving and Loading Models
Explains state dictionaries versus whole-model serialization.
PyTorch Project · Link checked: - Project documentationtorch.load
Documents weights_only, device mapping and untrusted-file warnings.
PyTorch Project · Link checked: - Official documentationSerialization semantics
Explains weights_only restrictions and untrusted artifacts.
PyTorch Project · Link checked: