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.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

torch_onnx-0.0.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torch_onnx-0.0.1.tar.gz
  • Upload date:
  • Size: 8.2 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.1.tar.gz
Algorithm Hash digest
SHA256 b59e97d25c6d951174646ee04f2ceb7f5787b44a70928c4f0c13646114a4b7e7
MD5 0dc53617760dc32d9bc79becbb8d0019
BLAKE2b-256 75bcb5458199ef85501314a47cd2d9f2cc3637650f55e29ea811e8f3ad3258dc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torch_onnx-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ede787183363eefd29bb78dc311e8ec1af8e7ae70ed10ffede7ff56f51f33ae
MD5 fe5506d4d8896c131cd5bced9a90a57f
BLAKE2b-256 c2000f206c95430c9e7ea68cf8492fa5a12f64ac93e978d8a0e00c7980033d98

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