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?
- 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.2.tar.gz
(8.4 kB
view details)
Built Distribution
File details
Details for the file torch_onnx-0.0.2.tar.gz
.
File metadata
- Download URL: torch_onnx-0.0.2.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cdd9c391ba3a4bea01c5e5dc4d19df9b8b999527129fe059623735e41438600 |
|
MD5 | b338aebf03ff02556354392f5e1f2b63 |
|
BLAKE2b-256 | a9c844757fd123e50b43c6d4221ef772e76ab3d87756f4c4a5ac1a359d8ab888 |
File details
Details for the file torch_onnx-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: torch_onnx-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.1 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 | 6edd8aff1fd2eebd390dc518103550f3a67e7e803013fe058bc7654ee14fdab9 |
|
MD5 | ebb9d9020e490ba5b70068025e4ce537 |
|
BLAKE2b-256 | c7706cb53961c3ccc387775f5dd5a4ded0c6961ea83f0c28b957e0ff8f2a7a90 |