Skip to content

Mark the Symmetric sparse named container broken under Enzyme on Julia 1.12 - #1052

Merged
seabbs merged 2 commits into
mainfrom
fix/enzyme-symmetric-sparse-broken
Dec 4, 2026
Merged

seabbs merged 2 commits into
mainfrom
fix/enzyme-symmetric-sparse-broken

Conversation

@seabbs-bot

@seabbs-bot seabbs-bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1038 (the doubled Enzyme gradient; the table-cut part is #1034, in #1049).
The doubled gradient is an Enzyme fault on Julia 1.12, not the package's, so that one case is marked broken for Enzyme reverse before Julia 1.13.

Claude Opus 5.5 [medium]

Finding

The "named container 2" case in test/ad/adjoints.jl differentiates Recurrence(g; coupling = Symmetric(sparse([θ[1] 0.1; 0.1 θ[2]]))) with plain Enzyme reverse.
The plain route reads the coupling one entry at a time (_mix_floats!).

A reproducer without the package gives the same fault (posted on #931: #931 (comment)):

  • Enzyme.gradient(Reverse, θ -> sum(Symmetric(sparse([θ[1] 0.1; 0.1 θ[2]]))), [0.4, 0.7]) gives [1.0, 2.0] on Julia 1.12.7; ForwardDiff gives [1.0, 1.0].
  • A loop q[a] += C[a, b] * p[b] over the same matrix gives exactly twice ForwardDiff, as in CI.
  • The same loop over the unwrapped SparseMatrixCSC is right.
  • With and without runtime activity alike.
  • Julia 1.13.4 with the same Enzyme (0.13.221) is right in every case.

So it is not #964 (a repeated mul! on a plain sparse matrix): one read is enough, the Symmetric wrapper is needed, and it is specific to 1.12.

The package case itself, run locally with Enzyme 0.13.221:

Coupling Julia 1.12.7 Julia 1.13.4
Symmetric(sparse(...)) 2× ForwardDiff matches
sparse(...) matches matches
Symmetric([...]) matches matches

Change

test/ad/adjoints.jl: the gradient check of named container 2 is broken when the backend is AutoEnzyme and VERSION < v"1.13", with a comment linking the reproducer.
The notice and the "no rule fires" checks of that case still run.
Mooncake reverse and Julia 1.13 still check the gradient.

Checks

"Lazy host arrays take the rule; other containers are named once" on Julia 1.12.7, both backends: 70 pass, 1 broken.
On 1.13 the condition is false and the gradient matched ForwardDiff locally.
The managed Enzyme reverse job on 1.13 may hit its time limit as it does on main.
main (with #1049) is merged in, and AD versions (Julia 1.12) was dispatched on this branch: https://github.com/EpiAware/ComposableRecurrences.jl/actions/runs/47331375902

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

Plain Enzyme reverse doubles the cotangents read through Symmetric of a
SparseMatrixCSC on Julia 1.12, with no package code involved (reproducer
on #931). Julia 1.13 with the same Enzyme is right, so the case is
broken only for Enzyme reverse before 1.13.

Part of #1038.
@seabbs-bot
seabbs-bot requested a review from seabbs as a code owner December 4, 2026 11:04
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.

2 participants