skillfed

pnnx

pnnx is an open standard for PyTorch model interoperability.

pnnx v20260526 227.5K downloads/30d#9,175 on PyPI23,698
Permissive license BSD-3 Active released

What it is and what it does

PNNX is a Python wrapper around an open standard for PyTorch model interoperability. It takes trained PyTorch models and exports them to PNNX format, which generates multiple output artifacts: a graph definition file, model weights, and Python inference code. The package can also convert existing TorchScript models to PNNX. The main use case is preparing PyTorch models for deployment or cross-framework use by optimizing the computation graph and making the model portable across different inference engines.

The package depends only on torch and provides two main functions: export (which traces a model and converts it to PNNX) and convert (which transforms an already-saved TorchScript model). It supports custom operators, module preservation, and multiple optimization levels. The fact sheet shows it is actively maintained, has no known vulnerabilities, and runs on modern Python versions across major platforms via pre-built wheels.

Use it for:

  • Export a trained PyTorch model to PNNX format for deployment on inference engines.
  • Convert a PyTorch model to alternative formats via the PNNX intermediate representation.
  • Optimize a model graph for inference by applying graph-level optimizations during export.
  • Generate portable Python inference code alongside model weights for reproducible model loading.
  • Handle models with dynamic input shapes by specifying alternative input shapes during export.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Exports and converts PyTorch neural network models to PNNX format, an open standard for model interoperability that generates optimized graph definitions, weights, and inference code.

Yes, if you need to export PyTorch models to PNNX format for deployment or cross-framework use. The package is actively maintained, has no security issues, and provides pre-built wheels for common platforms. Install friction is moderate due to the torch dependency, but that is expected for a PyTorch model tool. Not necessary if you only work within PyTorch's native ecosystem.

Install

pnnx on PyPI

pip

pip install pnnx

uv

uv add pnnx

poetry

poetry add pnnx

Installing pnnx

Before you install

Medium install friction due to torch dependency and platform-specific wheels. The package is actively maintained with recent releases and no known vulnerabilities. Supports Python 3.7 through 3.11 across macOS, Linux, and Windows.

License in practice

BSD-3 is permissive, allowing commercial and private use with minimal restrictions. You must include the license text in distributions but face no copyleft obligations.

Quickstart

pip install pnnx

import torch
import pnnx

net = torch.nn.Linear(10, 2)
x = torch.rand(1, 10)
opt_net = pnnx.export(net, "model.pt", x)

Requires torch to be installed; building from source requires C++14 compiler support and CMake >= 3.4.

Verify before relying

  • Whether pnnx2onnx and torchvision integration are enabled by default or require manual environment variable setup.
  • Performance characteristics and optimization level differences for typical model sizes.
  • Compatibility with dynamic shapes and practical limits of input_shapes2 resolution.

Package facts

License BSD-3 (permissive)
Python support supports the current Python release (>=3.7)
Install friction medium — platform-specific wheel
Runtime dependencies 1 — torch
Maintenance actively maintained — 80 days since the last release
Last repo commit
First released
Downloads 227,549/month — #9,175 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pnnx-20260526-py3-none-macosx_10_9_universal2.macosx_10_9_x86_64.macosx_11_0_arm64.whl; pnnx-20260526-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; pnnx-20260526-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; pnnx-20260526-py3-none-win_amd64.whl

License :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: C++Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

pytorch model exportneural network model conversionpnnx format exporttorch model optimizationmodel interoperability standardtorchscript model exportpytorch graph optimization
model-exportpytorch-toolsneural-network-optimization

More Artificial Intelligence packages