Skip to content

Commit 143c585

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 143c585

4 files changed

Lines changed: 33 additions & 13 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. Default is tight
20+
# for fp32 models; 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: 3 additions & 3 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(

examples/arm/executor_runner/arm_executor_runner.cpp

Lines changed: 19 additions & 8 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,7 +1195,7 @@ int main(int argc, const char* argv[]) {
11921195
ET_LOG(Fatal, "Not right number of parameters!");
11931196
ET_LOG(
11941197
Fatal,
1195-
"app -m model.pte -i input.bin [-i input2.bin] -o output_basename");
1198+
"app -m model.pte -i input.bin [-i input2.bin] -o output_basename [-atol 0.001] [-rtol 0.001]");
11961199
ET_LOG(Fatal, "Exiting!");
11971200
_exit(1);
11981201
}
@@ -1265,6 +1268,14 @@ int main(int argc, const char* argv[]) {
12651268
} else if (std::strcmp(argv[i], "-o") == 0) {
12661269
// store the base filename to write output to.
12671270
ctx.output_basename = argv[++i];
1271+
#if defined(ET_BUNDLE_IO)
1272+
} else if (std::strcmp(argv[i], "-atol") == 0) {
1273+
sscanf(argv[++i], "%f", &et_atol);
1274+
ET_LOG(Info, "Setting atol to %f", et_atol);
1275+
} else if (std::strcmp(argv[i], "-rtol") == 0) {
1276+
sscanf(argv[++i], "%f", &et_rtol);
1277+
ET_LOG(Info, "Setting rtol to %f", et_rtol);
1278+
#endif
12681279
}
12691280
}
12701281
#endif

0 commit comments

Comments
 (0)