Skip to content

Growth under ReverseDiff: no hcat, a valid zero point, and a replay check - #1022

Merged
seabbs-bot merged 7 commits into
mainfrom
claude/amazing-shannon-6nrow8
Dec 2, 2026
Merged

seabbs-bot merged 7 commits into
mainfrom
claude/amazing-shannon-6nrow8

Conversation

@seabbs-bot

Copy link
Copy Markdown
Collaborator

Carries #1006 with main merged in, plus one registry entry.

  • growth builds its Jacobian block by block without hcat, so ReverseDiff differentiates the mixing-strata scenario (closes ReverseDiff: growth of a stratified recurrence stops at an ambiguous hcat #1003).
  • The scenario is valid at the zero vector, where a backend may prepare or record.
  • The compiled-tape check replays each tape at a second point and compares with ForwardDiff there.
  • The mixing scenario and its plain-AD twin are listed for ReverseDiff (compiled) only: the root solve iterates until it settles, and a compiled tape does not replay value-dependent iteration (6 power steps recorded at zero, 40 needed at the scenario's input).

#1006's session ran ForwardDiff and both ReverseDiff modes locally with this entry: 9,483 pass, 1 broken, 0 fail.
Not run on this merge commit: any test.


Generated by Claude Code

…s a quantity fixed

growth found its root and Jacobian on tracked numbers under ReverseDiff,
as _primal_value had no method for them, and ReverseDiff's hcat of a
Matrix{TrackedReal} with a TrackedArray is ambiguous with SparseArrays
loaded. A ReverseDiff extension gives _primal_value and _fixed their
values, as for ForwardDiff's dual numbers. Fixes #1003.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwC7ixGWZNbRbSXXsSPbAs
…age holds a quantity fixed"

This reverts commit 4428bc2.
…piled tapes at a second point

The Jacobian was joined with hcat and vcat, and ReverseDiff's hcat of
a Matrix{TrackedReal} with a TrackedArray is ambiguous with SparseArrays
loaded. It is now filled block by block in an array like M, which takes
tracked numbers, and nothing is stripped for them: a compiled tape that
takes the root as a constant gives a wrong gradient at another point.
The compiled-tape check replays each registry scenario at a point about
1% from the one it was recorded at. Fixes #1003.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwC7ixGWZNbRbSXXsSPbAs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwC7ixGWZNbRbSXXsSPbAs
The coupling of "Growth rate and profile of strata that mix" is `K0`
scaled entry by entry by the exponential of its parameters, so it mixes
the strata at the zero vector too.

A tape recorded near the point it replays at runs the same steps of a
loop, so the second-point replay check is `@test` for every scenario and
no longer reads the broken list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwC7ixGWZNbRbSXXsSPbAs
A compiled tape does not replay value-dependent iteration.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
@github-actions

github-actions Bot commented Dec 3, 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 · · 1 19 4 · ·
ForwardDiff · · · 19 2 · ·
Mooncake reverse · · 1 20 · · ·
Enzyme reverse · · 1 20 · · ·
Evaluation — 24 benchmarks (by time change)
Benchmark base PR time memory
Evaluation / Matrix tv_piecewise_primary_k5 T200_L20_S1 1.76 μs 2.17 μs 🔴 1.23× ⚪ 1.0×
Evaluation / Matrix renewal T200_L20_S1 2.58 μs 2.79 μs 🔴 1.08× ⚪ 1.0×
Evaluation / Matrix tv_piecewise_renewal_secondary_k5 T200_L20_S1 3.03 μs 3.22 μs 🔴 1.06× ⚪ 1.0×
Evaluation / Matrix overview T200_L20_S3 13.85 μs 14.59 μs 🔴 1.05× ⚪ 1.0×
Evaluation / Matrix delay_fixed T200_L20_S1 611.0 ns 580.0 ns 🟢 0.95× ⚪ 1.0×
Evaluation / Matrix bvd_occupancy_kernel T200_L20_S1 5.92 μs 5.75 μs ⚪ 0.97× ⚪ 1.0×
Convolution body / BLAS axpy per lag 690.8 ns 708.3 ns ⚪ 1.03× —
Convolution body / package 312.3 ns 317.8 ns ⚪ 1.02× —
Convolution body / native axpy per lag 411.6 ns 416.4 ns ⚪ 1.01× —
Evaluation / Matrix tv_piecewise_renewal_primary_k5 T200_L20_S1 4.58 μs 4.63 μs ⚪ 1.01× ⚪ 1.0×
Evaluation / Matrix strata_mixing T200_L20_S5 22.03 μs 22.18 μs ⚪ 1.01× ⚪ 1.0×
Evaluation / Matrix custom_modifier T200_L20_S1 3.28 μs 3.3 μs ⚪ 1.01× ⚪ 1.0×
Evaluation / Matrix bvd_census T200_L20_S1 1.98 μs 1.99 μs ⚪ 1.01× ⚪ 1.0×
Evaluation / Matrix bvd_patches_call T200_L20_S5 43.33 μs 43.54 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix tv_piecewise_secondary_k5 T200_L20_S1 2.71 μs 2.72 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix bvd_patch T200_L20_S5 31.86 μs 31.96 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix renewal_depletion T200_L20_S1 6.87 μs 6.85 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix user_depletion T200_L20_S1 6.94 μs 6.92 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix bvd_renewal_call T200_L20_S1 7.16 μs 7.18 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix custom_modifier_pullback T200_L20_S1 3.31 μs 3.3 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix bvd_patches_call T200_L20_S1 15.45 μs 15.49 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix user_depletion_pullback T200_L20_S1 6.9 μs 6.89 μs ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix conv_fixed T200_L20_S1 541.0 ns 541.0 ns ⚪ 1.0× ⚪ 1.0×
Evaluation / Matrix random_walk T30_L1_S1 70.0 ns 70.0 ns ⚪ 1.0× ⚪ 1.0×
AD gradients — 63 benchmarks (by time change)
Benchmark base PR time memory
AD gradients / Matrix renewal T200_L20_S1 / Mooncake reverse 16.28 μs 12.69 μs 🟢 0.78× ⚪ 1.0×
AD gradients / Matrix random_walk T30_L1_S1 / ForwardDiff 2.15 μs 2.61 μs 🔴 1.21× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S5 / ForwardDiff 43.11 ms 49.27 ms 🔴 1.14× ⚪ 1.0×
AD gradients / Matrix bvd_occupancy_kernel T200_L20_S1 / Enzyme reverse 33.52 μs 30.52 μs 🟢 0.91× ⚪ 1.0×
AD gradients / Matrix bvd_census T200_L20_S1 / Mooncake reverse 13.73 μs 13.08 μs ⚪ 0.95× ⚪ 1.0×
AD gradients / Matrix strata_mixing T200_L20_S5 / Enzyme reverse 65.65 μs 68.68 μs ⚪ 1.05× ⚪ 1.0×
AD gradients / Matrix conv_fixed T200_L20_S1 / Enzyme reverse 2.34 μs 2.44 μs ⚪ 1.04× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_secondary_k5 T200_L20_S1 / ForwardDiff 572.22 μs 591.08 μs ⚪ 1.03× ⚪ 1.0×
AD gradients / Matrix renewal_depletion T200_L20_S1 / Enzyme reverse 14.91 μs 14.44 μs ⚪ 0.97× ⚪ 1.0×
AD gradients / Matrix custom_modifier_pullback T200_L20_S1 / Mooncake reverse 16.86 μs 17.37 μs ⚪ 1.03× ⚪ 1.0×
AD gradients / Matrix custom_modifier T200_L20_S1 / ForwardDiff 444.46 μs 455.53 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix custom_modifier_pullback T200_L20_S1 / Enzyme reverse 8.02 μs 7.84 μs ⚪ 0.98× ⚪ 1.0×
AD gradients / Matrix user_depletion_pullback T200_L20_S1 / Enzyme reverse 14.62 μs 14.31 μs ⚪ 0.98× ⚪ 1.0×
AD gradients / Matrix bvd_occupancy_kernel T200_L20_S1 / ForwardDiff 6.25 ms 6.12 ms ⚪ 0.98× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_secondary_k5 T200_L20_S1 / Enzyme reverse 7.33 μs 7.19 μs ⚪ 0.98× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_primary_k5 T200_L20_S1 / ForwardDiff 582.57 μs 593.56 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix custom_modifier T200_L20_S1 / Enzyme reverse 8.82 μs 8.98 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_primary_k5 T200_L20_S1 / Enzyme reverse 7.81 μs 7.67 μs ⚪ 0.98× ⚪ 1.0×
AD gradients / Matrix overview T200_L20_S3 / Enzyme reverse 39.14 μs 39.79 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix custom_modifier_pullback T200_L20_S1 / ForwardDiff 443.9 μs 451.04 μs ⚪ 1.02× ⚪ 1.0×
AD gradients / Matrix bvd_census T200_L20_S1 / Enzyme reverse 14.28 μs 14.49 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_secondary_k5 T200_L20_S1 / Enzyme reverse 10.82 μs 10.96 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix user_depletion_pullback T200_L20_S1 / ForwardDiff 475.22 μs 481.18 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S1 / ForwardDiff 1.54 ms 1.56 ms ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix delay_fixed T200_L20_S1 / Enzyme reverse 2.64 μs 2.61 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S1 / Enzyme reverse 40.0 μs 39.55 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_primary_k5 T200_L20_S1 / Mooncake reverse 14.31 μs 14.46 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix bvd_renewal_call T200_L20_S1 / Enzyme reverse 16.3 μs 16.14 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix user_depletion T200_L20_S1 / ForwardDiff 476.31 μs 480.95 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix delay_fixed T200_L20_S1 / ForwardDiff 436.13 μs 440.31 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_secondary_k5 T200_L20_S1 / Mooncake reverse 13.64 μs 13.77 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix conv_fixed T200_L20_S1 / ForwardDiff 331.25 μs 334.21 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix overview T200_L20_S3 / Mooncake reverse 59.45 μs 59.94 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix conv_fixed T200_L20_S1 / Mooncake reverse 10.28 μs 10.36 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix bvd_patch T200_L20_S5 / Enzyme reverse 83.84 μs 84.45 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix user_depletion T200_L20_S1 / Mooncake reverse 22.2 μs 22.35 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix user_depletion T200_L20_S1 / Enzyme reverse 16.36 μs 16.48 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_primary_k5 T200_L20_S1 / Mooncake reverse 22.41 μs 22.26 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix user_depletion_pullback T200_L20_S1 / Mooncake reverse 20.73 μs 20.6 μs ⚪ 0.99× ⚪ 1.0×
AD gradients / Matrix bvd_renewal_call T200_L20_S1 / ForwardDiff 574.07 μs 577.6 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix bvd_census T200_L20_S1 / ForwardDiff 1.88 ms 1.9 ms ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix renewal T200_L20_S1 / ForwardDiff 543.16 μs 545.95 μs ⚪ 1.01× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_secondary_k5 T200_L20_S1 / ForwardDiff 851.44 μs 847.46 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix renewal_depletion T200_L20_S1 / Mooncake reverse 20.68 μs 20.6 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_renewal_call T200_L20_S1 / Mooncake reverse 23.7 μs 23.62 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_primary_k5 T200_L20_S1 / ForwardDiff 632.84 μs 630.58 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix strata_mixing T200_L20_S5 / Mooncake reverse 106.02 μs 105.66 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix overview T200_L20_S3 / ForwardDiff 3.07 ms 3.06 ms ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S1 / Mooncake reverse 55.94 μs 55.78 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patch T200_L20_S5 / ForwardDiff 14.29 ms 14.33 ms ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix delay_fixed T200_L20_S1 / Mooncake reverse 9.31 μs 9.33 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_secondary_k5 T200_L20_S1 / Mooncake reverse 19.01 μs 19.05 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_occupancy_kernel T200_L20_S1 / Mooncake reverse 30.68 μs 30.74 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S5 / Enzyme reverse 111.42 μs 111.64 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix strata_mixing T200_L20_S5 / ForwardDiff 11.85 ms 11.87 ms ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix custom_modifier T200_L20_S1 / Mooncake reverse 17.66 μs 17.69 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix renewal T200_L20_S1 / Enzyme reverse 6.94 μs 6.95 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix renewal_depletion T200_L20_S1 / ForwardDiff 483.66 μs 484.21 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix random_walk T30_L1_S1 / Mooncake reverse 911.0 ns 912.0 ns ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patches_call T200_L20_S5 / Mooncake reverse 159.28 μs 159.15 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix tv_piecewise_renewal_primary_k5 T200_L20_S1 / Enzyme reverse 14.4 μs 14.41 μs ⚪ 1.0× ⚪ 1.0×
AD gradients / Matrix bvd_patch T200_L20_S5 / Mooncake reverse 123.95 μs 124.0 μ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×

seabbs-bot added a commit that referenced this pull request Dec 5, 2026
… case (#1062)

* Fill the growth Jacobian's last row through a two-range view

Reactant cannot broadcast into a traced row viewed with an integer index,
so the block fills from #1022 broke the growth registry scenario under
Reactant. The coverage job also gives each case 1800 s, since coverage
slows the wide coupled reverse compile past 600 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep the growth Jacobian comment free of other package names

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

ReverseDiff: growth of a stratified recurrence stops at an ambiguous hcat

2 participants