Skip to content

Leave the scenarios that crash Enzyme forward out of the benchmark grid - #1073

Open
seabbs-bot wants to merge 3 commits into
mainfrom
fix/enzyme-forward-bench-segfault
Open

seabbs-bot wants to merge 3 commits into
mainfrom
fix/enzyme-forward-bench-segfault

Conversation

@seabbs-bot

Copy link
Copy Markdown
Collaborator

Closes #1054.
The Enzyme forward cell of the AD benchmark grid segfaulted because of an Enzyme bug in batched forward mode (EnzymeAD/Enzyme.jl#3698), not package code.
This leaves the scenarios that crashed it out of that cell only, so the rest of the grid runs, while the tests still run them.

Needs your decision: the bug can hit any scenario that copies a view of its parameters, which _unpack gives nearly all of them, so another scenario may crash the cell on a later day. The list holds the two that crashed it here (with their twins). The alternatives are to time Enzyme forward one tangent at a time (chunk = Val(1), which does not crash but changes what the cell measures) or to wait for the upstream fix (EnzymeAD/Enzyme.jl#3723, which needs a rebase).

Opus 5.5

The crash

All three failing daily runs (46401458397, 46710682400, 47252385949) segfaulted on the first scenario of the grid, Convolution ragged kernel of views into the parameters, in gc_try_claim_and_push during a garbage collection while the scenario's collect of its vector of views allocated, under fwddiffe… (Enzyme forward), Julia 1.13.4.

Reproduced locally (Enzyme 0.13.221, EnzymeCore 0.8.28, Enzyme_jll 0.0.310+0, DifferentiationInterface 0.7.22):

  • The scenario's prepared DI.gradient with the benchmarks' Enzyme forward backend, looped for 60 s, one thread: segfault in 2 of 2 runs on Julia 1.13.4, same trace as CI.
  • The grid itself (BENCHMARK_TIER=full BENCHMARK_BACKENDS="Enzyme forward" BENCHMARK_MATRIX=false julia --project=benchmark benchmark/run.jl, as CI runs it) on Julia 1.13.4:
    • with the scenario left out, it crashed on its NoAdjoint twin;
    • with both left out, it crashed on Recurrence modifier with Bool and Int fields beside floats, which also segfaults on its own in 3 of 3 runs;
    • with these four left out, the whole grid ran: 270 of 270 groups timed, results saved, in 59 min.

Root cause: Enzyme, not the package

A reproducer with only Enzyme, batched forward over a vector of views of the argument passed to a non-inlined function:

Setup Result
Julia 1.13.4, Enzyme 0.13.221 segfault, 3 of 3 runs
Julia 1.12.7, Enzyme 0.13.221 segfault 2 of 3, GC error (probable corruption) 1 of 3
width one (Duplicated) ok, about 18 million gradients in 30 s
Enzyme 0.13.221 with the change of EnzymeAD/Enzyme.jl#3723 ported on ok, 3 of 3 runs

The pattern of #321, sink(exp.(reshape(view(θ, …), 3, 12))), also segfaults on the release (2 of 2) and runs clean with the ported fix (2 of 2).
So this is EnzymeAD/Enzyme.jl#3698: in forward mode Enzyme allocates the shadows of a new Memory before its header is written, and a collection in between reads a garbage length.
I posted the reproducer and these results on that issue (EnzymeAD/Enzyme.jl#3698 (comment)) rather than opening a duplicate.
The open fix PR there, EnzymeAD/Enzyme.jl#3723, predates the julia.gc_alloc_zeroinit fix of #4065, so as it stands it aborts on this reproducer; ported onto 0.13.221 it fixes it.

The AD test job passes because it takes one gradient per scenario, while the benchmark loop takes thousands, so a collection lands in the window.
There is no inlining or activity issue in the package to fix: the trigger is a copy of a view of the active argument, which the scenarios' losses make.

The change

  • test/ADFixtures/src/registry.jl: a benchmark-only list, benchmark_crashes(), read by exclusion_reason, holding the two scenarios and their twins for Enzyme forward, with the upstream issue in its docstring.
    It is separate from backend_skip_scenarios, which the tests also read and which test/ad/scenarios.jl requires to be empty, so the AD tests still run these scenarios.
  • test/ad/scenarios.jl: the list is checked to name real scenarios and backends, as the other lists are, and the ragged views scenario and its twin are checked to be left out of the Enzyme forward benchmark.

Checks

  • The AD fixtures need only features this version has… test item passes (39 of 39).
  • The :quality standards items and pre-commit pass.

This was opened by a bot. Please ping @seabbs for any questions.

seabbs-bot and others added 3 commits December 5, 2026 18:00
…enario

The scenario's repeated Enzyme forward gradients segfault in the
benchmark grid (#1054), while one gradient, as the tests take, is right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Repeated batched Enzyme forward gradients of the scenario segfault in the
garbage collector (EnzymeAD/Enzyme.jl#3698), which stopped the whole
Enzyme forward cell of the AD benchmark grid (#1054). A benchmark-only
list keeps the scenario in the tests, which take one gradient.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The grid next crashed on the NoAdjoint twin of the ragged views
scenario, then on the scenario with Bool and Int modifier fields, which
also segfaults on its own in three of three runs. Both are the same
Enzyme bug (EnzymeAD/Enzyme.jl#3698), which any copy of a view of the
parameters can reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@seabbs-bot
seabbs-bot requested a review from seabbs as a code owner December 5, 2026 20:17
@codecov

codecov Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
ad-enzyme-forward 43.00% <ø> (ø)
ad-enzyme-reverse 76.78% <ø> (ø)
ad-forwarddiff 41.88% <ø> (ø)
ad-mooncake-forward 54.69% <ø> (ø)
ad-mooncake-reverse 76.17% <ø> (ø)
ad-reversediff 42.88% <ø> (ø)
ad-reversediff-compiled 42.04% <ø> (ø)
unit 95.79% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Benchmark comparison vs base

Minimum time per call. Buckets are PR time as a % of base, so lower is faster (🟢 faster, ⚪ within 5%, 🔴 slower). Counts of benchmarks per bucket:

Group 🟢 <50% 🟢 50–75% 🟢 75–95% ⚪ 95–105% 🔴 105–125% 🔴 125–150% 🔴 >150%
Evaluation · · 2 22 · · ·
ForwardDiff · · 1 20 · · ·
Mooncake reverse · · · 21 · · ·
Enzyme reverse · · · 21 · · ·
Evaluation — 24 benchmarks (by time change)
Benchmark base PR time memory
Evaluation / Matrix tv_piecewise_secondary_k5 T200_L20_S1 1.34 μs 1.2 μs 🟢 0.9× ⚪ 1.0×
Evaluation / Matrix tv_piecewise_primary_k5 T200_L20_S1 1.68 μs 1.53 μs 🟢 0.91× ⚪ 1.0×
Evaluation / Matrix bvd_occupancy_kernel T200_L20_S1 5.11 μs 5.25 μs ⚪ 1.03× ⚪ 1.0×
Evaluation / Matrix delay_fixed T200_L20_S1 581.0 ns 591.0 ns ⚪ 1.02× ⚪ 1.0×
Evaluation / Matrix bvd_patch T200_L20_S5 31.37 μs 31.83 μs ⚪ 1.01× ⚪ 1.0×
Evaluation / Matrix bvd_census T200_L20_S1 1.4 μs 1.38 μs ⚪ 0.99× ⚪ 1.0×
Convolution body / BLAS axpy per lag 778.1 ns 788.6 ns ⚪ 1.01× —
Evaluation / Matrix bvd_patches_call T200_L20_S5 43.64 μs 44.08 μs ⚪ 1.01× ⚪ 1.0×
Evaluation / Matrix overview T200_L20_S3 14.08 μs 13.97 μs ⚪ 0.99× ⚪ 1.0×
Convolution body / package 363.6 ns 360.9 ns ⚪ 0.99× —
Evaluation / Matrix strata_mixing T200_L20_S5 22.07 μs 22.22 μs ⚪ 1.01× ⚪ 1.0×
Evaluation / Matrix bvd_patches_call T200_L20_S1 15.27 μs 15.36 μs ⚪ 1.01× ⚪ 1.0×
Convolution body / native axpy per lag 496.6 ns 498.8 ns ⚪ 1.0× —
Evaluation / Matrix tv_piecewise_renewal_primary_k5 T200_L20_S1 4.57 μs 4.55 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix tv_piecewise_renewal_secondary_k5 T200_L20_S1 3.02 μs 3.0 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix custom_modifier_pullback T200_L20_S1 3.28 μs 3.28 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix user_depletion T200_L20_S1 6.91 μs 6.9 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix bvd_renewal_call T200_L20_S1 7.15 μs 7.16 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix conv_fixed T200_L20_S1 540.0 ns 540.0 ns ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix custom_modifier T200_L20_S1 3.29 μs 3.29 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix random_walk T30_L1_S1 70.0 ns 70.0 ns ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix renewal T200_L20_S1 2.57 μs 2.57 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix renewal_depletion T200_L20_S1 6.88 μs 6.88 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix user_depletion_pullback T200_L20_S1 6.9 μs 6.9 μs ⚪ 1.0× ⚪ 1.0×
AD gradients — 63 benchmarks (by time change)
Benchmark base PR time memory
AD gradients / Matrix random_walk T30_L1_S1 / ForwardDiff 1.73 μs 1.56 μs 🟢 0.9× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_secondary_k5 T200_L20_S1 / Enzyme reverse 7.53 μs 7.2 μs ⚪ 0.96× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_secondary_k5 T200_L20_S1 / Mooncake reverse 13.4 μs 13.76 μs ⚪ 1.03× ⚪ 1.0×
AD gradients / Matrix custom_modifier T200_L20_S1 / Enzyme reverse 7.69 μs 7.89 μs ⚪ 1.03× ⚪ 1.0×
AD gradients / Matrix bvd_census T200_L20_S1 / ForwardDiff 1.13 ms 1.16 ms ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix conv_fixed T200_L20_S1 / Mooncake reverse 6.64 μs 6.51 μs ⚪ 0.98× ⚪ 1.0×
AD gradients / Matrix custom_modifier_pullback T200_L20_S1 / Mooncake reverse 16.19 μs 16.5 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_primary_k5 T200_L20_S1 / Enzyme reverse 14.33 μs 14.59 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_secondary_k5 T200_L20_S1 / Mooncake reverse 18.64 μs 18.97 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix bvd_occupancy_kernel T200_L20_S1 / Enzyme reverse 23.76 μs 24.16 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S5 / ForwardDiff 43.09 ms 43.8 ms ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix delay_fixed T200_L20_S1 / Enzyme reverse 2.56 μs 2.6 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix overview T200_L20_S3 / Mooncake reverse 54.22 μs 53.46 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix bvd_occupancy_kernel T200_L20_S1 / Mooncake reverse 24.18 μs 24.51 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix conv_fixed T200_L20_S1 / Enzyme reverse 2.4 μs 2.37 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix renewal T200_L20_S1 / ForwardDiff 346.75 μs 350.56 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix custom_modifier_pullback T200_L20_S1 / ForwardDiff 471.23 μs 466.05 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix renewal T200_L20_S1 / Mooncake reverse 12.27 μs 12.4 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S5 / Enzyme reverse 106.32 μs 107.45 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S5 / Mooncake reverse 158.87 μs 160.53 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_primary_k5 T200_L20_S1 / Enzyme reverse 8.24 μs 8.32 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_primary_k5 T200_L20_S1 / Mooncake reverse 13.84 μs 13.97 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix bvd_census T200_L20_S1 / Mooncake reverse 7.66 μs 7.73 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_secondary_k5 T200_L20_S1 / ForwardDiff 570.79 μs 565.52 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_primary_k5 T200_L20_S1 / ForwardDiff 450.94 μs 447.02 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_secondary_k5 T200_L20_S1 / ForwardDiff 420.86 μs 424.37 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix bvd_renewal_call T200_L20_S1 / ForwardDiff 580.4 μs 585.22 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix renewal_depletion T200_L20_S1 / Mooncake reverse 19.88 μs 19.72 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix delay_fixed T200_L20_S1 / ForwardDiff 314.45 μs 311.96 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix renewal_depletion T200_L20_S1 / Enzyme reverse 13.98 μs 13.87 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix user_depletion T200_L20_S1 / Mooncake reverse 21.74 μs 21.91 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix strata_mixing T200_L20_S5 / Mooncake reverse 103.15 μs 102.41 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix bvd_occupancy_kernel T200_L20_S1 / ForwardDiff 5.32 ms 5.36 ms ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix conv_fixed T200_L20_S1 / ForwardDiff 241.75 μs 243.42 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix user_depletion T200_L20_S1 / Enzyme reverse 16.13 μs 16.03 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix custom_modifier T200_L20_S1 / Mooncake reverse 16.46 μs 16.57 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix user_depletion T200_L20_S1 / ForwardDiff 499.74 μs 496.77 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix renewal T200_L20_S1 / Enzyme reverse 6.92 μs 6.88 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix renewal_depletion T200_L20_S1 / ForwardDiff 500.14 μs 502.94 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix user_depletion_pullback T200_L20_S1 / ForwardDiff 500.54 μs 497.77 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S1 / Enzyme reverse 39.13 μs 38.96 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix strata_mixing T200_L20_S5 / Enzyme reverse 64.23 μs 64.49 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patch T200_L20_S5 / Enzyme reverse 82.03 μs 82.36 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S1 / ForwardDiff 1.53 ms 1.53 ms ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patch T200_L20_S5 / ForwardDiff 13.75 ms 13.8 ms ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_secondary_k5 T200_L20_S1 / Enzyme reverse 11.01 μs 10.98 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_renewal_call T200_L20_S1 / Enzyme reverse 15.26 μs 15.22 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix custom_modifier_pullback T200_L20_S1 / Enzyme reverse 7.62 μs 7.64 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_census T200_L20_S1 / Enzyme reverse 8.84 μs 8.82 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_primary_k5 T200_L20_S1 / Mooncake reverse 21.94 μs 21.89 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S1 / Mooncake reverse 55.2 μs 55.1 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_renewal_call T200_L20_S1 / Mooncake reverse 22.36 μs 22.32 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix strata_mixing T200_L20_S5 / ForwardDiff 11.03 ms 11.01 ms ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix custom_modifier T200_L20_S1 / ForwardDiff 466.85 μs 467.52 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix delay_fixed T200_L20_S1 / Mooncake reverse 6.92 μs 6.91 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix overview T200_L20_S3 / ForwardDiff 3.18 ms 3.19 ms ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_primary_k5 T200_L20_S1 / ForwardDiff 572.33 μs 572.8 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patch T200_L20_S5 / Mooncake reverse 123.38 μs 123.32 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix user_depletion_pullback T200_L20_S1 / Mooncake reverse 19.8 μs 19.8 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix overview T200_L20_S3 / Enzyme reverse 36.14 μs 36.14 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix random_walk T30_L1_S1 / Enzyme reverse 180.0 ns 180.0 ns ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix random_walk T30_L1_S1 / Mooncake reverse 931.0 ns 931.0 ns ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix user_depletion_pullback T200_L20_S1 / Enzyme reverse 14.01 μs 14.01 μs ⚪ 1.0× ⚪ 1.0×

This branch has not been deployed

No deployments
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.

Enzyme forward segfaults in the registry AD benchmark grid

1 participant