The pre- and post- processing library for ONNX Runtime
Перейти к файлу
Wenbing Li be29e28dd7
support tokenizers build only in C API mode (#783)
* support tokenizer build only in C API mode

* fix the python build.

* fix the selectedops build

---------

Co-authored-by: Sayan Shaw <52221015+sayanshaw24@users.noreply.github.com>
2024-08-02 13:28:58 -07:00
.config Update tsaoptions.json (#309) 2022-10-25 15:23:33 -07:00
.github clean up requirements.txt and developer docs (#655) 2024-02-16 15:47:44 -08:00
.pipelines support tokenizers build only in C API mode (#783) 2024-08-02 13:28:58 -07:00
.pyproject Fix the pipeline breaks dues to the MSVC 19.40 and numpy 2.0 release (#747) 2024-06-17 16:58:11 -07:00
base Refactor the unit tests and cmake build script (#726) 2024-05-30 14:16:14 -07:00
cmake support tokenizers build only in C API mode (#783) 2024-08-02 13:28:58 -07:00
docs support tokenizers build only in C API mode (#783) 2024-08-02 13:28:58 -07:00
include add the decoder_prompt_id for whisper tokenizer (#775) 2024-07-29 14:21:17 -07:00
java Fix the windows API missing issue and Linux shared library size issue for Java packaging. (#774) 2024-07-29 16:03:58 -07:00
nuget Revert net7.0 update for now (#701) 2024-04-29 21:40:56 -07:00
onnxruntime_extensions reimplement resize cpu kernel for image processing (#768) 2024-07-23 15:40:52 -07:00
operators Add initial tiktoken and Phi3SmallTokenizer support (#729) 2024-08-02 10:24:02 -07:00
prebuild Enable using system certs on Android. (#543) 2023-08-24 12:17:07 +10:00
pyop reimplement resize cpu kernel for image processing (#768) 2024-07-23 15:40:52 -07:00
shared Add initial tiktoken and Phi3SmallTokenizer support (#729) 2024-08-02 10:24:02 -07:00
test support tokenizers build only in C API mode (#783) 2024-08-02 13:28:58 -07:00
tools removed OpenAIAudioToText from config (#777) 2024-07-31 10:40:43 -07:00
tutorials Fix the windows API missing issue and Linux shared library size issue for Java packaging. (#774) 2024-07-29 16:03:58 -07:00
.clang-format Add a generic image processor and its C API (#745) 2024-06-20 10:53:49 -07:00
.clang-tidy Refactor the header file directory and integrate the eager tensor implementation (#689) 2024-04-17 12:58:19 -07:00
.flake8 initial checkins 2020-10-12 10:52:52 -07:00
.gitignore Enhancing CUDA Support in Python Package Build and Testing (#608) 2023-11-27 15:39:52 -08: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 support tokenizers build only in C API mode (#783) 2024-08-02 13:28:58 -07: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 Refactor the header file directory and integrate the eager tensor implementation (#689) 2024-04-17 12:58:19 -07:00
README.md make onnx package to be optional. (#653) 2024-02-15 14:09:04 -08: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 add the decoder_prompt_id for whisper tokenizer (#775) 2024-07-29 14:21:17 -07:00
build.bat Fix the pipeline breaks dues to the MSVC 19.40 and numpy 2.0 release (#747) 2024-06-17 16:58:11 -07:00
build.ios_xcframework Add iOS packaging pipeline. (#327) 2022-12-23 05:27:41 -08:00
build.sh Eager mode: cuda kernel support (#694) 2024-04-24 12:49:00 -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 switch cmake cmp0169 flag to new (#762) 2024-07-15 23:28:49 -07:00
pyproject.toml Remove numpy dependency from its Python binary build (#657) 2024-02-21 09:54:17 -08:00
requirements-dev.txt Fix the pipeline breaks dues to the MSVC 19.40 and numpy 2.0 release (#747) 2024-06-17 16:58:11 -07:00
setup.cfg Minor changes to test CI PR trigger (#634) 2024-01-16 10:31:04 -08:00
setup.py make onnx package to be optional. (#653) 2024-02-15 14:09:04 -08:00
version.txt Bump up version in main from 0.11.0 to 0.12.0 (#702) 2024-04-30 11:45:33 -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. Generation of Pre-/Post-Processing ONNX Model

The onnxruntime-extensions Python package provides a convenient way to generate the ONNX processing graph. This can be achieved by converting the Huggingface transformer data processing classes into the desired format. For more detailed information, please refer to the API below:

help(onnxruntime_extensions.gen_processing_models)

NOTE:

The generation of model processing requires the ONNX package to be installed. The data processing models generated in this manner can be merged with other models using the 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