# "gradcheck" in Flux?

**URL:** <https://discourse.julialang.org/t/gradcheck-in-flux/39158>\
**Category:** Machine Learning\
**Created:** [May 9, 2020, 3:33am UTC](https://discourse.julialang.org/t/gradcheck-in-flux/39158 "2020-05-09T03:33:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaynick](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jaynick](https://discourse.julialang.org/u/jaynick)\
**Post date:** [May 9, 2020, 3:33am UTC](https://discourse.julialang.org/t/gradcheck-in-flux/39158/1 "2020-05-09T03:33:52Z")

</div>

Is there a function to check the Zygote gradient against a finite-difference?

I think I had seen something in discussions here but cannot find it, also not in the docs

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [May 9, 2020, 4:35am UTC](https://discourse.julialang.org/t/gradcheck-in-flux/39158/2 "2020-05-09T04:35:44Z")

</div>

There was a recent discussion on that might be helpful on Zulip: [Checking adjoints](https://julialang.zulipchat.com/#narrow/stream/233469-autodiff/topic/Checking.20adjoints)

Some links from that discussion:

[the `gradtest` function](https://github.com/FluxML/Zygote.jl/blob/ac4f1a0727d860b31197a336a02d04b33cb21219/test/gradcheck.jl)

[A PR to use FiniteDifferences.jl](https://github.com/FluxML/Zygote.jl/pull/464)

---

<div class="post-metadata">

**Author:** ![jaynick](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jaynick](https://discourse.julialang.org/u/jaynick)\
**Post date:** [May 11, 2020, 5:53am UTC](https://discourse.julialang.org/t/gradcheck-in-flux/39158/3 "2020-05-11T05:53:19Z")

</div>

This is helpful…

… however it seems difficult how to use these functions to check a constructed model that is differentiated with respect to Flux.params() or one of the other 2 schemes mentioned in the Zygote docs. I am trying to figure out how to adapt the idea, if it is possible. Probably I am overlooking the obvious!

(I do not have a clear statement of the deeper problem yet, but the surface problem is that the `ngradient` function evaluates a function that accepts arrays as its arguments, whereas the typical flux of writing an ML model does not result in functions that take their parameter arrays as arguments)
