Skip to content

Fix triangular helpers for adjoint Cholesky factors on Julia 1.13 - #490

Merged
shravanngoswamii merged 6 commits into
mainfrom
triufix
Nov 11, 2026
Merged

shravanngoswamii merged 6 commits into
mainfrom
triufix

Conversation

@yebai

@yebai yebai commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

On Julia 1.13, C.U of a Cholesky factorisation stored as the lower triangle is a non-copying UpperTriangular(C.factors') (JuliaLang/LinearAlgebra.jl#1186), so parent(C.U) is an Adjoint. upper_triangular used convert(typeof(A), UpperTriangular(A)), which cannot convert to an Adjoint, so cholesky_upper throws a MethodError:

Bijectors.upper_triangular(parent(cholesky(Hermitian([2.0 1; 1 2], :L)).U))  # MethodError on 1.13

Mooncake's forward-mode cholesky always stores the lower triangle, so CorrBijector and VecCorrBijector fail under it; in CI this shows as three VecCorrBijector and cholesky_upper cases of the Mooncake integration tests on Julia 1.13. lower_triangular has the same defect for factors stored as the upper triangle. Both helpers now use triu and tril. Adds a regression test and a 0.16.4 HISTORY entry.

Stacked on #489, which bumps to 0.16.4 and fixes the ReverseDiff extension and doctests that fail on main.

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 requested a review from sunxd3 November 11, 2026 07:52
On Julia 1.13, `Cholesky.U` of a factorisation stored as 'L' wraps
`factors'` without copying, so `parent(C.U)` is an `Adjoint`.
`upper_triangular` returned `convert(typeof(A), UpperTriangular(A))`,
but Julia cannot `convert` a triangular wrapper to an `Adjoint`, so it
threw a `MethodError`:

    upper_triangular(parent(cholesky(Hermitian([2.0 1; 1 2], :L)).U))

`cholesky_upper` requests 'U' storage, so this surfaces only where
`cholesky` stores 'L' regardless: Mooncake forward mode does, so
`CorrBijector` and `VecCorrBijector` failed under it.
`lower_triangular` has the same latent defect for 'U'-stored factors.

Use `triu`/`tril` instead, which return a dense array for wrapper
types. A regression test covers both helpers.

Assisted-by: Claude Code <noreply@anthropic.com>
@yebai
yebai changed the base branch from main to rdfix November 11, 2026 07:57
@github-actions

Copy link
Copy Markdown
Contributor

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

Base automatically changed from rdfix to main November 11, 2026 17:32
@shravanngoswamii

Copy link
Copy Markdown
Member

@shravangoswami-bot review

@shravangoswami-bot

shravangoswami-bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Recommendation: Approve

No blocking issue found in the reviewed source.

Review report

Source review at f4f30f5.

@shravanngoswamii
shravanngoswamii merged commit d3b1b44 into main Nov 11, 2026
18 of 21 checks passed
@shravanngoswamii
shravanngoswamii deleted the triufix branch November 11, 2026 20:08
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.

4 participants