Removes three undefined gradient rules. Updates the PlanarLayer pullback to use current values when a ReverseDiff tape is replayed.
Fix the ReverseDiff extension for ReverseDiff 1.18.4 and laterRevisions
- Base
f85bbdd1f4331b66e0ae0567d2d1092e54277c7e- Head
e0b1d94dcc8e46152969b5e013f09348fb266052- PR checked
- 2026-11-11T16:04:54.325Z
- Agent
- Claude Code cloud
- Requested model
- sonnet
- Requested effort
- medium
- Cloud session
- Open in Claude
- Reported models
- Unreported
Reviewed snapshot. Validation checks structure, not call paths.
Overview
Recommendation: Hold
Hold for a reproducible check of the two tape-replay fixes.
Check a compiled tape at a new input and with untracked PlanarLayer parameters. The author reports local checks, while this review has only inspected source.1
Bijectors.jl provides invertible transforms between constrained and unconstrained spaces. Its ReverseDiff extension (BijectorsReverseDiffExt) teaches ReverseDiff how to differentiate several of those transforms, using @grad (hand-written pullbacks) and @grad_from_chainrules (reuse ChainRules rrules).
With ReverseDiff 1.18.8 the extension fails to precompile with UndefVarError: pd_from_upper. ReverseDiff PR 328 changed @grad_from_chainrules so the named function must exist in the calling scope. The PR also fixes the PlanarLayer inverse gradient, which depends on find_alpha, and makes two doctests independent of how Distributions prints a LogNormal. Package version goes to 0.16.4.7
Affected users: anyone loading ReverseDiff together with Bijectors (including Turing users with ReverseDiff AD). The load failure affects all of them on ReverseDiff 1.18.8; the find_alpha changes affect only inverse PlanarLayer.
Changes
What changes
| Area | Before | After |
|---|---|---|
| Rules for pd_from_upper, _link_chol_lkj_from_upper, _link_chol_lkj_from_lower | @grad_from_chainrules declared on names that the extension never imports | Rules deleted |
| find_alpha @grad | Signature requires TrackedReal arguments; partial derivatives computed once at record time from tracked inputs; pullback closes over them | Signature accepts Real; partials recomputed inside the pullback from current input values |
| link / invlink doctests | Print LogNormal{Float64}(μ=0.0, σ=1.0) | Statement ends with a semicolon so nothing is printed |
| Version, HISTORY | 0.16.3 | 0.16.4 with four entries |
find_alpha pullback
Before
@grad function find_alpha(wt_y::TrackedReal, wt_u_hat::TrackedReal, b::TrackedReal) α = find_alpha(value(wt_y), value(wt_u_hat), value(b)) ∂wt_y = inv(1 + wt_u_hat * sech(α + b)^2) # uses tracked values ... find_alpha_pullback(Δ::Real) = (Δ * ∂wt_y, Δ * ∂wt_u_hat, Δ * ∂b) return α, find_alpha_pullback end
After
@grad function find_alpha(wt_y::Real, wt_u_hat::Real, b::Real) α = find_alpha(value(wt_y), value(wt_u_hat), value(b)) function find_alpha_pullback(Δ::Real) u, c = value(wt_u_hat), value(b) a = find_alpha(value(wt_y), u, c) ∂wt_y = inv(1 + u * sech(a + c)^2) return (Δ * ∂wt_y, -Δ * tanh(a + c) * ∂wt_y, Δ * (∂wt_y - 1)) end return α, find_alpha_pullback end
Review
Deleting the three rules is consistent with the stated cause
At base, pd_from_upper, _link_chol_lkj_from_upper and _link_chol_lkj_from_lower are not in the using/import lists of the extension, so the macro calls referred to names with no binding in the extension module. The head import list still does not contain them, so removal cannot drop a rule that was actually attached to a Bijectors function. This is a source check only; the precompile error on ReverseDiff 1.18.8 was not reproduced here.
3, 4, 5Pullback algebra matches the old partials
With α defined by α + u*tanh(α + b) = y, the new pullback returns 1/(1+u*sech²) for y, −tanh(α+b)*that for u, and (that − 1) for b. These are the same formulas as before, now evaluated at the current values. Checked by reading the code, not by running it.
1Each backward pass reruns the root finder
The forward pass solves for alpha once. The pullback solves for it again using the current input values. Runtime cost has not been measured.
1Untracked-argument claim is only partly visible in source
The PR says the rule now accepts untracked arguments. The @grad body does accept Real, but the track entry point is still find_alpha(wt_y::T, wt_u_hat::T, b::T) where {T<:TrackedReal}, which requires all three arguments to be the same tracked type. How the untracked-parameter replay reaches the @grad method was not traced, and no reproduction was run.
1No regression tests in the diff
Only HISTORY.md, Project.toml, the extension and src/Bijectors.jl change. The repository's ReverseDiff integration tests exist (test/integration_tests/reversediff) but nothing was added for tape reuse at a new input or for untracked PlanarLayer parameters, which are the behaviors the HISTORY entries describe. A small test that compiles a tape, changes the input and compares to ForwardDiff would lock these in. The PR body reports comparisons against main but they are not committed.
1Compat bounds are unchanged
Project.toml keeps ReverseDiff = "1". Deleting the rules is harmless on older versions, and the new find_alpha uses only value and track, so the wide bound seems fine. The replay behavior on versions before 1.18.4 was not checked.
5Scope of checking
Source reading at the pinned base and head, plus linked ReverseDiff PR 328. No package code or tests were run, so gradient equivalence with main and the doctest output are taken from the PR author. PR 490 is stacked on this one and relies on its 0.16.4 bump.
Review scope
Cloud source review. Package-test results were not verified.
Linked work: public repositories only, depth 2, at most 15 items. Read status describes collection, not semantic review.
Details
Declaration inventory (find_alpha)
| Change | Declaration | Location |
|---|---|---|
| removed | find_alpha(wt_y::TrackedReal, wt_u_hat::TrackedReal, b::TrackedReal) @grad method | ext/BijectorsReverseDiffExt.jl:201 (base) |
| added | find_alpha(wt_y::Real, wt_u_hat::Real, b::Real) @grad method | ext/BijectorsReverseDiffExt.jl:199 (head) |
| removed | find_alpha_pullback(Δ::Real), closure over precomputed partials | ext/BijectorsReverseDiffExt.jl:207 (base) |
| added | find_alpha_pullback(Δ::Real), recomputes from current inputs | ext/BijectorsReverseDiffExt.jl:202 (head) |
Limits: @grad and @grad_from_chainrules were not macro-expanded, so only written declarations are listed. The three deleted @grad_from_chainrules lines have no inventory entry because they declared no definitions. Linked work was collected to depth 2 with at most 15 items; ReverseDiff issues 314, 315, 319 and 320 are fixed by ReverseDiff PR 328 and are the background for the 1.18.8 change.