Skip to content

Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later - #489

Merged
yebai merged 4 commits into
mainfrom
rdfix
Nov 11, 2026
Merged

yebai merged 4 commits into
mainfrom
rdfix

Conversation

@yebai

@yebai yebai commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

With ReverseDiff 1.18.8, BijectorsReverseDiffExt fails to precompile (UndefVarError: pd_from_upper not defined). The extension declared @grad_from_chainrules rules for pd_from_upper, _link_chol_lkj_from_upper and _link_chol_lkj_from_lower without importing them; up to 1.18.7 these defined unused local functions, but 1.18.8 (JuliaDiff/ReverseDiff.jl#328) requires the functions to exist. Deleting the rules keeps current behaviour: ReverseDiff gradients match main for the affected bijectors on Julia 1.12.

The find_alpha rule now computes its partials in the pullback from the current inputs, removing the tape has finished recording error on ReverseDiff 1.18.4+ and wrong gradients when a tape is reused at a new input. It also accepts untracked arguments, so reusing a tape with untracked PlanarLayer parameters no longer raises a MethodError. The link and invlink doctests no longer print a LogNormal, whose display changed in Distributions. Bumps to 0.16.4.

Mooncake CI failed tests are unrelated.

The three removed rules name functions the extension never imports, so
they only defined unused local functions. ReverseDiff 1.18.8
(JuliaDiff/ReverseDiff.jl#328) adds the method to `typeof(f)`, which
requires `f` to exist, so loading fails with `UndefVarError`.

Assisted-by: Claude Code <noreply@anthropic.com>
Distributions now prints `LogNormal()` as a multi-line block, so the
doctests suppress that output instead of matching it.

Assisted-by: Claude Code <noreply@anthropic.com>
ReverseDiff re-runs the `@grad` body on each forward pass of a
recorded tape but keeps the pullback from recording time. Partials
computed from tracked inputs in the body therefore raise `tape has
finished recording` on ReverseDiff 1.18.4+, and partials computed in
the body from any values are stale when a tape is replayed at a new
input, as they already were before 1.18.4.

Assisted-by: Claude Code <noreply@anthropic.com>
Reusing a tape through `find_alpha` at a new input raised a
`MethodError` when some of its arguments were untracked, for example
the inverse `PlanarLayer` with plain `Float64` parameters. ReverseDiff
stores untracked inputs of a recorded call as plain values, but the
`@grad` signature required `TrackedReal` for every argument.

The tracking method needs no change: mixed arguments reach it through
the promotion in `find_alpha(::Real, ::Real, ::Real)`.

Assisted-by: Claude Code <noreply@anthropic.com>
@yebai yebai changed the title Fix loading the ReverseDiff extension with ReverseDiff 1.18.8 Fix the ReverseDiff extension for ReverseDiff 1.18.4 and later Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bijectors.jl documentation for PR #489 is available at:
https://TuringLang.github.io/Bijectors.jl/previews/PR489/

@shravanngoswamii

Copy link
Copy Markdown
Member

I have personally reviewed the PR and everything looks good to me. But before approving lets try my review bot here.

@shravangoswami-bot

shravangoswami-bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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. Source

Review report

Source review at e0b1d94.

@yebai
yebai merged commit 2d1580a into main Nov 11, 2026
21 of 27 checks passed
@yebai
yebai deleted the rdfix branch November 11, 2026 17:32
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.

3 participants