# How to use gradient of neural network as the loss function?

**URL:** <https://discourse.julialang.org/t/how-to-use-gradient-of-neural-network-as-the-loss-function/50569>\
**Category:** Machine Learning\
**Tags:** question\
**Created:** [November 22, 2020, 6:19am UTC](https://discourse.julialang.org/t/how-to-use-gradient-of-neural-network-as-the-loss-function/50569 "2020-11-22T06:19:50Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 23, 2021, 6:30pm UTC](https://discourse.julialang.org/t/how-to-use-gradient-of-neural-network-as-the-loss-function/50569/14 "2021-03-23T18:30:15Z")

</div>

You don’t need to modify much. There’s examples in the DiffEqFlux repo where the RHS of the ODE uses Zygote internally, and ReverseDiff for the VJP. It has to be that order though: the other fails.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-use-gradient-of-neural-network-as-the-loss-function/50569)._
