* Support quantization linear binary element wise math ops, implement QLinearAdd.
Support tests for quantization linear binary element wise math ops, implement test for QLinearAdd.
Add QlinearAdd with SSE2 intrisinc implemntation, Avx2 assembly implemntation, Neon intrisinc support.
QLinearAdd support VectorOnVector, VectorOnScalar, ScalarOnVector.
Generalized QlinearBinaryOp parallel related with broadcasting.
* Modify according to PR feedbacks. Mainly:
* template helper for generalize the qladd logic on v2v, s2v, v2s
* remove GetKernel related.
* change mixed lagecy MM/SSE code in the AVX code
* formater, typos, convensions, etc.
* Utilize MlasSubtractInt32x4 in MlasDequantizeLinearVector().
* Some format fix.
* More nature parallel parameter type.
* Fix build break for x86.
* Comment goes to 80 before wrap.
* Many change on assembly on Marco related.
Using vminps than vpminsd to handle NaN.
tested on windows.
* Using CLang Format to format the file.
* Fix arm32 build error.
* Remove some duplicate in different #if defined
* working add.u8.vector to vector
* Fix runtime bus error on real arm32 linux.
* fix typo in store last one lane.
* arm32 qlinearadd handle scalar.
* Move qladd to seperate c++ file
* Add neon64 qladd.
* refactor some, enhance two instructions on arm64 only instructions
* Fix typo for arm64
* use strict op in pure c++ (min/max on float value)
* sse2 new version.
* mrege arm/sse2/avx2
* pass arm/sse/avx2 linux test
* remove non-used assembly file.
* Remove unused data definition and tailing spaces.
* Fix broadcasting parallel issue.
* Enhance broadcasting scenarios. Allow testing result diff due to round
on half.
* Add Mlas or MLAS_ prefix for namespace safety.
* Handle alignment issue for arm32 for GCC/MSVC. remove some unused
signed/unsigned int ops.
* Specify /arch:AVX2 for qladd_avx2.cpp
* Fix type during copy/paste when unrolling. Better one GreatEqual
condition. Better formater by splitting two statements on single line.
* Arm neon alignment parameter is bits rather than bytes, change it.
* Move qladd_avx2.cpp to intrinsics/avx2/ folder
* Formatting using mlas style.
* Double check mlas style for these files.
* change indent 2 to 4 for qladd_avx2.cpp
* Fix windows x86 build error due to sse2 no _mm_cvtsi128_si64
* To re-trigger all as old failed pipeline updated.
Co-authored-by: Lei Zhang <phill.zhang@gmail.com>
|
||
|---|---|---|
| .github | ||
| cgmanifests | ||
| cmake | ||
| csharp | ||
| dockerfiles | ||
| docs | ||
| include/onnxruntime/core | ||
| java | ||
| nodejs | ||
| onnxruntime | ||
| orttraining | ||
| package/rpm | ||
| samples | ||
| server | ||
| tools | ||
| winml | ||
| .clang-format | ||
| .clang-tidy | ||
| .dockerignore | ||
| .flake8 | ||
| .gitattributes | ||
| .gitignore | ||
| .gitmodules | ||
| build.amd64.1411.bat | ||
| build.bat | ||
| BUILD.md | ||
| build.sh | ||
| CODEOWNERS | ||
| CONTRIBUTING.md | ||
| LICENSE | ||
| NuGet.config | ||
| ort.wprp | ||
| packages.config | ||
| README.md | ||
| requirements-dev.txt | ||
| requirements-doc.txt | ||
| requirements.txt | ||
| setup.py | ||
| ThirdPartyNotices.txt | ||
| VERSION_NUMBER | ||

ONNX Runtime is a cross-platform inferencing and training accelerator compatible with many popular ML/DNN frameworks, including PyTorch, TensorFlow/Keras, scikit-learn, and more. aka.ms/onnxruntime
Many users can benefit from ONNX Runtime, including those looking to:
- Improve inference performance for a wide variety of ML models
- Reduce time and cost of training large models
- Train in Python but deploy into a C#/C++/Java app
- Run on different hardware and operating systems
- Support models created in several different frameworks
ONNX Runtime inferencing APIs are stable and production-ready since the 1.0 release in October 2019 and can enable faster customer experiences and lower costs.
ONNX Runtime training feature was introduced in May 2020 in preview. This feature supports acceleration of PyTorch training on multi-node NVIDIA GPUs for transformer models. Additional updates for this feature are coming soon.
Table of Contents
Get Started
Inferencing: Start
To use ONNX Runtime, refer to the table on aka.ms/onnxruntime for instructions for different build combinations.
- Compatibility
- Binaries
- Build from source (includes additional combinations)
- Docker images
- API documentation
- Hardware accelerators
- Deploy ONNX Runtime inferencing
- Samples
- High level architectural design
- Performance Tuning
- Extensibility: Add a new graph transform
- Extensibility: Add a new rewrite rule
Compatibility
Supporting models based on the standard ONNX format, the runtime is compatible with PyTorch, scikit-learn, TensorFlow, Keras, and all other frameworks and tools that support the interoperable format.
ONNX Runtime is up to date and backwards compatible with all operators (both DNN and traditional ML) since ONNX v1.2.1+. (ONNX compatibility details). Newer versions of ONNX Runtime support all models that worked with prior versions, so updates should not break integrations.
- Supported operators/types
- Operators not supported in the current ONNX spec may be available as a Contrib Operator
- Extensibility: Add a custom operator/kernel
Binaries
Official builds are available on PyPi (Python) and Nuget (C#/C/C++):
- Default CPU Provider (Eigen + MLAS)
- GPU Provider - NVIDIA CUDA
- GPU Provider - DirectML (Windows)
- On Windows, the DirectML execution provider is recommended for optimal performance and compatibility with a broad set of GPUs.
Dev builds created from the master branch are available for testing newer changes between official releases. Please use these at your own risk. We strongly advise against deploying these to production workloads as support is limited for dev builds.
| Pypi (Python) | Nuget (C#/C/C++) | Other package repositories |
|---|---|---|
If using pip, run pip install --upgrade pip prior to downloading.CPU: onnxruntime / ort-nightly (dev) GPU: onnxruntime-gpu / ort-gpu-nightly (dev) |
CPU: Microsoft.ML.OnnxRuntime / ort-nightly (dev) GPU: Microsoft.ML.OnnxRuntime.Gpu / ort-nightly (dev) |
Contributed non-official packages (including Homebrew, Linuxbrew, and nixpkgs) These are not maintained by the core ONNX Runtime team and may have limited support; use at your discretion. |
System Requirements
The following are required for usage of the official published packages.
-
Visual C++ Runtime (for Windows packages)
- Requires Visual C++ 2019 runtime
-
System language
- Installation of the English language package and configuring
en_US.UTF-8 localeis required, as certain operators makes use of system locales. - For Ubuntu, install language-pack-en package
- Run the following commands:
locale-gen en_US.UTF-8update-locale LANG=en_US.UTF-8 - Follow similar procedure to configure other locales on other platforms.
- Run the following commands:
- Installation of the English language package and configuring
-
Default CPU
- ONNX Runtime binaries in the CPU packages use OpenMP and depend on the library being available at runtime in the system.
- For Windows, OpenMP support comes as part of VC runtime. It is also available as redist packages: vc_redist.x64.exe and vc_redist.x86.exe
- For Linux, the system must have libgomp.so.1 which can be installed using
apt-get install libgomp1.
- ONNX Runtime binaries in the CPU packages use OpenMP and depend on the library being available at runtime in the system.
-
Default GPU (CUDA)
- The default GPU build requires CUDA runtime libraries being installed on the system:
- Version: CUDA 10.1 and cuDNN 7.6.5
- Version dependencies from older ONNX Runtime releases can be found in prior release notes.
- The default GPU build requires CUDA runtime libraries being installed on the system:
Build from Source
For production scenarios, it's strongly recommended to build only from an official release branch.
Docker Images
- ONNX-Ecosystem: includes ONNX Runtime (CPU, Python), dependencies, tools to convert from various frameworks, and Jupyter notebooks to help get started
- Additional dockerfiles
API Documentation
| API | Supported Versions | Samples |
|---|---|---|
| Python | 3.5, 3.6, 3.7 Python Dev Notes |
Samples |
| C# | Samples | |
| C++ | Samples | |
| C | Samples | |
| WinRT | Windows.AI.MachineLearning | Samples |
| Java | 8-13 | Samples |
| Ruby (external project) | 2.4-2.7 | Samples |
| Javascript (node.js) | 12.x | Samples |
Supported Accelerators
| CPU | GPU | IoT/Edge/Mobile | Other |
|---|---|---|---|
|
|
|
|
Deploying ONNX Runtime
Cloud
-
ONNX Runtime can be deployed to any cloud for model inferencing, including Azure Machine Learning Services.
-
ONNX Runtime Server (beta) is a hosting application for serving ONNX models using ONNX Runtime, providing a REST API for prediction.
IoT and edge devices
The expanding focus and selection of IoT devices with sensors and consistent signal streams introduces new opportunities to move AI workloads to the edge. This is particularly important when there are massive volumes of incoming data/signals that may not be efficient or useful to push to the cloud due to storage or latency considerations. Consider: surveillance tapes where 99% of footage is uneventful, or real-time person detection scenarios where immediate action is required. In these scenarios, directly executing model inferencing on the target device is crucial for optimal assistance.
Client applications
-
Install or build the package you need to use in your application. (sample implementations using the C++ API)
-
On newer Windows 10 devices (1809+), ONNX Runtime is available by default as part of the OS and is accessible via the Windows Machine Learning APIs. (Tutorials for Windows Desktop or UWP app)
Training: Start
The ONNX Runtime training feature enables easy integration with existing Pytorch trainer code to accelerate the exection. With a few lines of code, you can add ONNX Runtime into your existing training scripts and start seeing acceleration. The current preview version supports training acceleration for transformer models on NVIDIA GPUs.
ONNX Runtime pre-training sample: This sample is setup to pre-train the BERT-Large model to show how ONNX Runtime training can be used to accelerate training execution.
Train PyTorch model with ONNX Runtime
ONNX Runtime (ORT) has the capability to train existing PyTorch models through its optimized backend. For this, we have introduced an python API for PyTorch, called ORTTrainer, which can be used to switch the training backend for PyTorch models (instance of torch.nn.Module) to orttrainer. This requires some changes in the trainer code, such as replacing the PyTorch optimizer, and optionally, setting flags to enable additional features such as mixed-precision training. Here is a sample code fragment to integrate ONNX Runtime Training in your PyTorch pre-training script:
NOTE: The current API is experimental and expected to see significant changes in the near future. Our goal is to improve the interface to provide a seamless integration with PyTorch training that requires minimal changes in users’ training code.
import torch
...
import onnxruntime
from onnxruntime.capi.ort_trainer import IODescription, ModelDescription, ORTTrainer
# Model definition
class Net(torch.nn.Module):
def __init__(self, D_in, H, D_out):
...
def forward(self, x):
...
model = Net(D_in, H, H_out)
criterion = torch.nn.Functional.cross_entropy
description = ModelDescription(...)
optimizer = 'SGDOptimizer'
trainer = ORTTrainer(model, criterion, description, optimizer, ...)
# Training Loop
for t in range(1000):
# forward + backward + weight update
loss, y_pred = trainer.train_step(x, y, learning_rate)
...
Build ONNX Runtime Training from source
To use ONNX Runtime training in a custom environment, like on-prem NVIDIA DGX-2 clusters, you can use these build instructions to generate the Python package to integrate into existing trainer code.
Data/Telemetry
This project may collect usage data and send it to Microsoft to help improve our products and services. See the privacy statement for more details.
Contributions and Feedback
We welcome contributions! Please see the contribution guidelines.
For any feedback or to report a bug, please file a GitHub Issue.
Code of Conduct
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
License
This project is licensed under the MIT License.