From c1e39f65c25a291d0b94f2a6779a7804ad8e9b03 Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Tue, 1 Dec 2026 09:05:24 -0700 Subject: [PATCH] Reconcile allocation flags contradicted by existing benchmark confirmation A reversed-order run already triggered by timing can explicitly reverse an allocation finding. The old helper retained every initial allocation result even when that repeat crossed the opposite threshold, so the report could still gate on contradicted evidence. Preserve standalone allocation gates, missing or neutral repeats, consistent regressions, thresholds, advisory pairing and the timing-only repeat trigger. Move only explicit allocs/memory direction conflicts into the existing inconclusive list, and show them accurately in CPU/GPU reports alongside the reversed allocation table. On Julia 1.10.11 and 1.13.4 the comparator suite passes 93 assertions; the old helper with the same regression tests gives 90 passes and 3 failures. Replaying the saved #850 allocation scalars (1.37155 initial versus 0.73257 reversed, two actual trial samples each) gives 5 passes/2 failures before and 7/7 after. CPU and GPU renderer suites plus comment tests pass; no benchmarks or hosted CI were rerun, and no intrinsic allocation parity is claimed. Written by an AI agent on jpsamaroo's review feedback. --- .buildkite/gpu_benchmark_report.py | 10 +++---- .buildkite/test_gpu_benchmark_report.py | 15 +++++++++++ .github/scripts/benchmark-report.cjs | 8 +++--- .github/scripts/benchmark-report.test.cjs | 11 ++++++++ AGENTS.md | 3 +++ benchmark/ci.jl | 14 ++++++---- benchmark/compare.jl | 28 +++++++++++++------ benchmark/compare_tests.jl | 33 +++++++++++++++++++++++ 8 files changed, 100 insertions(+), 22 deletions(-) diff --git a/.buildkite/gpu_benchmark_report.py b/.buildkite/gpu_benchmark_report.py index 775d50c84..5e51dbd13 100644 --- a/.buildkite/gpu_benchmark_report.py +++ b/.buildkite/gpu_benchmark_report.py @@ -48,8 +48,8 @@ def render(root, url, commit, section, limit=100): if shards or vendor in expected: groups.append((f"{label} {topology}", shards, vendor_suites)) lines = [f"", "## GPU benchmarks", "", - "Timing regressions require five samples per revision and independent confirmation.", "", - "| Backend | Regressions | Improvements | Within noise | Inconclusive time | Suites |", + "Timing regressions require five samples per revision and independent confirmation. Allocation changes explicitly contradicted by that existing repeat are inconclusive; missing or neutral repeats retain the original allocation gate.", "", + "| Backend | Regressions | Improvements | Within noise | Inconclusive metrics | Suites |", "|:---|---:|---:|---:|---:|:---|"] totals = {key: [] for key in CATEGORIES} for label, shards, vendor_suites in groups: @@ -74,7 +74,7 @@ def changes(entries): lines.extend(["", f"### GPU {category} across all backends", "", *changes(totals[category])]) for label, shards, vendor_suites in groups: lines.extend(["", "
", f"{label}", "", - "| Suite | Regressions | Improvements | Within noise | Inconclusive time |", + "| Suite | Regressions | Improvements | Within noise | Inconclusive metrics |", "|:---|---:|---:|---:|---:|"]) by_suite = dict(shards) for suite in vendor_suites: @@ -83,10 +83,10 @@ def changes(entries): lines.append(f"| {suite} (missing or invalid report) | — | — | — | — |") else: lines.append(f"| {suite} | " + " | ".join(str(len(data[key])) for key in CATEGORIES) + " |") - for category in ("regressions", "improvements"): + for category in ("regressions", "improvements", "insufficient"): entries = [(label, entry) for _, data in shards if "error" not in data for entry in data[category]] if entries: - lines.extend(["", f"#### {category.capitalize()}", "", *changes(entries)]) + lines.extend(["", f"#### {'Inconclusive metric changes' if category == 'insufficient' else category.capitalize()}", "", *changes(entries)]) lines.extend(["", "
"]) lines.extend(["", f"[GPU results and plots on Buildkite]({url})", f""]) return "\n".join(lines) diff --git a/.buildkite/test_gpu_benchmark_report.py b/.buildkite/test_gpu_benchmark_report.py index 01b87407a..2f2a914b6 100644 --- a/.buildkite/test_gpu_benchmark_report.py +++ b/.buildkite/test_gpu_benchmark_report.py @@ -33,6 +33,21 @@ def test_summary_and_missing_suites(self): body = report.render(root, "build", "abc", "pipeline") self.assertIn("| CUDA GPU+MPI | — | — | — | — | 0/4 |", body) + def test_inconclusive_allocation_is_visible(self): + with tempfile.TemporaryDirectory() as directory, patch.dict(os.environ, {"BENCHMARK_GPU_VENDORS": "cuda"}): + root = Path(directory) + shard = root / "benchmark-results-cuda-gpu-array" + shard.mkdir() + data = {"schema_version": 1, "jobs": [{}], "regressions": [], + "improvements": [], "within_noise": [], + "insufficient": [{"name": "svd", "ratio": 1.3715477533805658, "metric": "allocs"}]} + (shard / "summary.json").write_text(json.dumps(data)) + body = report.render(root, "build", "abc", "pipeline") + self.assertIn("Inconclusive metrics", body) + self.assertIn("Inconclusive metric changes", body) + self.assertIn("| CUDA GPU | 0 | 0 | 0 | 1 | 1/4 |", body) + self.assertIn("| CUDA GPU | `svd` | allocs | +37.2% |", body) + def test_preserves_current_cpu_and_other_pipeline(self): cpu = "\n\nCPU results" other = "\nOther GPU\n" diff --git a/.github/scripts/benchmark-report.cjs b/.github/scripts/benchmark-report.cjs index 904364b98..2a0c4ea61 100644 --- a/.github/scripts/benchmark-report.cjs +++ b/.github/scripts/benchmark-report.cjs @@ -67,8 +67,8 @@ function sortChanges(entries, improvement = false) { function renderReport(results, runUrl, limit) { const parts = [marker, '## Dagger benchmarks: `dirty` vs `master`', '', - 'Counts are benchmark metrics (time, allocations, bytes). Timing changes require non-overlapping median ± IQR bands; both revisions need at least five timed samples, and timing regressions need an independent confirmation run.', '', - '| Backend | Regressions | Improvements | Within noise | Inconclusive time | Suites |', + 'Counts are benchmark metrics (time, allocations, bytes). Timing changes require non-overlapping median ± IQR bands; both revisions need at least five timed samples, and timing regressions need an independent confirmation run. Allocation changes explicitly contradicted by that existing repeat are inconclusive; missing or neutral repeats retain the original allocation gate.', '', + '| Backend | Regressions | Improvements | Within noise | Inconclusive metrics | Suites |', '|:---|---:|---:|---:|---:|:---|']; for (const backend of results) { parts.push(`| ${backend.label} | ${countCells(backend.available ? backend : null)} | ${backend.available}/${suites.length} |`); @@ -92,13 +92,13 @@ function renderReport(results, runUrl, limit) { for (const backend of results) { parts.push('', '
', `${backend.label} (${backend.topology}) — ${backend.available ? `${backend.regressions.length} regressions, ${backend.improvements.length} improvements` : 'results unavailable'}`, '', - '| Suite | Regressions | Improvements | Within noise | Inconclusive time |', + '| Suite | Regressions | Improvements | Within noise | Inconclusive metrics |', '|:---|---:|---:|---:|---:|'); for (const shard of backend.shards) { parts.push(`| ${shard.suite}${shard.error ? ` (${shard.error})` : ''} | ${countCells(shard.data)} |`); } for (const [key, title] of [['regressions', 'Regressions'], ['improvements', 'Improvements'], - ['within_noise', 'Within noise'], ['insufficient', 'Inconclusive timing changes']]) { + ['within_noise', 'Within noise'], ['insufficient', 'Inconclusive metric changes']]) { if (!backend[key].length) continue; parts.push('', `#### ${title}`, '', changesTable(sortChanges(backend[key], key === 'improvements'), limit, false)); } diff --git a/.github/scripts/benchmark-report.test.cjs b/.github/scripts/benchmark-report.test.cjs index b74c6d99b..cea7e9ec8 100644 --- a/.github/scripts/benchmark-report.test.cjs +++ b/.github/scripts/benchmark-report.test.cjs @@ -85,3 +85,14 @@ test('escapes benchmark names and bounds oversized comments without losing total assert.equal(body.match(/
/g).length, backends.length); assert.equal(body.match(/<\/details>/g).length, backends.length); }); + +test('contradictory allocation metrics stay visible as inconclusive', t => { + const root = fixture(t); + write(root, 'default', 'linalg', { insufficient: [entry('linalg/dagger/svd', 1.3715477533805658, 'allocs')] }); + const body = buildReport(root, 'https://example.com/run'); + assert.match(body, /Inconclusive metrics/); + assert.match(body, /Inconclusive metric changes/); + assert.match(body, /Allocation changes explicitly contradicted/); + assert.match(body, /\| `linalg\/dagger\/svd` \| allocs \| \+37\.2% \|/); + assert.match(body, /\| Threads \| 0 \| 0 \| 0 \| 1 \| 1\/4 \|/); +}); diff --git a/AGENTS.md b/AGENTS.md index ad8c5740e..6412d625f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1217,3 +1217,6 @@ this section verbatim). Each entry is one bullet starting with `- `. the protocol alone is not enough for them. Test with a remote reader *and* a remote writer, in both orders: in one process every slot is the argument itself, so none of this is visible. + + +109. **Use contradictory confirmation evidence even when it did not trigger the repeat.** Allocation gates do not require another benchmark run, but a reversed-order run already triggered by timing can show the same allocation metric crossing the opposite threshold. Keep both raw measurements and classify that conflict as inconclusive instead of reporting the first result as a regression or an improvement. Missing or neutral repeat data must not silently disable the existing allocation gate. diff --git a/benchmark/ci.jl b/benchmark/ci.jl index b0aeee518..bba6daacc 100644 --- a/benchmark/ci.jl +++ b/benchmark/ci.jl @@ -201,7 +201,7 @@ job_summary_rows = [(j, get(job_regression_counts, j, 0), get(job_improvement_co sort!(job_summary_rows; by = r -> (-r[2], -r[3], r[1])) function job_summary_table(io, rows) - println(io, "| Job | Regressions | Improvements | Within noise | Inconclusive time | Advisory allocations |") + println(io, "| Job | Regressions | Improvements | Within noise | Inconclusive metrics | Advisory allocations |") println(io, "|:---|---:|---:|---:|---:|---:|") for (job, nreg, nimp, nnoise, ninsufficient, nadvisory) in rows marker = nreg > 0 ? " ⚠️" : (nimp > 0 ? " ✅" : "") @@ -281,9 +281,9 @@ open(joinpath(OUTPUT_DIR, "report.md"), "w") do io end println(io) if !isempty(insufficient) - println(io, "#### Inconclusive timing changes") + println(io, "#### Inconclusive metric changes") println(io) - println(io, "These changes had fewer than five timed samples in at least one revision, lacked a measured spread, or were not confirmed by the independent run; they are not counted as improvements or regressions.") + println(io, "Timing changes lacked five samples, a measured spread, or independent confirmation. Allocation changes listed here crossed opposite thresholds in the original and existing reversed-order comparisons. They are not counted as improvements or regressions.") println(io) for (name, metric, r) in insufficient println(io, "- `", name, "` (", metric, "): ", pct(r)) @@ -293,10 +293,14 @@ open(joinpath(OUTPUT_DIR, "report.md"), "w") do io if confirmation !== nothing println(io, "#### Independent confirmation (reversed revision order)") println(io) - println(io, "Timing regressions are counted only when both comparisons agree, with at least five samples per revision.") + println(io, "Timing regressions are counted only when both comparisons agree, with at least five samples per revision. Explicitly opposite allocation/memory classifications are inconclusive; missing or neutral repeat data leaves the original allocation gate unchanged.") println(io) println(io, create_table(confirmation; key="median", add_ratio_col=true)) println(io) + println(io, "Reversed-order allocations / memory:") + println(io) + println(io, create_table(confirmation; key="memory", add_ratio_col=true)) + println(io) end println(io, "#### Median time") println(io) @@ -330,7 +334,7 @@ if !isempty(within_noise) end if !isempty(insufficient) - println("\n$(length(insufficient)) timing change(s) are inconclusive: fewer than five samples, missing spread, or no independent confirmation.") + println("\n$(length(insufficient)) metric change(s) are inconclusive: timing lacks samples/spread/confirmation, or allocation comparisons disagree.") end if !isempty(advisory_allocations) diff --git a/benchmark/compare.jl b/benchmark/compare.jl index 8493c856b..2abe592e9 100644 --- a/benchmark/compare.jl +++ b/benchmark/compare.jl @@ -114,18 +114,30 @@ function attach_sample_counts!(flat, raw, prefix="") return flat end -# Only timing regressions require a second independent comparison. Allocation -# metrics retain their existing gates; unconfirmed timing flags stay visible. +# Only timing regressions trigger a second independent comparison. Allocation +# gates still stand alone, but an already available repeat must not explicitly +# contradict a claimed allocation regression or improvement. Missing/neutral +# repeat allocation data leaves the original gate unchanged. function confirm_timing_regressions(first, second) confirmed = Set((name, metric) for (name, metric, _) in second.regressions if metric == "time") - regressions = filter(first.regressions) do (name, metric, _) - metric != "time" || (name, metric) in confirmed - end + reversed_regressions = Set((name, metric) for (name, metric, _) in second.regressions + if metric in ("allocs", "memory")) + reversed_improvements = Set((name, metric) for (name, metric, _) in second.improvements + if metric in ("allocs", "memory")) insufficient = copy(first.insufficient) - for entry in first.regressions + regressions = filter(first.regressions) do entry + name, metric, _ = entry + keep = metric == "time" ? (name, metric) in confirmed : + !((name, metric) in reversed_improvements) + keep || push!(insufficient, entry) + keep + end + improvements = filter(first.improvements) do entry name, metric, _ = entry - metric == "time" && !((name, metric) in confirmed) && push!(insufficient, entry) + keep = !((name, metric) in reversed_regressions) + keep || push!(insufficient, entry) + keep end sort!(insufficient; by=last, rev=true) - return (; first..., regressions, insufficient) + return (; first..., regressions, improvements, insufficient) end diff --git a/benchmark/compare_tests.jl b/benchmark/compare_tests.jl index 73fc93d1e..e0ed2ba0c 100644 --- a/benchmark/compare_tests.jl +++ b/benchmark/compare_tests.jl @@ -125,3 +125,36 @@ end attach_sample_counts!(flat, raw) @test flat["suite/op"]["samples"] == 4 end + +@testset "Existing confirmation reconciles explicit allocation conflicts" begin + stats(; allocs=100, memory=1000, samples=2) = + Dict("allocs"=>allocs, "memory"=>memory, "samples"=>samples) + baseline = Dict("op"=>stats()) + first = compare_benchmarks(baseline, Dict("op"=>stats(; allocs=150, memory=500))) + opposite = compare_benchmarks(baseline, Dict("op"=>stats(; allocs=50, memory=1500))) + result = confirm_timing_regressions(first, opposite) + @test isempty(result.regressions) + @test isempty(result.improvements) + @test Set(result.insufficient) == Set([("op", "allocs", 1.5), ("op", "memory", 0.5)]) + @test first.regressions == [("op", "allocs", 1.5)] + @test first.improvements == [("op", "memory", 0.5)] + @test isempty(first.insufficient) + @test opposite.regressions == [("op", "memory", 1.5)] + @test opposite.improvements == [("op", "allocs", 0.5)] + + # Preserve standalone allocation policy for neutral/missing repeat data, + # agreement, and changes on another benchmark or another metric. + for repeat in (compare_benchmarks(baseline, baseline), + compare_benchmarks(baseline, Dict()), first, + compare_benchmarks(Dict("other"=>stats()), Dict("other"=>stats(; allocs=50)))) + unchanged = confirm_timing_regressions(first, repeat) + @test unchanged.regressions == first.regressions + @test unchanged.improvements == first.improvements + @test isempty(unchanged.insufficient) + end + only_memory = compare_benchmarks(baseline, Dict("op"=>stats(; memory=1500))) + unchanged_count = confirm_timing_regressions((; first..., improvements=Tuple{String,String,Float64}[]), only_memory) + @test unchanged_count.regressions == first.regressions + @test isempty(unchanged_count.insufficient) + @test isempty(result.advisory_allocations) +end