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

**URL:** https://discourse.julialang.org/t/zygote-jl-adjoint-mutating-inplace-adjoints/78241
**Category:** Machine Learning
**Tags:** differentiation, zygote, autodiff
**Created:** [March 21, 2022, 8:50pm UTC](https://discourse.julialang.org/t/zygote-jl-adjoint-mutating-inplace-adjoints/78241 "2022-03-21T20:50:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MaximilianGelbrecht](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@MaximilianGelbrecht](https://discourse.julialang.org/u/MaximilianGelbrecht)
#### Post date: [March 21, 2022, 8:50pm UTC](https://discourse.julialang.org/t/zygote-jl-adjoint-mutating-inplace-adjoints/78241/1 "2022-03-21T20:50:01Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)
#### Post date: [April 2, 2022, 5:05am UTC](https://discourse.julialang.org/t/zygote-jl-adjoint-mutating-inplace-adjoints/78241/2 "2022-04-02T05:05:13Z")

</div>

AFAICT, [this](https://github.com/FluxML/ZygoteRules.jl/blob/master/src/adjoint.jl#L66-L72) 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).
