Skip to content

Commit 64f199d

Browse files
williamwen42meta-codesync[bot]
authored andcommitted
Move unbacked-parity regression policy into the benchmark; widen MobileBert (#189813)
Summary: The periodic inductor_huggingface_unbacked_parity job intermittently reds on MobileBertForMaskedLM with no real regression behind it. Its backed and unbacked compiled times are ~equal and land in a bimodal distribution independently, so the backed-vs-unbacked diff is ~+-2% autotune/measurement jitter -- centered at zero over 16 independent runs, and a pre-onset build reproduces the same variance, so it is not a code regression. Move the regression policy out of the CI shell script and into the benchmark (_run_compare_backed_unbacked in benchmarks/dynamo/common.py), next to the comparison itself, as a per-model threshold table (MobileBertForMaskedLM = 3.0%, others 1.0%). The benchmark now emits a canonical UNBACKED_PARITY_REGRESSION / UNBACKED_PARITY_OK verdict line, and .ci/pytorch/test.sh detects that line instead of re-deriving the threshold in bash. X-link: pytorch/pytorch#189813 Approved by: https://github.com/bobrenjc93 Reviewed By: jeanschmidt Differential Revision: D112002277 fbshipit-source-id: 8753da02d79cbf776ab1c82a00339a1c18d7c7dd
1 parent 423645d commit 64f199d

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

userbenchmark/dynamo/dynamobench/common.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,6 +4027,21 @@ def main(runner, original_dir=None, args=None):
40274027
process_entry(0, runner, original_dir, args)
40284028

40294029

4030+
# Per-model tolerance (percent) for the backed-vs-unbacked compiled-time parity
4031+
# check. Most models track backed vs unbacked to within ~0.5%. MobileBertForMaskedLM
4032+
# has bimodal compiled timings (backed and unbacked land in different modes
4033+
# independently), so its backed-vs-unbacked diff is ~+-2% run-to-run jitter with no
4034+
# directional regression; it gets a wider band so the noise doesn't red the periodic
4035+
# job while a genuine regression is still caught.
4036+
UNBACKED_PARITY_THRESHOLDS = {"MobileBertForMaskedLM": 3.0}
4037+
DEFAULT_UNBACKED_PARITY_THRESHOLD = 1.0
4038+
4039+
4040+
def _unbacked_parity_diff_pct(backed_ms, unbacked_ms):
4041+
"""Percent by which the unbacked compiled time exceeds the backed one."""
4042+
return (unbacked_ms - backed_ms) / backed_ms * 100
4043+
4044+
40304045
def _run_compare_backed_unbacked(runner, args):
40314046
"""Run backed and unbacked per-model, alternating, and compare speedup."""
40324047
import re
@@ -4045,7 +4060,7 @@ def print_comparison(all_results):
40454060
b_ms = modes.get("backed_ms")
40464061
u_ms = modes.get("unbacked_ms")
40474062
if b_ms is not None and u_ms is not None:
4048-
ms_diff_pct = (u_ms - b_ms) / b_ms * 100
4063+
ms_diff_pct = _unbacked_parity_diff_pct(b_ms, u_ms)
40494064
print(
40504065
f" {name:<40s} {b_ms:>10.3f} {u_ms:>11.3f} {ms_diff_pct:>+7.1f}%",
40514066
flush=True,
@@ -4158,7 +4173,7 @@ def print_comparison(all_results):
41584173
):
41594174
b_ms = all_results[model]["backed_ms"]
41604175
u_ms = all_results[model]["unbacked_ms"]
4161-
ms_diff_pct = (u_ms - b_ms) / b_ms * 100
4176+
ms_diff_pct = _unbacked_parity_diff_pct(b_ms, u_ms)
41624177
print(
41634178
f" => diff: {ms_diff_pct:+.1f}% ({b_ms:.3f} ms vs {u_ms:.3f} ms)",
41644179
flush=True,
@@ -4175,6 +4190,27 @@ def print_comparison(all_results):
41754190

41764191
print_comparison(all_results)
41774192

4193+
# Emit a canonical regression verdict using per-model thresholds. The CI
4194+
# wrapper (.ci/pytorch/test.sh) detects the UNBACKED_PARITY_REGRESSION line
4195+
# rather than re-deriving the threshold, so the policy lives here as data.
4196+
regressions = []
4197+
for name, modes in all_results.items():
4198+
b_ms = modes.get("backed_ms")
4199+
u_ms = modes.get("unbacked_ms")
4200+
if b_ms is not None and u_ms is not None:
4201+
diff_pct = _unbacked_parity_diff_pct(b_ms, u_ms)
4202+
threshold = UNBACKED_PARITY_THRESHOLDS.get(
4203+
name, DEFAULT_UNBACKED_PARITY_THRESHOLD
4204+
)
4205+
if diff_pct > threshold:
4206+
regressions.append(
4207+
f"{name}: +{diff_pct:.2f}% > {threshold:.1f}% threshold"
4208+
)
4209+
if regressions:
4210+
print(f"UNBACKED_PARITY_REGRESSION: {', '.join(regressions)}", flush=True)
4211+
else:
4212+
print("UNBACKED_PARITY_OK: no per-model regressions", flush=True)
4213+
41784214

41794215
def write_csv_when_exception(args, name: str, status: str, device=None):
41804216
print(status)

0 commit comments

Comments
 (0)