Zygote.jl: @adjoint! (mutating / inplace adjoints)

Inspecting the Zygote code, I can see that aside from @adjoint there is also @adjoint! that is used to declare the adjoints of some mutating functions (like push! etc). I can’t find any doc strings or documentation when and how this can be used. I suspect, there are some limitations as Zygote generally forbids mutating. Can somebody explain @adjoint! to me or send me a link where it is explained?

More directly, I was wondering if I can define adjoints for some functions where I pre-allocate memory for the result, like a pre-allocated FFT or matrix multiplication.

1 Like

AFAICT, this is the entirety of the difference between adjoint and adjoint!. Git blame tells me both versions have existed since the first commit of ZygoteRules, but the docs are coy about why adjoint! is a thing in the first place (outside of pure convenience).

1 Like