Skip to content

Commit 45215f4

Browse files
committed
Make BundleIO ATOL/RTOL configurable per-test via runtime args
Previously tolerances were compile-time constants (ET_ATOL=5.0, ET_RTOL=1.0) baked into the executor runner binary, applied uniformly to all models. This masked numerical regressions on precise models. Add -atol and -rtol CLI args to the semihosting runner so tolerances can be set per-model at runtime. Tighten defaults to 1e-3 and move per-model overrides to a lookup table in test_cortex_m_e2e.sh. Resolves #18424
1 parent c11ba1b commit 45215f4

4 files changed

Lines changed: 52 additions & 23 deletions

File tree

.ci/scripts/test_cortex_m_e2e.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
set -eux
1515

1616
MODEL=$1
17+
18+
# Per-model BundleIO tolerances. Int8 quantized models need relaxed bounds
19+
# due to quantization error accumulating through layers. Models not listed
20+
# use the tight default (1e-3); override here for models that need it.
21+
declare -A MODEL_ATOL=( [mv2]="5.0" [mv3]="5.0" )
22+
declare -A MODEL_RTOL=( [mv2]="2.5" [mv3]="2.5" )
23+
ATOL="${MODEL_ATOL[$MODEL]:-1e-3}"
24+
RTOL="${MODEL_RTOL[$MODEL]:-1e-3}"
25+
1726
mkdir -p "./cortex_m_e2e/${MODEL}"
1827
WORK_DIR=$(realpath "./cortex_m_e2e/${MODEL}")
1928

@@ -51,7 +60,7 @@ FVP_Corstone_SSE-300_Ethos-U55 \
5160
-C cpu0.semihosting-heap_limit=0 \
5261
-C "cpu0.semihosting-cwd=${WORK_DIR}" \
5362
-C "ethosu.extra_args='--fast'" \
54-
-C "cpu0.semihosting-cmd_line='executor_runner -m ${MODEL}.bpte -i dummy.bin -o out'" \
63+
-C "cpu0.semihosting-cmd_line='executor_runner -m ${MODEL}.bpte -i dummy.bin -o out -atol ${ATOL} -rtol ${RTOL}'" \
5564
-a "${ELF}" \
5665
--timelimit 300 2>&1 | tee "${LOG_FILE}" || true
5766

backends/cortex_m/test/build_test_runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ aten::unsqueeze_copy.out,\
3131
aten::select_copy.int_out,\
3232
aten::amax.out"
3333

34-
${build_executor_runner} --pte=semihosting --bundleio --target=ethos-u55-128 --output="${build_root_test_dir}" --select_ops_list="${select_ops_list}" --extra_build_flags="-DET_ATOL=5.0 -DET_RTOL=1.0"
34+
${build_executor_runner} --pte=semihosting --bundleio --target=ethos-u55-128 --output="${build_root_test_dir}" --select_ops_list="${select_ops_list}"

examples/arm/executor_runner/CMakeLists.txt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ option(ET_LOG_DUMP_OUTPUT "Dump output in log" ON)
2222

2323
option(ET_BUNDLE_IO "Set to compile in BundleIO support" OFF)
2424
set(ET_ATOL
25-
"0.01"
25+
"1e-3"
2626
CACHE STRING "Set atol to use for BundleIO testing (Requires ET_BUNDLE_IO)"
2727
)
2828
set(ET_RTOL
29-
"0.01"
30-
CACHE STRING "Set atol to use for BundleIO testing (Requires ET_BUNDLE_IO)"
29+
"1e-3"
30+
CACHE STRING "Set rtol to use for BundleIO testing (Requires ET_BUNDLE_IO)"
3131
)
3232

3333
option(
@@ -415,14 +415,12 @@ endif()
415415

416416
if(ET_BUNDLE_IO)
417417
target_compile_definitions(arm_executor_runner PUBLIC -DET_BUNDLE_IO)
418-
endif()
419-
420-
if(ET_ATOL)
421-
target_compile_definitions(arm_executor_runner PUBLIC ET_ATOL=${ET_ATOL})
422-
endif()
423-
424-
if(ET_RTOL)
425-
target_compile_definitions(arm_executor_runner PUBLIC ET_RTOL=${ET_RTOL})
418+
if(DEFINED ET_ATOL)
419+
target_compile_definitions(arm_executor_runner PUBLIC ET_ATOL=${ET_ATOL})
420+
endif()
421+
if(DEFINED ET_RTOL)
422+
target_compile_definitions(arm_executor_runner PUBLIC ET_RTOL=${ET_RTOL})
423+
endif()
426424
endif()
427425

428426
# Devtools ETDump: Speed and dumping output

examples/arm/executor_runner/arm_executor_runner.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
* use bpte with bundled input and output refdata to
3232
* compare output.
3333
* See also ET_ATOL and ET_RTOL
34-
* ET_ATOL - The atol used to compare the output and ref data
35-
* when using ET_BUNDLE_IO ET_RTOL - The rtol used to compare the
36-
* output and ref data when using ET_BUNDLE_IO
34+
* ET_ATOL - The absolute tolerance used to compare output and
35+
* ref data when using ET_BUNDLE_IO.
36+
* Can be overridden at runtime with -atol <value>.
37+
* ET_RTOL - The relative tolerance used to compare output and
38+
* ref data when using ET_BUNDLE_IO.
39+
* Can be overridden at runtime with -rtol <value>.
3740
*
3841
* Devtools ETDump: Speed and dumping output
3942
*
@@ -221,15 +224,15 @@ unsigned char __attribute__((
221224
const size_t testset_idx = 0; // BundleIO test indexes to test if used
222225

223226
#if defined(ET_ATOL)
224-
const float et_atol = ET_ATOL;
227+
float et_atol = ET_ATOL;
225228
#else
226-
const float et_atol = 0.01;
229+
float et_atol = 1e-3f;
227230
#endif
228231

229232
#if defined(ET_RTOL)
230-
const float et_rtol = ET_RTOL;
233+
float et_rtol = ET_RTOL;
231234
#else
232-
const float et_rtol = 0.01;
235+
float et_rtol = 1e-3f;
233236
#endif
234237

235238
#endif
@@ -1192,13 +1195,16 @@ int main(int argc, const char* argv[]) {
11921195
ET_LOG(Fatal, "Not right number of parameters!");
11931196
ET_LOG(
11941197
Fatal,
1198+
#if defined(ET_BUNDLE_IO)
1199+
"app -m model.pte -i input.bin [-i input2.bin] -o output_basename [-atol 0.001] [-rtol 0.001]");
1200+
#else
11951201
"app -m model.pte -i input.bin [-i input2.bin] -o output_basename");
1202+
#endif
11961203
ET_LOG(Fatal, "Exiting!");
11971204
_exit(1);
11981205
}
1199-
ET_LOG(Info, " %s", argv[0]);
1200-
for (int i = 1; i < argc; i++) {
1201-
ET_LOG(Info, " %s %s", argv[i], argv[++i]);
1206+
for (int i = 0; i < argc; i++) {
1207+
ET_LOG(Info, " %s", argv[i]);
12021208
}
12031209
#else
12041210
(void)argc;
@@ -1265,6 +1271,22 @@ int main(int argc, const char* argv[]) {
12651271
} else if (std::strcmp(argv[i], "-o") == 0) {
12661272
// store the base filename to write output to.
12671273
ctx.output_basename = argv[++i];
1274+
#if defined(ET_BUNDLE_IO)
1275+
} else if (std::strcmp(argv[i], "-atol") == 0) {
1276+
if (i + 1 < argc && sscanf(argv[++i], "%f", &et_atol) == 1) {
1277+
ET_LOG(Info, "Setting atol to %f", et_atol);
1278+
} else {
1279+
ET_LOG(Fatal, "Invalid or missing value for -atol");
1280+
_exit(1);
1281+
}
1282+
} else if (std::strcmp(argv[i], "-rtol") == 0) {
1283+
if (i + 1 < argc && sscanf(argv[++i], "%f", &et_rtol) == 1) {
1284+
ET_LOG(Info, "Setting rtol to %f", et_rtol);
1285+
} else {
1286+
ET_LOG(Fatal, "Invalid or missing value for -rtol");
1287+
_exit(1);
1288+
}
1289+
#endif
12681290
}
12691291
}
12701292
#endif

0 commit comments

Comments
 (0)