# Mutate Zygote Gradients with a Custom Mask Before Update?

**URL:** <https://discourse.julialang.org/t/mutate-zygote-gradients-with-a-custom-mask-before-update/57236>\
**Category:** Machine Learning\
**Tags:** flux, zygote\
**Created:** [March 15, 2021, 9:56pm UTC](https://discourse.julialang.org/t/mutate-zygote-gradients-with-a-custom-mask-before-update/57236 "2021-03-15T21:56:53Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [March 25, 2021, 5:07am UTC](https://discourse.julialang.org/t/mutate-zygote-gradients-with-a-custom-mask-before-update/57236/2 "2021-03-25T05:07:50Z")

</div>

> [@boltzmannbrain](#):
>
> Is there some way to “detach” the gradients (e.g. via converting them to a new type), mutating them via the mask, and then converting them back to Zygote.gradient objects?

There’s no need to do that for the code you have above, because the only place gradients are “tracked” is inside the callback to `pullback`. In other words, there’s no such thing as a `Zygote.gradient` object and `gs` is just a collection of arrays 🙂.

With that in mind, the error has to be occurring within the call stack of `loss` somewhere. If you share a complete [MWE](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757) with the loss and all the auxiliary training code, we can troubleshoot that part.

---

_[View the full topic](https://discourse.julialang.org/t/mutate-zygote-gradients-with-a-custom-mask-before-update/57236)._
