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")
# Or patch the torch.onnx export API
torch_onnx.patch_torch()
torch.onnx.export(...)
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?
- We need to verify torch.export coverage on Huggingface Optimum https://github.com/huggingface/optimum/tree/main/optimum/exporters/onnx; and they are not patching torch.onnx itself.
- Path torch.onnx.export such that packages do not need to change a single line to use dynamo
- We have all operators implemented and portable
Project details
Release history Release notifications | RSS feed
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.7.tar.gz
(27.3 kB
view details)
Built Distribution
File details
Details for the file torch_onnx-0.0.7.tar.gz
.
File metadata
- Download URL: torch_onnx-0.0.7.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 887ca33153907818848d7736f77a50e456e98556ae0aab1ea58259be6ca6bff6 |
|
MD5 | 9e3fd1c0d26c5304d933da38a387d2d5 |
|
BLAKE2b-256 | 60484d1bb2fa325df357a394b9a383090432b366961f9bb83dc2b9744a8b9e86 |
File details
Details for the file torch_onnx-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: torch_onnx-0.0.7-py3-none-any.whl
- Upload date:
- Size: 30.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aecd706870fabbc1e4101ff9f6eb37bb2e3e72c3b981392a9c9e00da18b69821 |
|
MD5 | b9b96c3372692dfb3df28c0e217e6b38 |
|
BLAKE2b-256 | 4f0e30f63045e22f1507762eb8a5fa4fda4186447f610938d3d7d3033f8bde4e |