Skip to content

Unroll _transform_tuple to fix Enzyme.autodiff on tuples of length ≥ 33#170

Open
jlperla wants to merge 1 commit into
tpapp:masterfrom
jlperla:enzyme-3104-unroll-transform-tuple
Open

Unroll _transform_tuple to fix Enzyme.autodiff on tuples of length ≥ 33#170
jlperla wants to merge 1 commit into
tpapp:masterfrom
jlperla:enzyme-3104-unroll-transform-tuple

Conversation

@jlperla
Copy link
Copy Markdown

@jlperla jlperla commented May 15, 2026

Replace the Base.tail-recursive _transform_tuple with a @generated straight-line unroll — same outputs bit-for-bit, but the typed IR no longer contains a self-invoke, which is what Enzyme.autodiff (Forward and Reverse) trips on at tuple length ≥ 33 with AssertionError("conv == 37") (EnzymeAD/Enzyme.jl#3104).

The recursive Base.tail fold in _transform_tuple makes Enzyme.autodiff
(Forward and Reverse) throw `AssertionError("conv == 37")` from
Enzyme/src/rules/jitrules.jl:2073 once the tuple has ≥ 33 entries
(EnzymeAD/Enzyme.jl#3104). Replace it with a @generated straight-line
unroll that produces the same outputs bit-for-bit while emitting no
self-invoke in the typed IR — which is what Enzyme trips on.

Verified against the full Pkg.test() suite (all Pass = Total) and a
35-entry SW07-Pfeifer-style NamedTuple prior (fwd + rev both succeed).
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.

1 participant