Add build.py option to disable ORT format model runtime optimization (#9723)

ORT format model runtime optimization implementation is in progress.
This change adds a build.py option to disable the partial runtime optimization implementation, adds CI builds to test it, and disables runtime optimizations in mobile package builds.
This commit is contained in:
Edward Chen 2021-11-11 18:05:45 -08:00 committed by GitHub
parent 93e239747f
commit 997266a620
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 94 additions and 39 deletions

View file

@ -1,4 +1,3 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

View file

@ -104,7 +104,7 @@ Status SelectorActionTransformer::MatchAndProcess(Graph& graph, const GraphViewe
node_selection,
action_saved_state.produced_nodes});
#else
status = ORT_MAKE_STATUS(ONNXRUNTIME, FAILED,
status = ORT_MAKE_STATUS(ONNXRUNTIME, FAIL,
"Saving runtime optimizations is not enabled in this build.");
break;
#endif

View file

@ -511,7 +511,7 @@ def parse_arguments():
# options to reduce binary size
parser.add_argument("--minimal_build", default=None, nargs='*', type=str.lower,
help="Create a build that only supports ORT format models. "
"See /docs/ONNX_Runtime_Format_Model_Usage.md for more information. "
"See https://onnxruntime.ai/docs/tutorials/mobile/ for more information. "
"RTTI is automatically disabled in a minimal build. "
"To enable execution providers that compile kernels at runtime (e.g. NNAPI) pass 'extended' "
"as a parameter. e.g. '--minimal_build extended'. "
@ -537,6 +537,10 @@ def parse_arguments():
parser.add_argument("--disable_exceptions", action='store_true',
help="Disable exceptions to reduce binary size. Requires --minimal_build.")
parser.add_argument("--disable_ort_format_runtime_graph_optimizations", action='store_true',
help="Disable the ORT format model runtime graph optimization capability "
"(reduces binary size)")
parser.add_argument(
"--rocm_version", help="The version of ROCM stack to use. ")
parser.add_argument("--use_rocm", action='store_true', help="Build with ROCm")
@ -768,7 +772,8 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home
args.minimal_build or args.use_extensions))
else "OFF"),
"-Donnxruntime_REDUCED_OPS_BUILD=" + ("ON" if is_reduced_ops_build(args) else "OFF"),
# enable pyop if it is nightly build
"-Donnxruntime_ENABLE_ORT_FORMAT_RUNTIME_GRAPH_OPTIMIZATION=" + (
"ON" if not args.disable_ort_format_runtime_graph_optimizations else "OFF"),
"-Donnxruntime_ENABLE_LANGUAGE_INTEROP_OPS=" + ("ON" if args.enable_language_interop_ops else "OFF"),
"-Donnxruntime_USE_DML=" + ("ON" if args.use_dml else "OFF"),
"-Donnxruntime_USE_WINML=" + ("ON" if args.use_winml else "OFF"),

View file

@ -19,6 +19,7 @@
"--disable_exceptions",
"--enable_reduced_operator_type_support",
"--use_nnapi",
"--skip_tests"
"--skip_tests",
"--disable_ort_format_runtime_graph_optimizations"
]
}

View file

@ -20,6 +20,7 @@
"--enable_reduced_operator_type_support",
"--use_coreml",
"--skip_tests",
"--apple_deploy_target=11.0"
"--apple_deploy_target=11.0",
"--disable_ort_format_runtime_graph_optimizations"
]
}

View file

@ -1,18 +1,19 @@
# This CI has 4 major steps
# This CI has the following steps:
# 1. Build full ORT, install the full ORT python wheel and use it to generate ort format test models
# and include ops config file for step 3
# and include ops config file for step 3.
# 2. Build minimal ORT including all the kernels and disable exceptions.
# This step is build only to safe-guard the --disable_exceptions option.
# 3. Build minimal ORT include only the kernels using the include ops config file from step 1,
# and the models from <repo root>/onnxruntime/test/testdata/, run UT, and use onnx_test_runner to
# test the ort format models generated in step 1.
# Exceptions are enabled in this step to help debugging in case of CI failure.
# This step builds and tests ORT with and without type reduction enabled.
# 3.1. Build minimal ORT with type reduction from a globally allowed types list.
# This step builds and tests ORT with (3a) and without (3b) type reduction enabled.
# 4. Build minimal ORT with type reduction from a globally allowed types list.
# This step uses a hard-coded list of types which may not include the types needed by the models
# in <repo root>/onnxruntime/test/testdata/, so the tests for those models are skipped.
# 4. Build baseline minimal ORT for Android arm64-v8a including no kernels and disable exceptions
# This step is to report the baseline binary size for Android
# 5. Build baseline minimal ORT for Android arm64-v8a including no kernels and disable exceptions.
# This step is to report the baseline binary size for Android.
# 6. Build full (6a) and extended minimal (6b) ORT with runtime optimizations disabled.
jobs:
- job: Linux_CPU_Minimal_Build_E2E
timeoutInMinutes: 120
@ -44,7 +45,7 @@ jobs:
Repository: onnxruntimecpubuild
- task: CmdLine@2
displayName: Build full onnxruntime and generate ORT format test files
displayName: 1. Build full onnxruntime and generate ORT format test files
inputs:
script: |
docker run --rm \
@ -55,11 +56,12 @@ jobs:
-e NIGHTLY_BUILD \
-e BUILD_BUILDNUMBER \
onnxruntimecpubuild \
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_full_ort_and_create_ort_files.sh
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_full_ort_and_create_ort_files.sh \
/build/1
workingDirectory: $(Build.SourcesDirectory)
- task: CmdLine@2
displayName: Build minimal onnxruntime [exceptions DISABLED, type reduction DISABLED, training ops ENABLED]
displayName: 2. Build minimal onnxruntime [exceptions DISABLED, type reduction DISABLED, training ops ENABLED]
inputs:
script: |
# We will try to build minimal ORT with exceptions disabled and training ops enabled
@ -72,8 +74,8 @@ jobs:
-e BUILD_BUILDNUMBER \
onnxruntimecpubuild \
/opt/python/cp37-cp37m/bin/python3 /onnxruntime_src/tools/ci_build/build.py \
--build_dir /build --cmake_generator Ninja \
--config Debug\
--build_dir /build/2 --cmake_generator Ninja \
--config Debug \
--skip_submodule_sync \
--build_shared_lib \
--parallel \
@ -84,7 +86,7 @@ jobs:
workingDirectory: $(Build.SourcesDirectory)
- task: CmdLine@2
displayName: Build minimal onnxruntime [exceptions ENABLED, type reduction DISABLED, custom ops ENABLED] and run tests
displayName: 3a. Build minimal onnxruntime [exceptions ENABLED, type reduction DISABLED, custom ops ENABLED] and run tests
inputs:
script: |
docker run --rm \
@ -96,7 +98,7 @@ jobs:
-e BUILD_BUILDNUMBER \
onnxruntimecpubuild \
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_minimal_ort_and_run_tests.sh \
--build-directory /build/without_type_reduction \
--build-directory /build/3a \
--reduced-ops-config /home/onnxruntimedev/.test_data/required_ops.ort_models.config \
--enable-custom-ops
workingDirectory: $(Build.SourcesDirectory)
@ -106,7 +108,7 @@ jobs:
workingDirectory: $(Build.SourcesDirectory)
- task: CmdLine@2
displayName: Build minimal onnxruntime [exceptions ENABLED, type reduction ENABLED] and run tests
displayName: 3b. Build minimal onnxruntime [exceptions ENABLED, type reduction ENABLED] and run tests
inputs:
script: |
docker run --rm \
@ -118,7 +120,7 @@ jobs:
-e BUILD_BUILDNUMBER \
onnxruntimecpubuild \
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_minimal_ort_and_run_tests.sh \
--build-directory /build/with_type_reduction \
--build-directory /build/3b \
--reduced-ops-config /home/onnxruntimedev/.test_data/required_ops_and_types.ort_models.config \
--enable-type-reduction
workingDirectory: $(Build.SourcesDirectory)
@ -128,7 +130,7 @@ jobs:
workingDirectory: $(Build.SourcesDirectory)
- task: CmdLine@2
displayName: Build minimal onnxruntime [exceptions ENABLED, type reduction ENABLED (globally allowed types)] and run tests
displayName: 4. Build minimal onnxruntime [exceptions ENABLED, type reduction ENABLED (globally allowed types)] and run tests
inputs:
script: |
printf "%s\n%s\n" \
@ -144,7 +146,7 @@ jobs:
-e BUILD_BUILDNUMBER \
onnxruntimecpubuild \
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_minimal_ort_and_run_tests.sh \
--build-directory /build/with_type_reduction_globally_allowed_types \
--build-directory /build/4 \
--reduced-ops-config /home/onnxruntimedev/.test_data/globally_allowed_types.config \
--enable-type-reduction \
--skip-model-tests
@ -155,7 +157,7 @@ jobs:
workingDirectory: $(Build.SourcesDirectory)
- task: CmdLine@2
displayName: Build onnxruntime minimal baseline for Android arm64-v8a and report binary size
displayName: 5. Build onnxruntime minimal baseline for Android arm64-v8a and report binary size
inputs:
script: |
NDK_HOME=$(realpath $ANDROID_NDK_HOME)
@ -172,9 +174,9 @@ jobs:
-e BUILD_ID=$(Build.BuildId) \
-e BUILD_REASON=$(Build.Reason) \
-e BUILD_BRANCH=$(Build.SourceBranch) \
-e DASHBOARD_MYSQL_ORT_PASSWORD=$(dashboard-mysql-ort-password) \
onnxruntimecpubuild \
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_minimal_ort_android_baseline_and_report_bin_size.sh
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_minimal_ort_android_baseline_and_report_bin_size.sh \
/build/5
workingDirectory: $(Build.SourcesDirectory)
@ -186,7 +188,7 @@ jobs:
scriptLocation: inlineScript
scriptType: bash
inlineScript: |
BINARY_SIZE_DATA_FILE="$(Build.BinariesDirectory)/MinSizeRel/binary_size_data.txt"
BINARY_SIZE_DATA_FILE="$(Build.BinariesDirectory)/5/MinSizeRel/binary_size_data.txt"
if [[ ! -f "${BINARY_SIZE_DATA_FILE}" ]]; then
echo "File not found: ${BINARY_SIZE_DATA_FILE}"
exit 1
@ -198,6 +200,51 @@ jobs:
--build_id=$(Build.BuildId)
workingDirectory: '$(Build.BinariesDirectory)'
- script: git checkout -- .
displayName: Discard local changes to Git repository files
workingDirectory: $(Build.SourcesDirectory)
- task: CmdLine@2
displayName: 6a. Build full onnxruntime with runtime optimizations disabled
inputs:
script: |
docker run --rm \
--volume $(Build.SourcesDirectory):/onnxruntime_src \
--volume $(Build.BinariesDirectory):/build \
-e ALLOW_RELEASED_ONNX_OPSET_ONLY=1 \
-e NIGHTLY_BUILD \
-e BUILD_BUILDNUMBER \
onnxruntimecpubuild \
/opt/python/cp37-cp37m/bin/python3 /onnxruntime_src/tools/ci_build/build.py \
--build_dir /build/6a --cmake_generator Ninja \
--config Debug \
--skip_submodule_sync \
--build_shared_lib \
--parallel \
--disable_ort_format_runtime_graph_optimizations
workingDirectory: $(Build.SourcesDirectory)
- task: CmdLine@2
displayName: 6b. Build extended minimal onnxruntime with runtime optimizations disabled
inputs:
script: |
docker run --rm \
--volume $(Build.SourcesDirectory):/onnxruntime_src \
--volume $(Build.BinariesDirectory):/build \
-e ALLOW_RELEASED_ONNX_OPSET_ONLY=1 \
-e NIGHTLY_BUILD \
-e BUILD_BUILDNUMBER \
onnxruntimecpubuild \
/opt/python/cp37-cp37m/bin/python3 /onnxruntime_src/tools/ci_build/build.py \
--build_dir /build/6b --cmake_generator Ninja \
--config Debug \
--skip_submodule_sync \
--build_shared_lib \
--parallel \
--minimal_build extended \
--disable_ort_format_runtime_graph_optimizations
workingDirectory: $(Build.SourcesDirectory)
- task: PublishTestResults@2
displayName: 'Publish unit test results'
inputs:

View file

@ -7,6 +7,8 @@ set -e
set -x
export PATH=/opt/python/cp37-cp37m/bin:$PATH
BUILD_DIR=${1:?"usage: $0 <build directory>"}
# Validate the operator kernel registrations, as the ORT model uses hashes of the kernel registration details
# to find kernels. If the hashes from the registration details are incorrect we will produce a model that will break
# when the registration is fixed in the future.
@ -17,7 +19,7 @@ python3 /onnxruntime_src/tools/ci_build/op_registration_validator.py
# We do not run tests in this command since those are covered by other CIs.
# We run two full builds here. One for enabling nnapi and the other for enabling coreml.
python3 /onnxruntime_src/tools/ci_build/build.py \
--build_dir /build --cmake_generator Ninja \
--build_dir ${BUILD_DIR} --cmake_generator Ninja \
--config Debug \
--skip_submodule_sync \
--parallel \
@ -29,12 +31,12 @@ python3 /onnxruntime_src/tools/ci_build/build.py \
--use_coreml
# Run kernel def hash verification test
pushd /build/Debug
pushd ${BUILD_DIR}/Debug
ORT_TEST_STRICT_KERNEL_DEF_HASH_CHECK=1 ./onnxruntime_test_all --gtest_filter="KernelDefHashTest.ExpectedCpuKernelDefHashes"
popd
# Install the ORT python wheel
python3 -m pip install --user /build/Debug/dist/*
python3 -m pip install --user ${BUILD_DIR}/Debug/dist/*
# Convert all the E2E ONNX models to ORT format
python3 /onnxruntime_src/tools/python/convert_onnx_models_to_ort.py \
@ -62,9 +64,6 @@ python3 /onnxruntime_src/tools/python/create_reduced_build_config.py --format OR
mkdir /home/onnxruntimedev/.test_data/custom_ops_model
cp /onnxruntime_src/onnxruntime/test/testdata/custom_op_library/*.onnx /home/onnxruntimedev/.test_data/custom_ops_model/
python3 /onnxruntime_src/tools/python/convert_onnx_models_to_ort.py \
--custom_op_library /build/Debug/libcustom_op_library.so \
--custom_op_library ${BUILD_DIR}/Debug/libcustom_op_library.so \
/home/onnxruntimedev/.test_data/custom_ops_model
rm -rf /home/onnxruntimedev/.test_data/custom_ops_model
# Clear the build
rm -rf /build/Debug

View file

@ -1,18 +1,21 @@
#!/bin/bash
# This script will run a baseline minimal ort build for android arm64-v8a ABI
# and report the binary size to the ort mysql DB
# and write binary size data to a file
set -e
set -x
export PATH=/opt/python/cp37-cp37m/bin:$PATH
BUILD_DIR=${1:?"usage: $0 <build directory>"}
# Create an empty file to be used with build --include_ops_by_config, which will include no operators at all
echo -n > /home/onnxruntimedev/.test_data/include_no_operators.config
# Run a baseline minimal build of ORT Android arm64-v8a
# Generate binary size as /build/MinSizeRel/binary_size_data.txt
# Generate binary size as ${BUILD_DIR}/MinSizeRel/binary_size_data.txt
python3 /onnxruntime_src/tools/ci_build/build.py \
--build_dir /build --cmake_generator Ninja \
--build_dir ${BUILD_DIR} --cmake_generator Ninja \
--config MinSizeRel \
--skip_submodule_sync \
--parallel \
@ -33,7 +36,7 @@ BINARY_SIZE_LIMIT_IN_BYTES=1305000
echo "The current preset binary size limit is $BINARY_SIZE_LIMIT_IN_BYTES"
python3 /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/check_build_binary_size.py \
--threshold=$BINARY_SIZE_LIMIT_IN_BYTES \
/build/MinSizeRel/libonnxruntime.so
${BUILD_DIR}/MinSizeRel/libonnxruntime.so
echo "The content of binary_size_data.txt"
cat /build/MinSizeRel/binary_size_data.txt
cat ${BUILD_DIR}/MinSizeRel/binary_size_data.txt