* fix boost download url (#7843) * Topo sort the model before saving (#7913) * checkin toposort * review comments * revert and add TODO * Add shape inference to custom symbolic functions (#7937) **Description**: As title. **Motivation and Context** - PyTorch ONNX exporter heavily depends on ONNX shape inference to export accurate and efficient model. Custom symbolic function exports the op as contrib ops, thus exporter is unable to perform standard onnx shape inference. Models with dynamic shape inputs are affected. * Fix missing files on linux (#8066) * [Mobile package] Update required operator config with additional ops for wav2vec2. (#8079) Add some additional ops to the mobile package that are needed for the wav2vec2 model. * Add module attribute to ORTModule to support HuggingFace Trainer save_model (#8088) * Fix input schema extrator for ORTModule (#8098) * Fix 32bit Android java API crash (#8122) * Fix 32bit Android java API crash * fix code formating * [Mobile package] Update required operator config with additional ops for newer version of Wav2Vec 2. (#8123) This is an update to https://github.com/microsoft/onnxruntime/pull/8079 The sample application motivating the original update changed to use an updated version of the model. Now, fewer ops are required. This change removes the previously added ops which are no longer needed. * Add int64 as a required type to ConstantOfShape as it's used by the pytorch converter for Pad. (#8128) It's also used pointlessly for torch.tensor.repeat (although that usage should always be able to be constant folded). * Update logic in props.xml to account for shared provider library changes (#8138) * Ortmodule override torch.manual_seed() (#8131) * Ortmodule override torch.manual_seed() * Fix Python Cuda loading issues (#7939) * Fix mac shared_provider warning (#8153) Co-authored-by: Guoyu Wang <62914304+gwang-msft@users.noreply.github.com> Co-authored-by: Ye Wang <52801275+wangyems@users.noreply.github.com> Co-authored-by: Bowen Bao <bowbao@microsoft.com> Co-authored-by: Ryan Hill <38674843+RyanUnderhill@users.noreply.github.com> Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com> Co-authored-by: baijumeswani <bmeswani@microsoft.com> Co-authored-by: Thiago Crepaldi <thiago.crepaldi@microsoft.com> Co-authored-by: Scott McKay <skottmckay@gmail.com> Co-authored-by: Hariharan Seshadri <shariharan91@gmail.com> Co-authored-by: Sherlock <baihan.huang@gmail.com> |
||
|---|---|---|
| .. | ||
| src | ||
| testdata | ||
| build-android.gradle | ||
| build.gradle | ||
| README.md | ||
| settings-android.gradle | ||
| settings.gradle | ||
ONNX Runtime Java API
This directory contains the Java language binding for the ONNX runtime. Java Native Interface (JNI) is used to allow for seamless calls to ONNX runtime from Java.
Usage
This document pertains to developing, building, running, and testing the API itself in your local environment. For general purpose usage of the publicly distributed API, please see the general Java API documentation.
Building
Use the main project's build instructions with the --build_java option.
Requirements
JDK version 8 or later is required.
The Gradle build system is required and used here to manage the Java project's dependency management, compilation, testing, and assembly.
You may use your system Gradle installation installed on your PATH.
Version 6 or newer is recommended.
Optionally, you may use your own Gradle wrapper which will be locked to a version specified in the build.gradle configuration.
This can be done once by using system Gradle installation to invoke the wrapper task in the java project's directory: cd REPO_ROOT/java && gradle wrapper
Any installed wrapper is gitignored.
Build Output
The build will generate output in $REPO_ROOT/build/$OS/$CONFIGURATION/java/build:
docs/javadoc/- HTML javadocreports/- detailed test results and other reportslibs/onnxruntime-VERSION.jar- JAR with compiled classes, platform-specific JNI shared library, and platform-specific onnxruntime shared library.
Build System Overview
The main CMake build system delegates building and testing to Gradle.
This allows the CMake system to ensure all of the C/C++ compilation is achieved prior to the Java build.
The Java build depends on C/C++ onnxruntime shared library and a C JNI shared library (source located in the src/main/native directory).
The JNI shared library is the glue that allows for Java to call functions in onnxruntime shared library.
Given the fact that CMake injects native dependencies during CMake builds, some gradle tasks (primarily, build, test, and check) may fail.
When running the build script, CMake will compile the onnxruntime target and the JNI glue onnxruntime4j_jni target and expose the resulting libraries in a place where Gradle can ingest them.
Upon successful compilation of those targets, a special Gradle task to build will be executed. The results will be placed in the output directory stated above.
Advanced Loading
The default behavior is to load the shared libraries using classpath resources. If your use case requires custom loading of the shared libraries, please consult the javadoc in the package-info.java or OnnxRuntime.java files.
Development
Code Formatting
Spotless is used to keep the code properly formatted.
Gradle's spotlessCheck task will show any misformatted code.
Gradle's spotlessApply task will try to fix the formatting.
Misformatted code will raise failures when checks are ran during test run.
JNI Headers
When adding or updating native methods in the Java files, it may be necessary to examine the relevant JNI headers in build/headers/ai_onnxruntime*.h.
These files can be manually generated using Gradle's compileJava task which will compile the Java and update the header files accordingly.
Then the corresponding C files in ./src/main/native/ai_onnxruntime*.c may be updated and the build can be ran.
Dependencies
The Java API does not have any runtime or compile dependencies currently.