THE FILE FIELD GUIDE
.pt2

PyTorch ExportedProgram

AI & Machine Learning

PT2 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.

Identify the purpose and distribution

Distinguish exported programs from compiled packages.

  1. Read the publisher instructions and license; record the producer, version and purpose.
  2. Check whether the producer used torch.export.save or AOTInductor packaging; record platform and target device.
  3. Retain the original and assemble configuration and companions in a working copy.
Inspect with the matching environment

Successful loading and correct inference are separate checks.

  1. Inspect producer PyTorch version and export/compile settings.
  2. Use compatible export.load for an ExportedProgram or the specified API for an AOT package.
  3. Compare input dimensions, types and dynamic-shape constraints with the producer’s example.
Test with a known input

Match the input contract and compare with a reference.

  1. Run once at the captured input shape and compare with reference output.
  2. For supported dynamic shapes, test boundary sizes within the declared range.
  3. Record runtime and required libraries and include these conditions when handing it over.

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

  1. Establish archive purpose and original model/export settings.
  2. Export from the compatible original model and compare constraints/results.
  3. 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

Related-format differences
FormatMain roleWhat to check
PT2Export/AOT packagingProducer API and input constraints
PTWeights/models etc.Multiple save methods
ONNXInference graph interchangeOpset/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: