# Different loss with Zygote when taking gradients vs. without

**URL:** <https://discourse.julialang.org/t/different-loss-with-zygote-when-taking-gradients-vs-without/32523>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [December 20, 2019, 6:13pm UTC](https://discourse.julialang.org/t/different-loss-with-zygote-when-taking-gradients-vs-without/32523 "2019-12-20T18:13:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![holylorenzo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/holylorenzo/32/34169_2.png) [@holylorenzo](https://discourse.julialang.org/u/holylorenzo)\
**Post date:** [December 20, 2019, 6:13pm UTC](https://discourse.julialang.org/t/different-loss-with-zygote-when-taking-gradients-vs-without/32523/1 "2019-12-20T18:13:06Z")

</div>

I am working on the newest Flux branch and noticed some weird behavior.

When I calculate the loss of my model’s outputs I get the following number:

```julia
> y_pred = model(x)
> loss(y_pred, y)
0.003791215f0

```

However, doing the same calculation while taking gradients gives a different result:

```julia
> ps = Params(params(model))
  gradient(ps) do
      y_pred = model(x)
      l = loss(y_pred, y)
      println(l)
      return l
  end

0.035433643

```

Maybe there is something obvious I’m missing, otherwise I’ll probably have to put together a minimum working example.  
Thanks for any help!
