PyTorch ExportedProgram
AI & Machine LearningPT2 archives support PyTorch export and AOTInductor workflows. A saved ExportedProgram and compiled model package require different restoration/runtime procedures. ZIP-based structure does not imply safe execution after extraction.
- What it is used for
- Persisting exported programs or compiled artifacts
- 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
- Wrong loader: distinguish export persistence from compiled artifacts.
- Input rejected: inspect captured shape/type/range constraints.
- Environment mismatch: compare version, device and compile requirements.
- torch.load fails: use the API corresponding to export or compiled packaging.
- Resizing violates constraints: inspect fixed axes and range limits.
- Different OS/GPU fails: inspect compilation requirements and consider rebuilding from the source.
PT2 → re-export the original model to the required format
- Establish archive purpose and original model/export settings.
- Export from the compatible original model and compare constraints/results.
- Compare output shapes, values and timing with the same input before/after export; retain definitions and export settings.
Compiled artifacts do not guarantee reconstruction of the training model; renaming to PT/ONNX is not conversion.
Why PT2 has different loading workflows
PT2 packaging is used for exported programs and AOTInductor artifacts, so a suffix does not select one universal loader.
Include the save API and captured inputs; retaining the original model/settings supports rebuilding for a new environment.
Source for these steps:PyTorch Project · PT2 Archive Spec / PyTorch Project · torch.export API Reference
Checking shape constraints and compatibility
Distinguish dynamic batching from dynamic image dimensions; values outside captured constraints may be rejected.
Serialization and package compatibility depend on versions; verify producer and consumer rather than assuming arbitrary cross-version loading.
Source for these steps:PyTorch Project · PT2 Archive Spec / PyTorch Project · torch.export API Reference
Related-format differences
| Format | Main role | What to check |
|---|---|---|
| PT2 | Export/AOT packaging | Producer API and input constraints |
| PT | Weights/models etc. | Multiple save methods |
| ONNX | Inference graph interchange | Opset/runtime compatibility |
Handling and security
Use trusted PT2 producers only. Compiled archives can include native code; distinguish inspecting/extracting contents from executing them. Do not run unfamiliar runtimes or companion code.
Questions and answers
Can torch.export.load open every PT2?
Compiled packaging and other workflows require their appropriate procedures.
Does ZIP structure mean an ordinary document?
Executable artifacts can be included.
Can input sizes change freely?
Check captured export/compile constraints.
Can renaming PT2 to PT make it loadable?
The structure and purpose remain unchanged; use the loader matching its creation process.
Should I extract and run its files?
Executable artifacts may be present; follow trusted producer instructions.
Format facts: name, steward and MIME type
- Formal name
- PyTorch PT2 archive
- Steward / specification
- PyTorch Project
- MIME type
- Depends on the producer or server; an extension alone does not establish a MIME type.
Primary and official sources
- Project documentationPT2 Archive Spec
Documents PT2 packaging for exported programs and AOTInductor artifacts.
PyTorch Project · Link checked: - Project documentationtorch.export API Reference
Reference for ExportedProgram serialization and compatibility.
PyTorch Project · Link checked: