You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native Enzyme Reverse rejects plate cells that return an unbound argument's element (fresh container of constant pointers) #49
Native Enzyme Reverse (static activity analysis, no runtime activity) raises EnzymeRuntimeActivityError when a plate cell returns an element of an argument that is neither active nor bound, or a field of one, and the plate's output then reaches the active result:
using ReactiveKernels, Enzyme, DifferentiationInterface
@kernelpassthrough(groups, rates) =begin
per =plate(groups) do g
g # also identity(g), or s.xs over recordsend
total =sum(reduce(vcat, per) .* rates)
end
groups = [[0.5, 1.0, 1.0], [0.5], [1.0, 1.0]]
rates = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
ad =prepare_ad(passthrough, AutoEnzyme(; mode = Enzyme.Reverse), groups, copy(rates);
active =:rates, want =:total)
ad_value_and_gradient!(ad, similar(rates), groups, copy(rates))
# EnzymeRuntimeActivityError: Constant memory is stored (or returned) to a differentiable variable
The primal is correct and the derivative is defined (vcat(groups...)).
Cause. The plate's pointwise buffer is a fresh container, and the cell stores the constant argument's element pointers into it. Static activity analysis cannot prove that container inactive once its contents reach an active result. Plain Enzyme fails the same way without ReactiveKernels: sum(onealloc(map(identity, groups)) .* rates) with Const(groups). benchmark/repro_enzyme_constant_element_container.jl reproduces it with Enzyme alone; measured on Julia 1.10.12 and 1.12.7 with Enzyme 0.13.210 (Enzyme_jll 0.0.301). Fresh copies of the elements, or reading the constant argument without the intermediate container, differentiate; set_runtime_activity(Reverse) differentiates every case.
Workarounds today.
Bind the data: prepare(spec; bound = (; groups)). A data-only plate is computed once at preparation and leaves the gradient.
Prepare the gradient with AutoEnzyme(mode = Enzyme.set_runtime_activity(Enzyme.Reverse)).
Return a fresh value from the cell, for example copy(s.xs), at one allocation per cell.
Tracking. RK's lowering stores the authored cell result unchanged. test/test_plate_consumer_native_ad.jl (testset "plate cells returning inactive argument storage under native Reverse") pins the three unbound gradients as @test_broken; an Enzyme that repairs its activity analysis turns them into "Unexpected Pass", the signal to drop the pins and the docs/src/constraints.md entry. The repair belongs in Enzyme's activity analysis.
Activity