Skip to content

test(autotune): stop pinning the rep-scaling test to an exact ceiling - #990

Merged
inureyes merged 1 commit into
mainfrom
fix/autotune-rep-scaling-test-flake
Aug 1, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/autotune-rep-scaling-test-flake

Conversation

@inureyes

@inureyes inureyes commented Aug 1, 2026

Copy link
Copy Markdown
Member

Summary

autotune::autotune_tests::timed_repetitions_scale_inversely_with_launch_cost is flaky. It passes in isolation and fails under full-suite parallelism, where more than 1200 tests contend for the machine. This replaces the load-sensitive assertion with the property the test actually exists to check.

Cause

FakeOp::run simulates launch cost with std::thread::sleep, which can overshoot its requested duration but never undershoot it. Under contention a declared 100us launch measures far slower, so the fixed 50ms sample budget buys fewer repetitions and the realized count lands below the ceiling. The test then failed its assert_eq!(reps, 64). Nothing in the autotuner is wrong; the assertion was measuring host load rather than the behaviour under test.

Fix

The property is that sampling effort scales inversely with launch cost, not that a cheap launch reaches one specific number. The test now asserts that shape: the cheap launch samples well above the floor and stays within the ceiling, the costly launch reaches the floor exactly, and cheap outsamples costly. The costly direction keeps its equality deliberately, because overshooting a 20ms sleep only exhausts the budget sooner, so the floor is reached under any amount of load and that assertion cannot go flaky in the same way.

Verification

Run on Apple M1 Ultra with --features metal,accelerate, both in isolation and under the full-suite condition that originally exposed the failure.

  • cargo test --release -p mlxcel-core --lib --features metal,accelerate autotune:: gives 55 passed.
  • cargo test -p mlxcel-core --release --features metal,accelerate gives 1203 passed, 1 failed, where the single remaining failure is the pre-existing fused_moe_parity_tests::fused_moe_geglu_kernel_matches_references_gemma4_shape tracked in fix(tests): fused MoE GeGLU parity threshold is tighter than the gather_qmm reference's own jitter #964 and unrelated to this change.
  • cargo clippy -p mlxcel-core --lib --tests --features metal,accelerate -- -D warnings and cargo fmt --all -- --check are clean.

Context

Introduced by #906 and found while validating a later sub-issue of epic #909, where it was the only new failure in an otherwise clean regression run. Worth fixing rather than tolerating, because this repository's CI does not run the test suite, so a local full-suite run is the project's real gate and an intermittent failure there costs someone a misattributed investigation.

Refs #906, #909

`timed_repetitions_scale_inversely_with_launch_cost` asserted that a cheap fake launch lands on exactly 64 repetitions. It passed in isolation and failed under full-suite parallelism, where more than 1200 tests contend for the machine.

The cause is that `FakeOp::run` simulates cost with `std::thread::sleep`, which can overshoot its request but never undershoot it. Contention inflates the measured per-iteration cost, the budget therefore buys fewer repetitions, and the realized count falls below the ceiling. Nothing about the autotuner is wrong; the assertion was measuring the host rather than the property.

The property under test is that sampling effort scales inversely with launch cost, so the test now asserts that shape instead of one number: the cheap launch must sample well above the floor and stay within the ceiling, the costly launch must reach the floor exactly, and cheap must outsample costly. The costly direction stays an equality because overshooting a 20ms sleep only exhausts the budget sooner, so the floor is reached under any amount of load.

Introduced in #906 and found while validating a later sub-issue of epic #909, where it was the only new failure in an otherwise clean regression run.
@inureyes inureyes added type:test Test related changes area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:medium Medium priority status:done Completed labels Aug 1, 2026
@inureyes
inureyes merged commit 3cc62f7 into main Aug 1, 2026
5 checks passed
@inureyes
inureyes deleted the fix/autotune-rep-scaling-test-flake branch August 1, 2026 15:27
@inureyes inureyes self-assigned this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:medium Medium priority status:done Completed type:test Test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant