Skip to content

tests: the local-baseline case does not measure CPU contention (macos-python's only red) - #2653

Merged
aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
fiestorra:fix/bench-baseline-threshold
Dec 1, 2026
Merged

aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
fiestorra:fix/bench-baseline-threshold

Conversation

@fiestorra

@fiestorra fiestorra commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

This changes a test's threshold, so it is the test owner's call rather than mine. It is not a draft pull request - if you would rather keep the old invocation, say so and I will close it.

The macos-python job's only failure is test_a_local_baseline_replaces_the_committed_one, and the assertion that fails is not about code:

File "…/tests/test_bench_translate.py", line 106
  self.assertEqual(result.returncode, 0, result.stderr)
AssertionError: 1 != 0 :

Exit 1 with empty stderr is scripts/bench_translate.py's own over-limit verdict (return 1 if slow else 0 for --json). Two runs seconds apart measured more than --max-slowdown 5 apart on a shared runner.

What the case is actually for, in its own comment: "The committed numbers come from one machine; on another they would fail a run with no regression in it" - it checks that a local baseline replaces the committed one, that baseline_source is that file, that the key sets match, and that no spurious regression is reported. The 5x limit was incidental to exercising the flag.

What the change is: the --max-slowdown 5 guard is removed from that one invocation - not raised - because scripts/bench_translate.py takes --max-slowdown with default=None and applies no limit at all when it is absent. The case keeps its intent (a local baseline replaces the committed one) without also measuring CPU contention. It also drops self.assertEqual(report["over_limit"], []), which only held while the guard existed, and asserts instead that the report's baseline is the file the test just wrote. The over-limit behaviour keeps its own deterministic coverage: --max-slowdown 0.01 must report one, asserted at line 48-51 against a synthetic baseline that cannot be noise.

Tested: python3 -m pytest tests/test_bench_translate.py -q -> 10 passed, 5 subtests, including the forced-regression case that still asserts a non-empty over_limit.

Not tested: on macOS, which is the job this is for - I have Windows only. What I can say is that the change cannot make the plumbing assertions weaker (they are untouched) and that the timing assertion is the only one removed.

If a maintainer would rather keep a performance threshold in this case, the alternative is to take the better of two written baselines, which is more code for the same purpose; I did not choose for you.

The extra commit at the tip (no longer carried)

The branch used to carry a3b5ebea1 (test(semantic): align computed-I/J f16 interp oracle…), added only because semantic-tests was red on main for that oracle and every branch cut from main inherited it. main now has the same edit as c717967d0, so a rebase drops the commit and this pull request no longer touches tests/semantic/test_interp_computed_ij_fallback.py - the diff is only what this change actually needs.

AI-assisted: yes - DeepSeek v4.1 (flash) as the coding agent, with a separate reviewer agent reading the change before submission. Where and on what: the measurements above were taken on Windows 11 with MSVC 19.44.35226 on an RTX 4090 (NVIDIA driver 621.24) where a C++ or GPU path is involved; Python and docs cases need none of it.

Written with an AI assistant.

@merzleckeier

Copy link
Copy Markdown
Contributor

I checked 2ec0571e (GitHub merge fe8b6003) against 452d1d1b on CachyOS with Python 3.14.10. The CLI for this case can omit --max-slowdown and check the saved numbers directly. I tested that change alongside the draft.

MEASURED. The full python3 -I tests/test_bench_translate.py -v run passed 10/10 in each tree. In a diagnostic replay I supplied the same recorded baseline to each tree and scaled only the second invocation's measured values. These are injected ratios.

Replay Base (5×) Draft (1000×) No limit in this case, compare saved values
8× 0/3 3/3 3/3
1024× 0/3 0/3 3/3

I also substituted the committed baseline values while leaving baseline_source set to the local file. The base and draft both passed that probe. The variant failed at dictionary equality, as intended.

The test-only change is to read json.load(handle)["measured"] from the file just written, run the second command with --baseline and --json without a limit, then check self.assertEqual(report["baseline"], written_measurements) alongside the existing path and key checks. The separate --max-slowdown tests still pass in both output formats and in --compare.

AI-assisted with OpenAI Codex.

@fiestorra

Copy link
Copy Markdown
Contributor Author

Your replay data settled it, and I took your variant rather than mine.

What your table showed: a 1000x limit is still a timing threshold - at a 1024x slowdown it failed 0/3, while comparing the run's baseline back against the file it was handed passed 3/3 in every replay. A limit measures the runner; the numbers do not.

What the branch now does (8fc90097c):

with open(path, encoding="utf-8") as handle:
    written = json.load(handle)["measured"]
result = run("--runs", "1", "--size", "20", "--baseline", path, "--json")
self.assertEqual(result.returncode, 0, result.stderr)
report = json.loads(result.stdout)
self.assertEqual(report["baseline_source"], os.path.abspath(path))
self.assertEqual(sorted(report["baseline"]), sorted(report["measured"]))
# The baseline is that file's own numbers, not the committed ones: substituting the latter fails here.
self.assertEqual(report["baseline"], written)

No --max-slowdown on that invocation at all, so the case asserts the thing its name says - a local baseline replaces the committed one - and nothing about CPU contention.

Checked here, in the direction you checked it: python3 -m pytest tests/test_bench_translate.py -q -> 10 passed, 5 subtests; and your negative control reproduced - substituting a different baseline makes the case fail (1 failed), so the new assertion is load-bearing rather than decorative. The --max-slowdown 0.01 case still reports an over-limit as before.

Thank you for measuring the 1024x point instead of accepting the 1000x; that is the difference between a patch that hides the flake and one that removes it.

Written with an AI assistant.

@fiestorra
fiestorra marked this pull request as ready for review November 29, 2026 22:45
@fiestorra

Copy link
Copy Markdown
Contributor Author

Ready for review now, for two reasons that are not mine:

python3 -m pytest tests/test_bench_translate.py tests/semantic/test_interp_computed_ij_fallback.py -q -> 19 passed, 18 subtests, and substituting a different baseline still fails the case (the assertion is load-bearing).

This is the last red standing between #2641 and a green board: macos-python is the only failing job on it.

Written with an AI assistant.

@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16, main 452d1d1, PR head 5faa965 (test-only PR, so "red" = main's version of the tests, "green" = this PR's version, both on main's code). MEASURED:

  • tests/semantic/test_interp_computed_ij_fallback.py (pytest): main's version 2 failed / 9 (test_p1lv_f16_computed_ij_uses_interpolated_attribute_not_vsrc2, test_perspective_fixture_branch_and_f16_halves); this PR's version 9/9 passed, 13 subtests.
  • tests/test_bench_translate.py (python3 -I, 3 runs each, idle machine): main's version 10/10 OK ×3, this PR's version 10/10 OK ×3. The CPU-contention failure did not reproduce here, so this run neither confirms nor refutes the flake; it only shows the new assertion passes.

Note: #2566 makes the same SHADER-468 RTZ change to test_interp_computed_ij_fallback.py, and this PR conflicts with #2566 on that file (git merge-tree of main+this PR against #2566). Splitting the test_bench_translate.py half out would let it land on its own.

AI-assisted: Claude Code

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Update by OreoFR: the conflict with #2566 I reported here is gone. main (1b0f657) now carries the SHADER-468 change to tests/semantic/test_interp_computed_ij_fallback.py (71db4c405), and this PR merges cleanly both with main and on top of main + #2566 (git merge-tree, checked 2026-11-30 11:10 local). Note also that my earlier check merged this PR with main first and then compared against #2566's head, which can report a conflict through an older merge base; I now check main + #2566 first, then the PR.

AI-assisted: Claude Code

test_a_local_baseline_replaces_the_committed_one asks that a locally written
baseline replaces the committed one; the 5x limit was incidental to that, and on
a shared runner it turned the case into a performance test whose only observed
failure was a contended box (macos-python on ProjectLeonida#2641: returncode 1 with empty
stderr, i.e. the tool's own over-limit verdict).

The over-limit behaviour keeps its deterministic coverage: --max-slowdown 0.01
must report one, and that case asserts it.

Written with an AI assistant.
merzleckeier measured what a bigger limit buys and it is not enough: at a 1024x
slowdown the 1000x draft still failed 0/3, while comparing the run's baseline
back against the file it was given passed 3/3. A limit measures the runner;
the numbers do not.

So the case now reads the measured values out of the baseline it just wrote and
asserts the second run used exactly those, with no --max-slowdown on that
invocation. The over-limit behaviour keeps its own deterministic test
(--max-slowdown 0.01 must report one), untouched.

Verified here: 10 passed, 5 subtests; and substituting a different baseline
makes the case fail (1 failed), which is what the assertion is for.

Written with an AI assistant.
@fiestorra
fiestorra force-pushed the fix/bench-baseline-threshold branch from 5faa965 to 7c99b8e Compare November 30, 2026 13:55
@fiestorra

Copy link
Copy Markdown
Contributor Author

Re-verified after the rebase onto main 20fe0c754, on this machine (Windows 11, MSVC 19.44.35226): the diff no longer carries the interp-oracle commit (main has it as c717967d0), and what is left still passes.

python3 -m pytest tests/test_bench_translate.py -q
10 passed, 5 subtests passed in 10.70s

What I did not test: the rest of the change, and anything the rebase did not touch. This confirms the rebase kept the change working, not that the change is correct - that is what the review and the CI are for.

Written with an AI assistant.

@aslan2142 aslan2142 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Comparing report["baseline"] directly against the written baseline file's measured dict in tests/test_bench_translate.py removes the CPU-contention flakiness while testing local baseline override deterministically. Clean-room verified, 5/5 CI green, and independently verified. Merging.

(AI-assisted review.)

@aslan2142
aslan2142 merged commit 678d1fb into ProjectLeonida:main Dec 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants