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

Uploaded Source

Built Distribution

torch_onnx-0.0.3-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torch_onnx-0.0.3.tar.gz
  • Upload date:
  • Size: 8.9 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.3.tar.gz
Algorithm Hash digest
SHA256 19ae00d516a3862ac0ff992ca373f7c171e8d37f7828c2b075256808c791b9db
MD5 2e674292c26cf79c5c45872c70eb78f4
BLAKE2b-256 4fbf78b221e6abd1d065a932cb9b86c41585a04c4182c6cc2a76beaf85d23057

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torch_onnx-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6c516ec6a913a3ec4c51eddcc9a8f4d784c47fdad374c0a1caf566054cf81ba1
MD5 dc550328c8c0969aaaddfc30e300a743
BLAKE2b-256 d2bc180fe262521a9107d8b6a79ac109e59ac9f0baf489684e5a90be4d2e7165

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