Skip to content

Commit

Permalink
Remove deprecated "mobile" packages (microsoft#20941)
Browse files Browse the repository at this point in the history
# Description

This PR removes the building of the ORT "mobile" packages and much of the associated infrastructure which is no longer needed.

Not removed yet - tools/ci_build/github/android/mobile_package.required_operators.config and the helper scripts that depend on it.

# Motivation and Context

The mobile packages were deprecated in 1.18. Users should use the full packages (Android - onnxruntime-android, iOS - onnxruntime-c/onnxruntime-objc) instead or do a custom build.
  • Loading branch information
edgchen1 authored Jun 7, 2024
1 parent a53f692 commit 981893c
Show file tree
Hide file tree
Showing 30 changed files with 68 additions and 273 deletions.
2 changes: 1 addition & 1 deletion cmake/onnxruntime_java.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Android")
set(ANDROID_TEST_PACKAGE_LIB_DIR ${ANDROID_TEST_PACKAGE_DIR}/app/libs)
file(MAKE_DIRECTORY ${ANDROID_TEST_PACKAGE_LIB_DIR})
# Copy the built Android AAR package to libs folder of our test app
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ANDROID_PACKAGE_OUTPUT_DIR}/outputs/aar/onnxruntime-debug.aar ${ANDROID_TEST_PACKAGE_LIB_DIR}/onnxruntime-mobile.aar)
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ANDROID_PACKAGE_OUTPUT_DIR}/outputs/aar/onnxruntime-debug.aar ${ANDROID_TEST_PACKAGE_LIB_DIR}/onnxruntime-android.aar)
# Build Android test apk for java package
add_custom_command(TARGET onnxruntime4j_jni
POST_BUILD
Expand Down
15 changes: 3 additions & 12 deletions java/build-android.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def headersDir = System.properties['headersDir']
def publishDir = System.properties['publishDir']
def minSdkVer = System.properties['minSdkVer']
def targetSdkVer = System.properties['targetSdkVer']
def buildVariant = System.properties['buildVariant'] ?: "Full"
boolean enableTrainingApis = (System.properties['ENABLE_TRAINING_APIS'] ?: "0") == "1"
boolean isMobileBuild = (buildVariant == "Mobile")

// Since Android requires a higher numbers indicating more recent versions
// This function assume ORT version number will be in formart of A.B.C such as 1.7.0
Expand All @@ -28,17 +26,10 @@ project.version = rootProject.file('../VERSION_NUMBER').text.trim()
project.group = "com.microsoft.onnxruntime"

def tmpArtifactId = enableTrainingApis ? project.name + "-training" : project.name
def mavenArtifactId = isMobileBuild ? tmpArtifactId + '-mobile' : tmpArtifactId + '-android'
def mobileDescription = 'The ONNX Runtime Mobile package is a size optimized inference library for executing ONNX ' +
'(Open Neural Network Exchange) models on Android. This package is built from the open source inference engine ' +
'but with reduced disk footprint targeting mobile platforms. To minimize binary size this library supports a ' +
'reduced set of operators and types aligned to typical mobile applications. The ONNX model must be converted to ' +
'ORT format in order to use it with this package. ' +
'See https://onnxruntime.ai/docs/reference/ort-format-models.html for more details.'
def mavenArtifactId = tmpArtifactId + '-android'
def defaultDescription = 'ONNX Runtime is a performance-focused inference engine for ONNX (Open Neural Network ' +
'Exchange) models. This package contains the Android (aar) build of ONNX Runtime. It includes support for all ' +
'types and operators, for ONNX format models. All standard ONNX models can be executed with this package. ' +
'As such the binary size and memory usage will be larger than the onnxruntime-mobile package.'
'types and operators, for ONNX format models. All standard ONNX models can be executed with this package.'
def trainingDescription = 'The onnxruntime-training android package is designed to efficiently train and infer a ' +
'wide range of ONNX models on edge devices, such as mobile phones, tablets, and other portable devices with ' +
'a focus on minimizing resource usage and maximizing accuracy.' +
Expand Down Expand Up @@ -147,7 +138,7 @@ publishing {

pom {
name = enableTrainingApis ? 'onnxruntime-training' : 'onnx-runtime'
description = isMobileBuild ? mobileDescription : enableTrainingApis ? trainingDescription : defaultDescription
description = enableTrainingApis ? trainingDescription : defaultDescription
url = 'https://microsoft.github.io/onnxruntime/'
licenses {
license {
Expand Down
2 changes: 1 addition & 1 deletion java/src/test/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation(name: "onnxruntime-mobile", ext: "aar")
implementation(name: "onnxruntime-android", ext: "aar")

androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
Expand Down
56 changes: 10 additions & 46 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ Prior to ORT v1.13, the ONNX Runtime React Native package utilized the ONNX Runt
Follow these [instructions](https://onnxruntime.ai/docs/reference/ort-format-models.html#convert-onnx-models-to-ort-format) to convert ONNX model to ORT format.
Note that the ONNX Runtime Mobile package includes a reduced set of operators and types, so not all models are supported. See [here](https://onnxruntime.ai/docs/reference/operators/MobileOps.html) for the list of supported operators and types.

From ORT v1.13 onwards the 'full' ONNX Runtime package is used. It supports both ONNX and ORT format models, and all operators and types.
From ORT v1.13 onwards, the 'full' ONNX Runtime package is used. It supports both ONNX and ORT format models, and all operators and types.

From ORT v1.19 onwards, the ONNX Runtime Mobile packages are no longer published.

### Build

Expand All @@ -298,35 +300,24 @@ From ORT v1.13 onwards the 'full' ONNX Runtime package is used. It supports both

2. Acquire or build the Android ONNX Runtime package

1. To use a published Android ONNX Runtime Mobile package from Maven, go to step 5.
1. To use a published Android ONNX Runtime package from Maven, go to step 5.

2. Set up an Android build environment using these [instructions](https://onnxruntime.ai/docs/build/android.html). Note that the dependencies are quite convoluted, so using the specified JDK and Gradle versions is important.

3. In `<ORT_ROOT>`, run the below python script to build the ONNX Runtime Android archive file. On a Windows machine, this requires an admin account to build.

You can build a 'full' package that supports all operators and types, or a reduced size 'mobile' package that supports a limited set of operators and types based on your model/s to miminize the binary size.
You can build a 'full' package that supports all operators and types, or a reduced size package that supports a limited set of operators and types based on your model/s to miminize the binary size.
See [here](https://onnxruntime.ai/docs/build/custom.html) for information about how the reduced build works, including creating the configuration file using your model/s.

Full build:
The instructions here show how to build a 'full' package.

```sh
python tools/ci_build/github/android/build_aar_package.py tools/ci_build/github/android/default_full_aar_build_settings.json --config Release --android_sdk_path <ANDROID_SDK_PATH> --android_ndk_path <ANDROID_NDK_PATH> --build_dir <BUILD_DIRECTORY>
```

Reduced size build with configuration file generated from your model/s. Note that either Release or MinSizeRel could be used as the config, depending on your priorities:

```sh
python tools/ci_build/github/android/build_aar_package.py tools/ci_build/github/android/default_mobile_aar_build_settings.json --config MinSizeRel --android_sdk_path <ANDROID_SDK_PATH> --android_ndk_path <ANDROID_NDK_PATH> --build_dir <BUILD_DIRECTORY> --include_ops_by_config <required_ops_and_types_for_your_models.config> --enable_reduced_operator_type_support
```

4. Move the generated ONNX Runtime Android archive file to `<ORT_ROOT>/js/react_native/android/libs/`.

Full build:
Copy `<BUILD_DIRECTORY>/aar_out/Release/com/microsoft/onnxruntime/onnxruntime-android/<version>/onnxruntime-android-<version>.aar` into `<ORT_ROOT>/js/react_native/android/libs` directory.

Reduced size build:
Copy `<BUILD_DIRECTORY>/aar_out/MinSizeRel/com/microsoft/onnxruntime/onnxruntime-mobile/<version>/onnxruntime-mobile-<version>.aar` into `<ORT_ROOT>/js/react_native/android/libs` directory and update to dependencies in [js/react_native/android/build.gradle](https://github.com/microsoft/onnxruntime/blob/365a01397dbd1293e0c2773380c57fd271432b72/js/react_native/android/build.gradle#L136-L137) to use onnxruntime-mobile instead of onnxruntime-android.

5. To verify, open the Android Emulator and run this command from `<ORT_ROOT>/js/react_native/android`

```sh
Expand All @@ -339,42 +330,20 @@ From ORT v1.13 onwards the 'full' ONNX Runtime package is used. It supports both

2. Set up iOS build environment using these [instructions](https://onnxruntime.ai/docs/build/ios.html).

3. Build a fat ONNX Runtime Mobile Framework for iOS and iOS simulator from `<ORT_ROOT>` using this command:

Full build:
3. Build a fat ONNX Runtime Framework for iOS and iOS simulator from `<ORT_ROOT>` using this command:

```sh
python tools/ci_build/github/apple/build_apple_framework.py tools/ci_build/github/apple/default_full_apple_framework_build_settings.json --config Release
```

Reduced size build:

```sh
python tools/ci_build/github/apple/build_apple_framework.py tools/ci_build/github/apple/default_mobile_ios_framework_build_settings.json --config MinSizeRel --include_ops_by_config <required_ops_and_types_for_your_models.config> --enable_reduced_operator_type_support
```

The build creates `Headers`, `LICENSE`, and `onnxruntime.xcframework` in `build/iOS_framework/framework_out` directory. From `framework_out` directory, create an archive file named `onnxruntime-c.zip` for a full build or `onnxruntime-mobile-c.zip` for a reduced size build and copy to `<ORT_ROOT>/js/react_native/local_pods` directory.

Full build:
The build creates `Headers`, `LICENSE`, and `onnxruntime.xcframework` in `build/iOS_framework/framework_out` directory. From `framework_out` directory, create an archive file named `onnxruntime-c.zip` and copy to `<ORT_ROOT>/js/react_native/local_pods` directory.

```sh
zip -r onnxruntime-c.zip .
```

Reduced size build:

```sh
zip -r onnxruntime-mobile-c.zip .
```

4. To verify, open the iOS Simulator and run the below command from `<ORT_ROOT>/js/react_native/ios`. Change the destination argument as needed to specify a running iOS Simulator.

If using the reduced size build it is necessary to first update some configuration to use the mobile ORT package:

- replace `onnxruntime/onnxruntime.framework` with `onnxruntime-mobile/onnxruntime.framework` in /js/react_native/ios/OnnxruntimeModule.xcodeproj/project.pbxproj
- replace `onnxruntime-c` with `onnxruntime-mobile-c` in /js/react_native/ios/Podfile
- For reference, [this PR](https://github.com/microsoft/onnxruntime/pull/13037) shows the changes made to switch from using the 'mobile' ORT package to the 'full' package.

```sh
pod install
xcodebuild test -workspace OnnxruntimeModule.xcworkspace -scheme OnnxruntimeModuleTest -destination 'platform=iOS Simulator,OS=latest,name=iPhone 13'
Expand All @@ -394,14 +363,9 @@ From ORT v1.13 onwards the 'full' ONNX Runtime package is used. It supports both
yarn bootstrap
```

When testing with a custom built ONNX Runtime Android package, copy `<BUILD_DIRECTORY>/aar_out/MinSizeRel/com/microsoft/onnxruntime/onnxruntime-{android|mobile}/<version>/onnxruntime-{android|mobile}-<version>.aar` into the `<ORT_ROOT>/js/react_native/e2e/android/app/libs` directory.

When testing with a custom built ONNX Runtime iOS package, copy `onnxruntime-[mobile-]c.zip` into the `<ORT_ROOT>/js/react_native/local_pods` directory.

If using the reduced size build it is necessary to update some configuration to use the mobile ORT package:
When testing with a custom built ONNX Runtime Android package, copy `<BUILD_DIRECTORY>/aar_out/MinSizeRel/com/microsoft/onnxruntime/onnxruntime-android/<version>/onnxruntime-android-<version>.aar` into the `<ORT_ROOT>/js/react_native/e2e/android/app/libs` directory.

- replace `com.microsoft.onnxruntime:onnxruntime-android` with `com.microsoft.onnxruntime:onnxruntime-mobile` in /js/react_native/e2e/android/app/build.gradle
- replace `onnxruntime-c` with `onnxruntime-mobile-c` in /js/react_native/e2e/ios/Podfile
When testing with a custom built ONNX Runtime iOS package, copy `onnxruntime-c.zip` into the `<ORT_ROOT>/js/react_native/local_pods` directory.

- Run E2E Testing with Detox framework

Expand Down
2 changes: 0 additions & 2 deletions js/react_native/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ dependencies {

androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito-inline-extended:2.28.1"

// Mobile build:
// implementation "com.microsoft.onnxruntime:onnxruntime-mobile:latest.integration@aar"
implementation "com.microsoft.onnxruntime:onnxruntime-android:latest.integration@aar"

// By default it will just include onnxruntime full aar package
Expand Down
4 changes: 1 addition & 3 deletions js/react_native/e2e/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ repositories {
dependencies {
androidTestImplementation('com.wix:detox:20.7.0')
implementation 'androidx.appcompat:appcompat:1.1.0'

implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
Expand Down Expand Up @@ -220,8 +220,6 @@ dependencies {
implementation project(':onnxruntime-react-native')
// specify ORT dependency here so it can be found in libs flatDir repository
implementation "com.microsoft.onnxruntime:onnxruntime-android:latest.integration@aar"
// Mobile build:
// implementation "com.microsoft.onnxruntime:onnxruntime-mobile:latest.integration@aar"
}

// Run this once to be able to run the application with BUCK
Expand Down
7 changes: 0 additions & 7 deletions js/react_native/e2e/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ target 'OnnxruntimeModuleExample' do

use_frameworks!

# Mobile build:
# ort_mobile_c_local_pod_path = ENV['ORT_MOBILE_C_LOCAL_POD_PATH']
# if ort_mobile_c_local_pod_path != nil
# print 'Using onnxruntime-c pod at ', ort_mobile_c_local_pod_path, "\n"
# pod 'onnxruntime-mobile-c', :path => ort_mobile_c_local_pod_path
# end

ort_c_local_pod_path = ENV['ORT_C_LOCAL_POD_PATH']
if ort_c_local_pod_path != nil
print 'Using onnxruntime-c pod at ', ort_c_local_pod_path, "\n"
Expand Down
9 changes: 0 additions & 9 deletions js/react_native/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ def shared

# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Mobile build
# ort_mobile_c_local_pod_path = ENV['ORT_MOBILE_C_LOCAL_POD_PATH']
# if ort_mobile_c_local_pod_path != nil
# print 'Using onnxruntime-c pod at ', ort_mobile_c_local_pod_path, "\n"
# pod 'onnxruntime-mobile-c', :path => ort_mobile_c_local_pod_path
# else
# pod 'onnxruntime-mobile-c'
# end

ort_c_local_pod_path = ENV['ORT_C_LOCAL_POD_PATH']
if ort_c_local_pod_path != nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
def include_macos_target
if '@C_POD_NAME@' != 'onnxruntime-mobile-c'
if ENV['SKIP_MACOS_TEST'] != 'true'
return true
else
return false
end
end
return false
end

target 'ios_package_test' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
Expand All @@ -21,7 +10,7 @@ target 'ios_package_test' do
end
end

if include_macos_target
if ENV['SKIP_MACOS_TEST'] != 'true'
target 'macos_package_test' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
Expand Down
34 changes: 18 additions & 16 deletions tools/android_custom_build/build_custom_android_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import sys

SCRIPT_DIR = pathlib.Path(__file__).parent.resolve()
DEFAULT_OPS_CONFIG_RELATIVE_PATH = "tools/ci_build/github/android/mobile_package.required_operators.config"
DEFAULT_BUILD_SETTINGS_RELATIVE_PATH = "tools/ci_build/github/android/default_mobile_aar_build_settings.json"


def is_windows():
Expand Down Expand Up @@ -53,16 +51,18 @@ def parse_args():
parser.add_argument(
"--include_ops_by_config",
type=pathlib.Path,
help="The configuration file specifying which ops to include. "
help="The optional configuration file specifying which ops to include. "
"Such a configuration file is generated during ONNX to ORT format model conversion. "
f"The default is {DEFAULT_OPS_CONFIG_RELATIVE_PATH} in the ONNX Runtime repo.",
"When providing this option, consider also enabling op type support reduction by specifying "
"the build.py --enable_reduced_operator_type_support option in the build settings configuration file.",
)

parser.add_argument(
"--build_settings",
type=pathlib.Path,
required=True,
help="The configuration file specifying the build.py options. "
f"The default is {DEFAULT_BUILD_SETTINGS_RELATIVE_PATH} in the ONNX Runtime repo.",
"For an example, see tools/ci_build/github/android/default_full_aar_build_settings.json.",
)

default_config = "Release"
Expand Down Expand Up @@ -95,6 +95,12 @@ def parse_args():

args = parser.parse_args()

if not args.build_settings.is_file():
raise ValueError(f"--build_settings argument is not a file: {args.build_settings}")

if args.include_ops_by_config is not None and not args.include_ops_by_config.is_file():
raise ValueError(f"--include_ops_by_config argument is not a file: {args.include_ops_by_config}")

if args.docker_path is None:
raise ValueError("Unable to determine docker path. Please provide it with --docker_path.")

Expand Down Expand Up @@ -129,7 +135,7 @@ def main():
working_dir.mkdir(parents=True, exist_ok=True)
working_dir = working_dir.resolve()

# copy over any custom build configuration files
# copy over custom build configuration files
config_files = [f for f in [args.include_ops_by_config, args.build_settings] if f]
if config_files:
input_dir = working_dir / "input"
Expand All @@ -141,16 +147,10 @@ def main():
output_dir.mkdir(exist_ok=True)

container_ops_config_file = (
f"/workspace/shared/input/{args.include_ops_by_config.name}"
if args.include_ops_by_config
else f"/workspace/onnxruntime/{DEFAULT_OPS_CONFIG_RELATIVE_PATH}"
f"/workspace/shared/input/{args.include_ops_by_config.name}" if args.include_ops_by_config else None
)

container_build_settings_file = (
f"/workspace/shared/input/{args.build_settings.name}"
if args.build_settings
else f"/workspace/onnxruntime/{DEFAULT_BUILD_SETTINGS_RELATIVE_PATH}"
)
container_build_settings_file = f"/workspace/shared/input/{args.build_settings.name}"

# enable use of Ctrl-C to stop when running interactively
docker_run_interactive_args = ["-it"] if sys.stdin.isatty() else []
Expand All @@ -165,11 +165,13 @@ def main():
"/bin/bash",
"/workspace/scripts/build.sh",
args.config,
container_ops_config_file,
container_build_settings_file,
"/workspace/shared/output",
container_build_settings_file,
]

if container_ops_config_file is not None:
docker_container_build_cmd += [container_ops_config_file]

run(docker_container_build_cmd)

print("Finished building Android package at '{}'.".format(output_dir / "aar_out"))
Expand Down
24 changes: 16 additions & 8 deletions tools/android_custom_build/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@

set -e -x

USAGE_TEXT="Usage: ${0} <build config> <ops config file> <build settings file> <output directory>"
USAGE_TEXT="Usage: ${0} <build config> <output directory> <build settings file> [<ops config file>]"

BUILD_CONFIG=${1:?${USAGE_TEXT}}
OPS_CONFIG_FILE=${2:?${USAGE_TEXT}}
OUTPUT_DIR=${2:?${USAGE_TEXT}}
BUILD_SETTINGS_FILE=${3:?${USAGE_TEXT}}
OUTPUT_DIR=${4:?${USAGE_TEXT}}
OPS_CONFIG_FILE=${4} # optional input

# build in directory that is not shared with the host to avoid permissions issues and speed up file access
BUILD_DIR=/workspace/build

# build ORT AAR
python3 /workspace/onnxruntime/tools/ci_build/github/android/build_aar_package.py \
--build_dir="${BUILD_DIR}" \
--config="${BUILD_CONFIG}" \
--include_ops_by_config="${OPS_CONFIG_FILE}" \
"${BUILD_SETTINGS_FILE}"
if [[ -n "${OPS_CONFIG_FILE}" ]]; then
python3 /workspace/onnxruntime/tools/ci_build/github/android/build_aar_package.py \
--build_dir="${BUILD_DIR}" \
--config="${BUILD_CONFIG}" \
--include_ops_by_config="${OPS_CONFIG_FILE}" \
"${BUILD_SETTINGS_FILE}"
else
python3 /workspace/onnxruntime/tools/ci_build/github/android/build_aar_package.py \
--build_dir="${BUILD_DIR}" \
--config="${BUILD_CONFIG}" \
"${BUILD_SETTINGS_FILE}"
fi

# copy AAR to output directory
cp -r "${BUILD_DIR}/aar_out" "${OUTPUT_DIR}"
Loading

0 comments on commit 981893c

Please sign in to comment.