The pre- and post- processing library for ONNX Runtime
Перейти к файлу
Scott McKay 2cf9bab611
Add ability to create a 'dummy' nuget package using build with no ops (#573)
* Add ability to create a 'dummy' nuget package from a build with no ops. This is required on iOS due to the ORT C# package including the ability to register custom ops. That creates a compile time dependency for the RegisterCustomOps symbol to exist. If the user can't (Xamarin) or does not want to use extensions that results in usage of ORT being broken.

For simplicity, consistency and to minimize changes to the build infrastructure we build a nuget package for all platforms so everything is 1:1 with the real package except the build uses an empty config to select the ops to include. Technically we only need something with iOS builds.

We should only need to publish this once unless the RegisterCustomOps API changes.

* Address PR comments

* Update .pipelines/nuget.yml

Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>

---------

Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
2023-10-21 09:44:26 +10:00
.config Update tsaoptions.json (#309) 2022-10-25 15:23:33 -07:00
.github/workflows fix linux_wheel pipeline by updating linux build wheel configuration (#563) 2023-09-21 10:59:12 -07:00
.pipelines Add ability to create a 'dummy' nuget package using build with no ops (#573) 2023-10-21 09:44:26 +10:00
base Fix the exception on invalid trie-tokenizer input (#575) 2023-10-16 17:03:02 -07:00
cmake Enable C++ unit tests on iOS (#560) 2023-09-18 18:52:30 -05:00
docs Update Azure Op doc for main (#554) 2023-08-31 12:57:47 -07:00
includes Refactor String and Audio operators with status-return prototype. (#576) 2023-10-19 10:40:58 -07:00
java fix the android packaging issue (#497) 2023-07-24 17:18:49 -07:00
nuget Add ability to create a 'dummy' nuget package using build with no ops (#573) 2023-10-21 09:44:26 +10:00
onnxruntime_extensions Fix the exception on invalid trie-tokenizer input (#575) 2023-10-16 17:03:02 -07:00
operators Refactor String and Audio operators with status-return prototype. (#576) 2023-10-19 10:40:58 -07:00
prebuild Enable using system certs on Android. (#543) 2023-08-24 12:17:07 +10:00
pyop Enable the status returnable APIs from ORT 1.16 C ABI (#558) 2023-09-13 14:59:09 -07:00
shared Enable the status returnable APIs from ORT 1.16 C ABI (#558) 2023-09-13 14:59:09 -07:00
test remove ftfy imports and add warning if not installed (#578) 2023-10-19 14:09:55 -07:00
tools Add ability to create a 'dummy' nuget package using build with no ops (#573) 2023-10-21 09:44:26 +10:00
tutorials Typo "Pytorch"→"PyTorch" (#569) 2023-10-06 10:06:08 -07:00
.clang-format initial checkins 2020-10-12 10:52:52 -07:00
.clang-tidy initial checkins 2020-10-12 10:52:52 -07:00
.flake8 initial checkins 2020-10-12 10:52:52 -07:00
.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
.swift-format Update OrtExtensionsUsage to also use the ORT Objective-C API. (#483) 2023-09-25 07:35:37 -07:00
CMakeLists.txt Add ability to create a 'dummy' nuget package using build with no ops (#573) 2023-10-21 09:44:26 +10:00
CODEOWNERS Update CODEOWNERS 2023-08-22 17:02:17 -07:00
CODE_OF_CONDUCT.md Initial CODE_OF_CONDUCT.md commit 2020-10-05 12:36:41 -07:00
LICENSE Updating LICENSE to template content 2020-10-05 12:36:43 -07:00
MANIFEST.in Prepare for 0.4.0 release (#151) 2021-09-25 00:40:12 -07:00
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 Initial SECURITY.md commit 2020-10-05 12:36:44 -07:00
ThirdPartyNotices.txt Enable C++ unit tests on iOS (#560) 2023-09-18 18:52:30 -05:00
build.android Make CIs pass with Azure ops enabled by default. (#518) 2023-08-12 17:45:59 +10:00
build.bat Add a bbpe tokenizer decoder for Whisper model (#376) 2023-03-08 15:00:01 -08:00
build.ios_xcframework Add iOS packaging pipeline. (#327) 2022-12-23 05:27:41 -08:00
build.sh support build_id on Python package building (#281) 2022-08-24 14:39:33 -07:00
build_lib.bat Add build.py to make it easier for developers to build different variants (#318) 2023-01-02 14:55:31 +10:00
build_lib.sh Enable C++ unit tests on iOS (#560) 2023-09-18 18:52:30 -05:00
cgmanifest.json Enable C++ unit tests on iOS (#560) 2023-09-18 18:52:30 -05:00
pyproject.toml fix linux_wheel pipeline by updating linux build wheel configuration (#563) 2023-09-21 10:59:12 -07:00
requirements-dev.txt remove ftfy imports and add warning if not installed (#578) 2023-10-19 14:09:55 -07:00
requirements.txt Remove onnx<1.14 from requirements.txt (#447) 2023-05-21 23:34:09 -07:00
setup.cfg update Python pipelines for release (#353) 2023-02-06 18:23:56 -08:00
setup.py Add an environment variable to explicitly enable/disable azureop build (#527) 2023-08-17 16:54:45 -07:00
version.txt add more hf models into converter APIs (#562) 2023-09-18 14:38:32 -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