Help with gradient

Do what the error message tells you: don’t mutate arrays, use a functional style (map, comprehensions, etc).

It is difficult to help more without a concrete, self-contained example.

Also, see

https://fluxml.ai/Zygote.jl/latest/utils/#Zygote.Buffer