Skip to main content

Experimental tools for converting PyTorch models to ONNX

Project description

PyTorch to ONNX Exporter

Experimental torch ONNX exporter.

[!WARNING] This is an experimental project and is not designed for production use. Use torch.onnx.export for these purposes.

Installation

pip install torch-onnx

Usage

import torch
import torch_onnx
from onnxscript import ir
import onnx

# Get an exported program with torch.export
exported = torch.export.export(...)
model = torch_onnx.exported_program_to_ir(exported)
proto = ir.to_proto(model)
# This will give you an ATen dialect graph (un-lowered ONNX graph with ATen ops)
onnx.save(proto, "model.onnx")

Design

{ExportedProgram, jit} -> {ONNX IR} -> {torchlib} -> {ONNX}

  • Flat graph; Scope info as metadata, not functions
    • Because existing tools are not good at handling them
  • Eager optimization where appropriate
    • Because exsiting tools are not good at optimizing
  • Drop in replacement for torch.onnx.export
    • Minimum migration effort
  • Use ExportedProgram
    • Rely on robustness of the torch.export implementation
    • This does not solve dynamo limitations, but it avoids introducing additional breakage by running fx passes
  • Build graph eagerly, in place
    • Expose shape and dtype information to the op functions; build with IR

Why is this doable?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_onnx-0.0.4.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

torch_onnx-0.0.4-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file torch_onnx-0.0.4.tar.gz.

File metadata

  • Download URL: torch_onnx-0.0.4.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.9

File hashes

Hashes for torch_onnx-0.0.4.tar.gz
Algorithm Hash digest
SHA256 a802fc4f9f6f840a22fe78eec7876c6d4c954c55c58572d92164bddc1e366eaa
MD5 9b8fd33df7c7fd8957b032c6895e949e
BLAKE2b-256 58df6b62d2cbe2361d9f3c3d13c2a3ce61bb3ea62b5a2e3c4517d704e5f12e02

See more details on using hashes here.

File details

Details for the file torch_onnx-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: torch_onnx-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.9

File hashes

Hashes for torch_onnx-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1362a73ba4ad5c747bf57fde69c5e9b21d2ced86e3641d7ffef2be31428f5072
MD5 ba46cca785864c581e18fa18d61477d2
BLAKE2b-256 ebb2e2c995efdf519b65e0b96229a991a22ceb3b2c10ea752b82739974996724

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page