Repository navigation
[Tencent Rhino-Bird 2026] pnnx support for PyTorch ExportedProgram (.pt2) #6975
geekgoer
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
pnnx support for PyTorch ExportedProgram (
.pt2)This project was developed for the 2026 Tencent Rhino-Bird Open Source Program. Its goal is to enable pnnx to directly convert models saved as PyTorch
ExportedProgrampackages:Author: @geekgoer
Pull request: Tencent/ncnn#6959
Development branch: geekgoer/ncnn:feat/pnnx-pt2
Status: pull request under review; upstream GitHub Actions are awaiting maintainer approval
Last updated: September 12, 2026
Goals and current status
pnnx model.pt2Design and implementation
A PT2 package contains a serialized ExportedProgram graph, a graph signature, metadata, and tensor payloads. The new C++ frontend performs the following steps:
The archive reader supports stored entries, central-directory indexing, data descriptors, ZIP64 metadata, bounds validation, and CRC checking. Compressed or encrypted entries are rejected explicitly, so no decompression library is introduced.
The generated
*_pnnx.pymodel also providesexport_exported_program(example_inputs=None). This enables the following round trip:Additional normalization was added for raw ExportedProgram forms including convolution, pooling, interpolation, instance normalization, recurrent networks, channel shuffle, triangular masking, windows, and scatter/slice-copy operations.
Validation
The main local environment was Windows, MSVC Release, and PyTorch 2.5.1 CPU.
maxdiff = 0.0);Review feedback has also resulted in focused fixes and regression coverage for:
bias=Falseandproj_size > 0;torch.fullnodes;Supported scope
Current limitations
Unsupported archive, schema, or graph features fail with explicit diagnostics rather than silently falling back to TorchScript.
Example
Export a model with PyTorch:
Convert it with pnnx:
Re-export the generated PNNX Python model as PT2:
python -c "import model_pnnx; model_pnnx.export_exported_program()"Links
Feedback and additional compatibility reports are welcome.
All reactions