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
Second order forward-over-reverse fails with a mixed activity error when the differentiated function fills a preallocated array using a non-trivial fused broadcast expression (by non-trivial here I mean anything but y .= x).
The stacktrace points to broadcast_unalias, which suggests that the problem might stem from the code path that allocates intermediate storage whenever there's aliasing between the LHS and RHS of a broadcast assignment. In the MWE below, this code path is not hit and no intermediate storage is allocated, but the code path exists in the compiled f (for one, it makes AllocCheck.jl report allocations in f), so I guess Enzyme has to differentiate it.
The error does not occur if the broadcast expression is replaced with the equivalent map! call. Notably, map! does not check for aliasing.
Forgot to mention: Enzyme.API.runtimeActivity!(true) does fix the problem, but leads to a warning about fallback BLAS replacements. This warning appears both for the broadcast and map! versions.
julia> using Enzyme
julia> Enzyme.API.runtimeActivity!(true)
julia> include("enzymebroadcast.jl");
┌ Warning: Using fallback BLAS replacements for (["cblas_daxpy64_", "cblas_dcopy64_"]), perfo
rmance may be degraded
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/Y4hSX/src/utils.jl:59
hv = [-2.0]
Let me also mention that in a Pluto notebook this warning fails to show and triggers an error instead: ArgumentError: Base.TTY(RawFD(4294967295) invalid status, 0 bytes waiting) is not initialized. But that's probably a Pluto issue. (Edit: submitted fonsp/Pluto.jl#3012.)
The error goes away if I replace dot(tmp, x) with the ~equivalent sum(tmp .* x) (and thus remove the dependency on LinearAlgebra). So the trigger is not the broadcasted assignment alone, but some interaction between it and dot, when doing 2nd order forward-over-reverse.
Second order forward-over-reverse fails with a mixed activity error when the differentiated function fills a preallocated array using a non-trivial fused broadcast expression (by non-trivial here I mean anything but
y .= x
).The stacktrace points to
broadcast_unalias
, which suggests that the problem might stem from the code path that allocates intermediate storage whenever there's aliasing between the LHS and RHS of a broadcast assignment. In the MWE below, this code path is not hit and no intermediate storage is allocated, but the code path exists in the compiledf
(for one, it makes AllocCheck.jl report allocations inf
), so I guess Enzyme has to differentiate it.The error does not occur if the broadcast expression is replaced with the equivalent
map!
call. Notably,map!
does not check for aliasing.Possibly related: #1637, #1482, #1476
MWE:
Error:
The text was updated successfully, but these errors were encountered: