# How to add norm of gradient to a loss function?

**URL:** <https://discourse.julialang.org/t/how-to-add-norm-of-gradient-to-a-loss-function/69873>\
**Category:** Machine Learning\
**Tags:** flux, zygote\
**Created:** [October 16, 2021, 2:08am UTC](https://discourse.julialang.org/t/how-to-add-norm-of-gradient-to-a-loss-function/69873 "2021-10-16T02:08:17Z")\
**Posts on this page:** 1\
**Showing post:** 15

<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:** [October 28, 2021, 6:44pm UTC](https://discourse.julialang.org/t/how-to-add-norm-of-gradient-to-a-loss-function/69873/15 "2021-10-28T18:44:35Z")

</div>

Ok, this is tricky to accomplish with Zygote alone, but you could try mixing ADs like in [Zygote push forward unable to differentiate through generic broadcast - #10 by RynoLaubscher](https://discourse.julialang.org/t/zygote-push-forward-unable-to-differentiate-through-generic-broadcast/64364/10). Unfortunately I don’t have any personal experience with that, so if you’re unable to get that working and nobody else replies, I’d recommend hitting up #autodiff on Slack.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-add-norm-of-gradient-to-a-loss-function/69873)._
