Skip to main content

Open Neural Network Exchange

Project description

PyPI - Version CI CII Best Practices OpenSSF Scorecard REUSE compliant Ruff Black

Open Neural Network Exchange (ONNX) is an open ecosystem that empowers AI developers to choose the right tools as their project evolves. ONNX provides an open source format for AI models, both deep learning and traditional ML. It defines an extensible computation graph model, as well as definitions of built-in operators and standard data types. Currently we focus on the capabilities needed for inferencing (scoring).

ONNX is widely supported and can be found in many frameworks, tools, and hardware. Enabling interoperability between different frameworks and streamlining the path from research to production helps increase the speed of innovation in the AI community. We invite the community to join us and further evolve ONNX.

Use ONNX

Learn about the ONNX spec

Programming utilities for working with ONNX Graphs

Contribute

ONNX is a community project and the open governance model is described here. We encourage you to join the effort and contribute feedback, ideas, and code. You can participate in the Special Interest Groups and Working Groups to shape the future of ONNX.

Check out our contribution guide to get started.

If you think some operator should be added to ONNX specification, please read this document.

Community meetings

The schedules of the regular meetings of the Steering Committee, the working groups and the SIGs can be found here

Community Meetups are held at least once a year. Content from previous community meetups are at:

Discuss

We encourage you to open Issues, or use Slack (If you have not joined yet, please use this link to join the group) for more real-time discussion.

Follow Us

Stay up to date with the latest ONNX news. [Facebook] [Twitter]

Roadmap

A roadmap process takes place every year. More details can be found here

Installation

Official Python packages

ONNX released packages are published in PyPi.

pip install onnx  # or pip install onnx[reference] for optional reference implementation dependencies

ONNX weekly packages are published in PyPI to enable experimentation and early testing.

vcpkg packages

onnx is in the maintenance list of vcpkg, you can easily use vcpkg to build and install it.

git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat # For powershell
./bootstrap-vcpkg.sh # For bash
./vcpkg install onnx

Conda packages

A binary build of ONNX is available from Conda, in conda-forge:

conda install -c conda-forge onnx

Build ONNX from Source

Before building from source uninstall any existing versions of onnx pip uninstall onnx.

c++17 or higher C++ compiler version is required to build ONNX from source. Still, users can specify their own CMAKE_CXX_STANDARD version for building ONNX.

If you don't have protobuf installed, ONNX will internally download and build protobuf for ONNX build.

Or, you can manually install protobuf C/C++ libraries and tools with specified version before proceeding forward. Then depending on how you installed protobuf, you need to set environment variable CMAKE_ARGS to "-DONNX_USE_PROTOBUF_SHARED_LIBS=ON" or "-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF". For example, you may need to run the following command:

Linux:

export CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=ON"

Windows:

set CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=ON"

The ON/OFF depends on what kind of protobuf library you have. Shared libraries are files ending with *.dll/*.so/*.dylib. Static libraries are files ending with *.a/*.lib. This option depends on how you get your protobuf library and how it was built. And it is default OFF. You don't need to run the commands above if you'd prefer to use a static protobuf library.

Windows

If you are building ONNX from source, it is recommended that you also build Protobuf locally as a static library. The version distributed with conda-forge is a DLL, but ONNX expects it to be a static library. Building protobuf locally also lets you control the version of protobuf. The tested and recommended version is 3.21.12.

The instructions in this README assume you are using Visual Studio. It is recommended that you run all the commands from a shell started from "x64 Native Tools Command Prompt for VS 2019" and keep the build system generator for cmake (e.g., cmake -G "Visual Studio 16 2019") consistent while building protobuf as well as ONNX.

You can get protobuf by running the following commands:

git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout v21.12
cd cmake
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=<protobuf_install_dir> -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF .
msbuild protobuf.sln /m /p:Configuration=Release
msbuild INSTALL.vcxproj /p:Configuration=Release

Then it will be built as a static library and installed to <protobuf_install_dir>. Please add the bin directory(which contains protoc.exe) to your PATH.

set CMAKE_PREFIX_PATH=<protobuf_install_dir>;%CMAKE_PREFIX_PATH%

Please note: if your protobuf_install_dir contains spaces, do not add quotation marks around it.

Alternative: if you don't want to change your PATH, you can set ONNX_PROTOC_EXECUTABLE instead.

set CMAKE_ARGS=-DONNX_PROTOC_EXECUTABLE=<full_path_to_protoc.exe>

Then you can build ONNX as:

git clone https://github.com/onnx/onnx.git
cd onnx
git submodule update --init --recursive
# prefer lite proto
set CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON
pip install -e . -v

Linux

First, you need to install protobuf. The minimum Protobuf compiler (protoc) version required by ONNX is 3.6.1. Please note that old protoc versions might not work with CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON.

Ubuntu 20.04 (and newer) users may choose to install protobuf via

apt-get install python3-pip python3-dev libprotobuf-dev protobuf-compiler

In this case, it is required to add -DONNX_USE_PROTOBUF_SHARED_LIBS=ON to CMAKE_ARGS in the ONNX build step.

A more general way is to build and install it from source. See the instructions below for more details.

Installing Protobuf from source

Debian/Ubuntu:

  git clone https://github.com/protocolbuffers/protobuf.git
  cd protobuf
  git checkout v21.12
  git submodule update --init --recursive
  mkdir build_source && cd build_source
  cmake ../cmake -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
  make -j$(nproc)
  make install

CentOS/RHEL/Fedora:

  git clone https://github.com/protocolbuffers/protobuf.git
  cd protobuf
  git checkout v21.12
  git submodule update --init --recursive
  mkdir build_source && cd build_source
  cmake ../cmake  -DCMAKE_INSTALL_LIBDIR=lib64 -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
  make -j$(nproc)
  make install

Here "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" is crucial. By default static libraries are built without "-fPIC" flag, they are not position independent code. But shared libraries must be position independent code. Python C/C++ extensions(like ONNX) are shared libraries. So if a static library was not built with "-fPIC", it can't be linked to such a shared library.

Once build is successful, update PATH to include protobuf paths.

Then you can build ONNX as:

git clone https://github.com/onnx/onnx.git
cd onnx
git submodule update --init --recursive
# Optional: prefer lite proto
export CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON
pip install -e . -v

Mac

export NUM_CORES=`sysctl -n hw.ncpu`
brew update
brew install autoconf && brew install automake
wget https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protobuf-cpp-3.21.12.tar.gz
tar -xvf protobuf-cpp-3.21.12.tar.gz
cd protobuf-3.21.12
mkdir build_source && cd build_source
cmake ../cmake -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
make -j${NUM_CORES}
make install

Once build is successful, update PATH to include protobuf paths.

Then you can build ONNX as:

git clone --recursive https://github.com/onnx/onnx.git
cd onnx
# Optional: prefer lite proto
set CMAKE_ARGS=-DONNX_USE_LITE_PROTO=ON
pip install -e . -v

Verify Installation

After installation, run

python -c "import onnx"

to verify it works.

Common Build Options

For full list refer to CMakeLists.txt

Environment variables

  • USE_MSVC_STATIC_RUNTIME should be 1 or 0, not ON or OFF. When set to 1 onnx links statically to runtime library. Default: USE_MSVC_STATIC_RUNTIME=0

  • DEBUG should be 0 or 1. When set to 1 onnx is built in debug mode. or debug versions of the dependencies, you need to open the CMakeLists file and append a letter d at the end of the package name lines. For example, NAMES protobuf-lite would become NAMES protobuf-lited. Default: Debug=0

CMake variables

  • ONNX_USE_PROTOBUF_SHARED_LIBS should be ON or OFF. Default: ONNX_USE_PROTOBUF_SHARED_LIBS=OFF USE_MSVC_STATIC_RUNTIME=0 ONNX_USE_PROTOBUF_SHARED_LIBS determines how onnx links to protobuf libraries.

    • When set to ON - onnx will dynamically link to protobuf shared libs, PROTOBUF_USE_DLLS will be defined as described here, Protobuf_USE_STATIC_LIBS will be set to OFF and USE_MSVC_STATIC_RUNTIME must be 0.
    • When set to OFF - onnx will link statically to protobuf, and Protobuf_USE_STATIC_LIBS will be set to ON (to force the use of the static libraries) and USE_MSVC_STATIC_RUNTIME can be 0 or 1.
  • ONNX_USE_LITE_PROTO should be ON or OFF. When set to ON onnx uses lite protobuf instead of full protobuf. Default: ONNX_USE_LITE_PROTO=OFF

  • ONNX_WERROR should be ON or OFF. When set to ON warnings are treated as errors. Default: ONNX_WERROR=OFF in local builds, ON in CI and release pipelines.

Common Errors

  • Note: the import onnx command does not work from the source checkout directory; in this case you'll see ModuleNotFoundError: No module named 'onnx.onnx_cpp2py_export'. Change into another directory to fix this error.

  • If you run into any issues while building Protobuf as a static library, please ensure that shared Protobuf libraries, like libprotobuf, are not installed on your device or in the conda environment. If these shared libraries exist, either remove them to build Protobuf from source as a static library, or skip the Protobuf build from source to use the shared version directly.

  • If you run into any issues while building ONNX from source, and your error message reads, Could not find pythonXX.lib, ensure that you have consistent Python versions for common commands, such as python and pip. Clean all existing build files and rebuild ONNX again.

Testing

ONNX uses pytest as test driver. In order to run tests, you will first need to install pytest:

pip install pytest nbval

After installing pytest, use the following command to run tests.

pytest

Development

Check out the contributor guide for instructions.

License

Apache License v2.0

Code of Conduct

ONNX Open Source Code of Conduct

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

onnx_weekly-1.18.0.dev20240923.tar.gz (11.4 MB view details)

Uploaded Source

Built Distributions

onnx_weekly-1.18.0.dev20240923-cp312-cp312-win_amd64.whl (14.6 MB view details)

Uploaded CPython 3.12 Windows x86-64

onnx_weekly-1.18.0.dev20240923-cp312-cp312-win32.whl (14.5 MB view details)

Uploaded CPython 3.12 Windows x86

onnx_weekly-1.18.0.dev20240923-cp312-cp312-macosx_12_0_universal2.whl (16.7 MB view details)

Uploaded CPython 3.12 macOS 12.0+ universal2 (ARM64, x86-64)

onnx_weekly-1.18.0.dev20240923-cp311-cp311-win_amd64.whl (14.6 MB view details)

Uploaded CPython 3.11 Windows x86-64

onnx_weekly-1.18.0.dev20240923-cp311-cp311-win32.whl (14.5 MB view details)

Uploaded CPython 3.11 Windows x86

onnx_weekly-1.18.0.dev20240923-cp311-cp311-macosx_12_0_universal2.whl (16.7 MB view details)

Uploaded CPython 3.11 macOS 12.0+ universal2 (ARM64, x86-64)

onnx_weekly-1.18.0.dev20240923-cp310-cp310-win_amd64.whl (14.6 MB view details)

Uploaded CPython 3.10 Windows x86-64

onnx_weekly-1.18.0.dev20240923-cp310-cp310-win32.whl (14.4 MB view details)

Uploaded CPython 3.10 Windows x86

onnx_weekly-1.18.0.dev20240923-cp310-cp310-macosx_12_0_universal2.whl (16.7 MB view details)

Uploaded CPython 3.10 macOS 12.0+ universal2 (ARM64, x86-64)

onnx_weekly-1.18.0.dev20240923-cp39-cp39-win_amd64.whl (14.5 MB view details)

Uploaded CPython 3.9 Windows x86-64

onnx_weekly-1.18.0.dev20240923-cp39-cp39-win32.whl (14.4 MB view details)

Uploaded CPython 3.9 Windows x86

onnx_weekly-1.18.0.dev20240923-cp39-cp39-macosx_12_0_universal2.whl (16.7 MB view details)

Uploaded CPython 3.9 macOS 12.0+ universal2 (ARM64, x86-64)

onnx_weekly-1.18.0.dev20240923-cp38-cp38-win_amd64.whl (14.6 MB view details)

Uploaded CPython 3.8 Windows x86-64

onnx_weekly-1.18.0.dev20240923-cp38-cp38-win32.whl (14.4 MB view details)

Uploaded CPython 3.8 Windows x86

onnx_weekly-1.18.0.dev20240923-cp38-cp38-macosx_12_0_universal2.whl (16.7 MB view details)

Uploaded CPython 3.8 macOS 12.0+ universal2 (ARM64, x86-64)

File details

Details for the file onnx_weekly-1.18.0.dev20240923.tar.gz.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923.tar.gz
Algorithm Hash digest
SHA256 9ea6cfd2986631de60cfe86982fcf7a38fd8818d112b5cd40c547099c0b1dca5
MD5 531663e169a9be196f12d70a4f7f60e1
BLAKE2b-256 66793d8abe2312ed67bfdc93c9c834a0429f794337e005aadb2f2b2a9ffbd10f

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7c4badad8e75f63740744992b8ec394e1e39d21fcd64454dda00424b6397748d
MD5 ca7be116066f0b4bb5ad0c61d8acc705
BLAKE2b-256 c52a1d4b9bbbd862687b311b19bb08c5e9e8eeb04f4cd65c02d7413e99b95dab

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 6550fd297c73e7a3eaf38dc5537e655203306b114b0994ceea97ad8f6f1119c5
MD5 9d12335564eb78d5164fbc2581b8f33a
BLAKE2b-256 4bcc90ba8a9f7a1238c236677083fccde1a8220b48bc5317927a59d341d32a10

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp312-cp312-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp312-cp312-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 50be8e8655372a95e5250e16648761b61fde7917a52d99abe139feac54159383
MD5 f90aadf4c5466a6e2f79bfbeed03803a
BLAKE2b-256 575f2ab518daa7b343e391824512d101a8887cff8fa5c071faf7fe96fb471ec2

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b163108c3eb49334be62e04fe1c06cf298a744758c9c032b03d930f99081e7ed
MD5 ad4cae89f7040bafbbcf9cf0db8227c9
BLAKE2b-256 9df868d554150da9eb53e06a28d93b80a35a0363b4b9948502f6a00bc9c1b4e6

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 10f8797630fe3b62ceda0bdb5401ce5a87769bea32a82c6b8a2e191b048f6290
MD5 fa37b38e0fff8ee0a08b9f4fb113dc0f
BLAKE2b-256 bc28683a7c9a687ca8069daf772844f6c5dd8c7c894a4b36549439690dc63cfa

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp311-cp311-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp311-cp311-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 36ad111d209e5581c62def91656fa4d86f9b76930353538ff6ab09cc25e0c7b1
MD5 73c6e2a57360de9e3c2704d639dcfc23
BLAKE2b-256 010707441a2a38287b3b93c928a49542bcc8f62b7d032609f650f516f15b126d

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 677e300fa2d60744a9ee7aab0b6189147ec3b91018ef9297f2e866ce015e0ac3
MD5 a01cb4cc8a1879e401da6f6d8a7a08dc
BLAKE2b-256 8f7c9e558c489928330c4955df95081c4beaa025532b3f9335988d0040ad9e6b

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp310-cp310-win32.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 8e464924c1358708b6f038262ad15724c4bd11aa6279c33758d4002dc6e094c9
MD5 dc57d8878c628c055496c14a1c8ac511
BLAKE2b-256 86537bac7c44765e5416030615e7dae4367b65525c2f1fcb077308f96946e7e2

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp310-cp310-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp310-cp310-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 ebef342d9de67c6296c446ca6669728703ccbad250c9243d2d4f2e9493437e45
MD5 9c4797baa2f9b575c93d989faceeee9d
BLAKE2b-256 b6063a75ab5f9a63935e3b517f30c5d8432b7083d0a98389d926ec559a113b31

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 359f268015c366c755835a63feb677fa3062de1d40e7d507d22d751eae7a51f0
MD5 d6b7a405b6700774e21a016878748fab
BLAKE2b-256 840240eb62dbb12cfc216b5a1c1048c2b93d66b5e953a7bd7f00702fcf0d042d

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp39-cp39-win32.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 027b7bd32b288d54161b56d409fe12e6781b3d9a8d582c1465338d9b07371c4b
MD5 37e9174563719dfce3ba9a4dfc93bd57
BLAKE2b-256 a023dbf367fe419dd122722e12f3397927f4706791d6436f695e6620c406c5e0

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp39-cp39-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp39-cp39-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 7d328016c29645e3f7e3804f141aba9b754695acb064328bec837adfe1caa921
MD5 bbc77bee57ab4c67370db15c2bdded8c
BLAKE2b-256 c6e223ee3f439f656563feefe45a60552a3a84f2ad7f43eac6eed5ebbebbe6d7

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 7d76956e079f3528d73193f7143a4b2c35feed0bfc0156b8967120b74de58293
MD5 281746f3d587787ed6b89a6dd412fc60
BLAKE2b-256 59611ca8d3f67c6501dc97558f4440f65cccbd1ab909b8120dd8ef6d2b1145e9

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp38-cp38-win32.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 2ac80a83c2dc527f1ea375bfd00cebae4865313b0400d72a36f7ba6d3c63284e
MD5 16dfe43881ec4708dc807c4be1bbe8d8
BLAKE2b-256 d793469ce2f22a579ce9efb8a1d1ac876c7b7fc831ccd34c7756fcbe031093cf

See more details on using hashes here.

File details

Details for the file onnx_weekly-1.18.0.dev20240923-cp38-cp38-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for onnx_weekly-1.18.0.dev20240923-cp38-cp38-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 d49f15ab2e595e96ea33597c034a595cda3f7bdd6c8ad0af6237fcb171609f87
MD5 145c1be8e181901a16ab3642bded8e71
BLAKE2b-256 79d6b000e63a4728dd855a2ae0276efcee1daf3703150412ce080bfcca735de2

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