Skip to content

Commit e59cb94

Browse files
authored
Add CI build with type reduction enabled (#6622)
1 parent 352e8cb commit e59cb94

File tree

5 files changed

+121
-32
lines changed

5 files changed

+121
-32
lines changed

onnxruntime/test/testdata/required_ops_config.readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ required_ops.config:
77
List of all the required operators for .onnx models in the testdata directory.
88
Note that add_opset_314159.onnx adds a spurious opset for 'Add' so the config file will contain an entry for that.
99

10-
required_operators_and_types.config
10+
required_ops_and_types.config
1111
To generate/update:
1212
python ../../../tools/python/create_reduced_build_config.py --format ORT --enable_type_reduction . required_ops_and_types.config
1313
Contains:

tools/ci_build/github/azure-pipelines/linux-cpu-minimal-build-ci-pipeline.yml

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# and the models from <repo root>/onnxruntime/test/testdata/, run UT, and use onnx_test_runner to
88
# test the ort format models generated in step 1.
99
# Exceptions are enabled in this step to help debugging in case of CI failure.
10+
# This step builds and tests ORT with and without type reduction enabled.
1011
# 4. Build baseline minimal ORT for Android arm64-v8a including no kernels and disable exceptions
1112
# This step is to report the baseline binary size for Android
1213
jobs:
@@ -15,11 +16,23 @@ jobs:
1516
workspace:
1617
clean: all
1718
pool: Linux-CPU
19+
20+
variables:
21+
test_data_directory: $(Build.SourcesDirectory)/.test_data
22+
1823
steps:
1924
- checkout: self
2025
clean: true
2126
submodules: recursive
2227

28+
- task: CmdLine@2
29+
displayName: Create test data directory
30+
inputs:
31+
script: |
32+
# Create a folder for all test data
33+
mkdir -p $(test_data_directory)
34+
workingDirectory: $(Build.SourcesDirectory)
35+
2336
- template: templates/get-docker-image-steps.yml
2437
parameters:
2538
Dockerfile: tools/ci_build/github/linux/docker/Dockerfile.centos
@@ -31,23 +44,22 @@ jobs:
3144
displayName: Build full onnxruntime and generate ORT format test files
3245
inputs:
3346
script: |
34-
# Create a folder for all test data
35-
mkdir -p $HOME/.test_data
3647
docker run --rm \
3748
--volume $(Build.SourcesDirectory):/onnxruntime_src \
3849
--volume $(Build.BinariesDirectory):/build \
39-
--volume $HOME/.test_data:/home/onnxruntimedev/.test_data \
50+
--volume $(test_data_directory):/home/onnxruntimedev/.test_data \
4051
-e ALLOW_RELEASED_ONNX_OPSET_ONLY=1 \
4152
-e NIGHTLY_BUILD \
4253
-e BUILD_BUILDNUMBER \
4354
onnxruntimecentoscpubuild \
4455
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_full_ort_and_create_ort_files.sh
4556
workingDirectory: $(Build.SourcesDirectory)
57+
4658
- task: CmdLine@2
47-
displayName: Build minimal onnxruntime with exceptions disabled
59+
displayName: Build minimal onnxruntime [exceptions DISABLED, type reduction DISABLED]
4860
inputs:
4961
script: |
50-
# We will try to build the ORT minimal with exception disabled
62+
# We will try to build minimal ORT with exceptions disabled
5163
# Only the building process is verified here, no test will be performed
5264
docker run --rm \
5365
--volume $(Build.SourcesDirectory):/onnxruntime_src \
@@ -66,31 +78,59 @@ jobs:
6678
--minimal_build \
6779
--disable_exceptions
6880
workingDirectory: $(Build.SourcesDirectory)
81+
6982
- task: CmdLine@2
70-
displayName: Build minimal onnxruntime and run tests with exceptions enabled
83+
displayName: Build minimal onnxruntime [exceptions ENABLED, type reduction DISABLED] and run tests
7184
inputs:
7285
script: |
7386
docker run --rm \
7487
--volume $(Build.SourcesDirectory):/onnxruntime_src \
7588
--volume $(Build.BinariesDirectory):/build \
76-
--volume $HOME/.test_data:/home/onnxruntimedev/.test_data \
89+
--volume $(test_data_directory):/home/onnxruntimedev/.test_data \
7790
-e ALLOW_RELEASED_ONNX_OPSET_ONLY=1 \
7891
-e NIGHTLY_BUILD \
7992
-e BUILD_BUILDNUMBER \
8093
onnxruntimecentoscpubuild \
81-
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_minimal_ort_and_run_tests.sh
94+
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_minimal_ort_and_run_tests.sh \
95+
--build-directory /build/without_type_reduction \
96+
--reduced-ops-config /home/onnxruntimedev/.test_data/required_ops.ort_models.config
8297
workingDirectory: $(Build.SourcesDirectory)
98+
99+
- script: git checkout -- .
100+
displayName: Discard local changes to Git repository files
101+
workingDirectory: $(Build.SourcesDirectory)
102+
103+
- task: CmdLine@2
104+
displayName: Build minimal onnxruntime [exceptions ENABLED, type reduction ENABLED] and run tests
105+
inputs:
106+
script: |
107+
docker run --rm \
108+
--volume $(Build.SourcesDirectory):/onnxruntime_src \
109+
--volume $(Build.BinariesDirectory):/build \
110+
--volume $(test_data_directory):/home/onnxruntimedev/.test_data \
111+
-e ALLOW_RELEASED_ONNX_OPSET_ONLY=1 \
112+
-e NIGHTLY_BUILD \
113+
-e BUILD_BUILDNUMBER \
114+
onnxruntimecentoscpubuild \
115+
/bin/bash /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/build_minimal_ort_and_run_tests.sh \
116+
--build-directory /build/with_type_reduction \
117+
--reduced-ops-config /home/onnxruntimedev/.test_data/required_ops_and_types.ort_models.config \
118+
--enable-type-reduction
119+
workingDirectory: $(Build.SourcesDirectory)
120+
121+
- script: git checkout -- .
122+
displayName: Discard local changes to Git repository files
123+
workingDirectory: $(Build.SourcesDirectory)
124+
83125
- task: CmdLine@2
84126
displayName: Build onnxruntime minimal baseline for Android arm64-v8a and report binary size
85127
inputs:
86128
script: |
87-
# Create a folder for all test data
88-
mkdir -p $HOME/.test_data
89129
docker run --rm \
90130
--volume $(Build.SourcesDirectory):/onnxruntime_src \
91131
--volume $(Build.BinariesDirectory):/build \
92132
--volume $ANDROID_HOME:/android_home \
93-
--volume $HOME/.test_data:/home/onnxruntimedev/.test_data \
133+
--volume $(test_data_directory):/home/onnxruntimedev/.test_data \
94134
-e ALLOW_RELEASED_ONNX_OPSET_ONLY=1 \
95135
-e NIGHTLY_BUILD \
96136
-e BUILD_BUILDNUMBER \

tools/ci_build/github/linux/ort_minimal/build_full_ort_and_create_ort_files.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
set -e
77
set -x
88

9-
# Validate the operator kernel registrations, as the ORT model uses hashes of the kernel registration details
9+
# Validate the operator kernel registrations, as the ORT model uses hashes of the kernel registration details
1010
# to find kernels. If the hashes from the registration details are incorrect we will produce a model that will break
1111
# when the registration is fixed in the future.
1212
python3 /onnxruntime_src/tools/ci_build/op_registration_validator.py
@@ -26,25 +26,23 @@ python3 /onnxruntime_src/tools/ci_build/build.py \
2626
# Install the ORT python wheel
2727
python3 -m pip install --user /build/Debug/dist/*
2828

29-
# Convert all the E2E ONNX models to ORT format
29+
# Convert all the E2E ONNX models to ORT format
3030
python3 /onnxruntime_src/tools/python/convert_onnx_models_to_ort.py \
3131
/onnxruntime_src/onnxruntime/test/testdata/ort_minimal_e2e_test_data
3232

33-
# Create a config with just the required ops for ORT format models in testdata
34-
# This is used by build_minimal_ort_and_run_tests.sh later in the linux-cpu-minimal-build-ci-pipeline CI
33+
# Create configs with just the required ops for ORT format models in testdata
34+
# These are used by build_minimal_ort_and_run_tests.sh later in the linux-cpu-minimal-build-ci-pipeline CI
3535
# and will include ops for the E2E models we just converted
36+
37+
# Config without type reduction
3638
python3 /onnxruntime_src/tools/python/create_reduced_build_config.py --format ORT \
3739
/onnxruntime_src/onnxruntime/test/testdata \
38-
/onnxruntime_src/onnxruntime/test/testdata/required_ops.ort_models.config
40+
/home/onnxruntimedev/.test_data/required_ops.ort_models.config
3941

40-
# Re-create testdata/required_ops_and_types.config.
41-
# This is meaningful when nnapi_minimal_build_minimal_ort_and_run_tests.sh runs later in the
42-
# linux-cpu-minimal-build-ci-pipeline CI, as recreating the configs checks that we are still creating
43-
# a valid config. We have a checked in version of the file for use in other CIs where we don't do a full ORT
44-
# build as part of the CI, such as the android-x86_64-crosscompile-ci-pipeline CI.
42+
# Config with type reduction
4543
python3 /onnxruntime_src/tools/python/create_reduced_build_config.py --format ORT --enable_type_reduction \
4644
/onnxruntime_src/onnxruntime/test/testdata \
47-
/onnxruntime_src/onnxruntime/test/testdata/required_ops_and_types.config
45+
/home/onnxruntimedev/.test_data/required_ops_and_types.ort_models.config
4846

4947
# Clear the build
5048
rm -rf /build/Debug

tools/ci_build/github/linux/ort_minimal/build_minimal_ort_and_run_tests.sh

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,75 @@
22

33
# This script will create a minimal build with the required operators for all ORT format models
44
# in the testdata directory. This includes E2E models generated by build_full_ort_and_create_ort_files.sh.
5-
# The build will run the unit tests for the minimal build, followed by running onnx_test_runner
5+
# The build will run the unit tests for the minimal build, followed by running onnx_test_runner
66
# for the E2E test cases.
77

8-
98
set -e
109
set -x
1110

11+
USAGE_TEXT="Usage:
12+
-b|--build-directory <build directory>
13+
Specifies the build directory. Required.
14+
-c|--reduced-ops-config <reduced Ops config file>
15+
Specifies the reduced Ops configuration file path. Required.
16+
[--enable-type-reduction]
17+
Builds with type reduction enabled."
18+
19+
BUILD_DIR=
20+
REDUCED_OPS_CONFIG_FILE=
21+
ENABLE_TYPE_REDUCTION=
22+
23+
while [[ $# -gt 0 ]]
24+
do
25+
OPTION_KEY="$1"
26+
case $OPTION_KEY in
27+
-b|--build-directory)
28+
BUILD_DIR="$2"
29+
shift
30+
shift
31+
;;
32+
-c|--reduced-ops-config)
33+
REDUCED_OPS_CONFIG_FILE="$2"
34+
shift
35+
shift
36+
;;
37+
--enable-type-reduction)
38+
ENABLE_TYPE_REDUCTION=1
39+
shift
40+
;;
41+
*)
42+
echo "Invalid option: $1"
43+
echo "$USAGE_TEXT"
44+
exit 1
45+
;;
46+
esac
47+
done
48+
49+
if [[ -z "${BUILD_DIR}" || -z "${REDUCED_OPS_CONFIG_FILE}" ]]; then
50+
echo "Required option was not provided."
51+
echo "$USAGE_TEXT"
52+
exit 1
53+
fi
54+
1255
# Perform a minimal build with required ops and run ORT minimal build UTs
1356
python3 /onnxruntime_src/tools/ci_build/build.py \
14-
--build_dir /build --cmake_generator Ninja \
57+
--build_dir ${BUILD_DIR} --cmake_generator Ninja \
1558
--config Debug \
1659
--skip_submodule_sync \
1760
--build_shared_lib \
1861
--parallel \
1962
--minimal_build \
2063
--disable_ml_ops \
21-
--include_ops_by_config /onnxruntime_src/onnxruntime/test/testdata/required_ops.ort_models.config
64+
--include_ops_by_config ${REDUCED_OPS_CONFIG_FILE} \
65+
${ENABLE_TYPE_REDUCTION:+"--enable_reduced_operator_type_support"}
2266

2367
# Run the e2e test cases
24-
/build/Debug/onnx_test_runner /onnxruntime_src/onnxruntime/test/testdata/ort_minimal_e2e_test_data
68+
${BUILD_DIR}/Debug/onnx_test_runner /onnxruntime_src/onnxruntime/test/testdata/ort_minimal_e2e_test_data
69+
70+
# Print binary size info
71+
python3 /onnxruntime_src/tools/ci_build/github/linux/ort_minimal/check_build_binary_size.py \
72+
--arch "$(uname -m)" --os "$(uname -o)" --build_config "minimal-reduced" \
73+
${BUILD_DIR}/Debug/libonnxruntime.so
74+
75+
echo "Binary size info:"
76+
cat ${BUILD_DIR}/Debug/binary_size_data.txt

tools/ci_build/github/linux/ort_minimal/check_build_binary_size.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _check_binary_size(path, readelf, threshold, os_str, arch, build_config):
3333
'{},{},{},{}\n'.format(os_str, arch, build_config, sections_total)
3434
])
3535

36-
if sections_total > threshold:
36+
if threshold is not None and sections_total > threshold:
3737
raise RuntimeError('Sections total size for {} of {} exceeds threshold of {} by {}. On-disk size={}'
3838
.format(path, sections_total, threshold, sections_total - threshold, ondisk_size))
3939

@@ -42,10 +42,9 @@ def main():
4242
argparser = argparse.ArgumentParser(description='Check the binary size for provided path and '
4343
'create a text file for upload to the performance dashboard.')
4444

45-
# required
46-
argparser.add_argument('-t', '--threshold', type=int, required=True,
47-
help='Return error if binary size exceeds this threshold.')
4845
# optional
46+
argparser.add_argument('-t', '--threshold', type=int,
47+
help='Return error if binary size exceeds this threshold.')
4948
argparser.add_argument('-r', '--readelf_path', type=str, default='readelf', help='Path to readelf executable.')
5049
argparser.add_argument('--os', type=str, default='android',
5150
help='OS value to include in binary_size_data.txt')

0 commit comments

Comments
 (0)