The pre- and post- processing library for ONNX Runtime
Перейти к файлу
Wenbing Li ee14fbe48e
correct CLIP tokenizer name (#526)
2023-08-16 12:51:17 -07:00
.config
.github/workflows Gradle wrapper security updates (#381) 2023-03-16 11:06:00 -07:00
.pipelines Make CIs pass with Azure ops enabled by default. (#518) 2023-08-12 17:45:59 +10:00
base Make kernel Compute method implementations const (#500) 2023-07-28 09:25:36 +10:00
cmake Android fixes/improvements (#522) 2023-08-16 15:17:13 +10:00
docs Add a new API for building data processing graph from Huggingface transformers processor/tokenizer (#482) 2023-07-17 16:50:58 -07:00
includes Android fixes/improvements (#522) 2023-08-16 15:17:13 +10:00
java fix the android packaging issue (#497) 2023-07-24 17:18:49 -07:00
nuget correct CLIP tokenizer name (#526) 2023-08-16 12:51:17 -07:00
onnxruntime_extensions correct CLIP tokenizer name (#526) 2023-08-16 12:51:17 -07:00
operators Android fixes/improvements (#522) 2023-08-16 15:17:13 +10:00
prebuild Android fixes/improvements (#522) 2023-08-16 15:17:13 +10:00
pyop PyOp attribute supports int and float data type (#425) 2023-05-05 19:35:59 -07:00
shared Refactor setup for Azure ops. Add Android support. (#507) 2023-08-08 19:54:30 +10:00
test Android fixes/improvements (#522) 2023-08-16 15:17:13 +10:00
tools correct CLIP tokenizer name (#526) 2023-08-16 12:51:17 -07:00
tutorials Update inputs in Whisper E2E script (#511) 2023-08-08 15:46:21 -07:00
.clang-format
.clang-tidy
.flake8
.gitignore Add an C# demo project for NuGet package (#407) 2023-04-27 14:29:58 -07:00
.sscignore Fix Secure Supply Chain Analysis Warning in PR pipeline (#414) 2023-05-04 16:29:21 -07:00
CMakeLists.txt Only enable azureop build in CI builds (#525) 2023-08-16 12:50:54 -07:00
CODEOWNERS
CODE_OF_CONDUCT.md
LICENSE
MANIFEST.in
README.md Add a new API for building data processing graph from Huggingface transformers processor/tokenizer (#482) 2023-07-17 16:50:58 -07:00
SECURITY.md
ThirdPartyNotices.txt Update cgmanifest.json and ThirdPartyNotices.txt (#438) 2023-05-15 13:11:05 -07:00
build.android Make CIs pass with Azure ops enabled by default. (#518) 2023-08-12 17:45:59 +10:00
build.bat
build.ios_xcframework
build.sh
build_lib.bat
build_lib.sh
cgmanifest.json Update cgmanifest.json and ThirdPartyNotices.txt (#438) 2023-05-15 13:11:05 -07:00
pyproject.toml Add UT for Azure Ops during packaging (#502) 2023-08-02 17:01:09 -07:00
requirements-dev.txt Add TrieTokenizer for RWKV-like LLM models (#509) 2023-08-08 16:47:38 -07:00
requirements.txt Remove onnx<1.14 from requirements.txt (#447) 2023-05-21 23:34:09 -07:00
setup.cfg
setup.py Add TrieTokenizer for RWKV-like LLM models (#509) 2023-08-08 16:47:38 -07:00
version.txt upgrade all dependency versions (#466) 2023-06-03 20:09:41 -07:00

README.md

ONNXRuntime-Extensions

Build Status

What's ONNXRuntime-Extensions

Introduction: ONNXRuntime-Extensions is a library that extends the capability of the ONNX models and inference with ONNX Runtime, via ONNX Runtime Custom Operator ABIs. It includes a set of ONNX Runtime Custom Operator to support the common pre- and post-processing operators for vision, text, and nlp models. And it supports multiple languages and platforms, like Python on Windows/Linux/macOS, some mobile platforms like Android and iOS, and Web-Assembly etc. The basic workflow is to enhance a ONNX model firstly and then do the model inference with ONNX Runtime and ONNXRuntime-Extensions package.

Quickstart

Python installation

pip install onnxruntime-extensions

Nightly Build

on Windows

pip install --index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ onnxruntime-extensions

Please ensure that you have met the prerequisites of onnxruntime-extensions (e.g., onnx and onnxruntime) in your Python environment.

on Linux/macOS

Please make sure the compiler toolkit like gcc(later than g++ 8.0) or clang are installed before the following command

python -m pip install git+https://github.com/microsoft/onnxruntime-extensions.git

Usage

1. Generate the pre-/post- processing ONNX model

With onnxruntime-extensions Python package, you can easily get the ONNX processing graph by converting them from Huggingface transformer data processing classes, check the following API for details.

help(onnxruntime_extensions.gen_processing_models)

NOTE: These data processing model can be merged into other model onnx.compose if needed.

2. Using Extensions for ONNX Runtime inference

Python

There are individual packages for the following languages, please install it for the build.

import onnxruntime as _ort
from onnxruntime_extensions import get_library_path as _lib_path

so = _ort.SessionOptions()
so.register_custom_ops_library(_lib_path())

# Run the ONNXRuntime Session, as ONNXRuntime docs suggested.
# sess = _ort.InferenceSession(model, so)
# sess.run (...)

C++

  // The line loads the customop library into ONNXRuntime engine to load the ONNX model with the custom op
  Ort::ThrowOnError(Ort::GetApi().RegisterCustomOpsLibrary((OrtSessionOptions*)session_options, custom_op_library_filename, &handle));

  // The regular ONNXRuntime invoking to run the model.
  Ort::Session session(env, model_uri, session_options);
  RunSession(session, inputs, outputs);

Java

var env = OrtEnvironment.getEnvironment();
var sess_opt = new OrtSession.SessionOptions();

/* Register the custom ops from onnxruntime-extensions */
sess_opt.registerCustomOpLibrary(OrtxPackage.getLibraryPath());

C#

SessionOptions options = new SessionOptions()
options.RegisterOrtExtensions()
session = new InferenceSession(model, options)

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

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

MIT License