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/benchmark/ci.jl b/benchmark/ci.jl index ef7a0eacf..e3f431c75 100644 --- a/benchmark/ci.jl +++ b/benchmark/ci.jl @@ -209,7 +209,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 ? " ✅" : "") @@ -289,9 +289,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)) @@ -301,10 +301,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) @@ -338,7 +342,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