# Please help with the very simplest 4-line Autodiff example: Flux0.9

**URL:** <https://discourse.julialang.org/t/please-help-with-the-very-simplest-4-line-autodiff-example-flux0-9/33257>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [January 12, 2020, 2:48am UTC](https://discourse.julialang.org/t/please-help-with-the-very-simplest-4-line-autodiff-example-flux0-9/33257 "2020-01-12T02:48:11Z")\
**Posts on this page:** 2\
**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:** [January 12, 2020, 2:48am UTC](https://discourse.julialang.org/t/please-help-with-the-very-simplest-4-line-autodiff-example-flux0-9/33257/1 "2020-01-12T02:48:11Z")

</div>

This is with Flux 0.9, Julia1.3

Meta comment: Julia looks amazing. I keep coming back to it, but everything I try does not seem to work. Bad beginner luck.

1a) This example I want to work. It should find [0,0] as the solution to the bottom of z=x^2 + y^2, but it give an error **“`back!` was already used”**

```julia
using Flux, Tracker
p = param([0.3, -0.7])
for i=1:5  
  global p
  theloss = sum(p .* p)
  Tracker.back!(theloss) # `back!` was already used
  p = p - 0.05 * Tracker.grad(p)
  println(i," ",p)
end

```

1b) In this version gradient returns something that does not seem to be a gradient,  
also nor a function that can be called to obtain a gradient. I also tried many other variations. But a solution to 1a) above is enough. This is just to show that other things were tried.

```julia
p = param([0.3, -0.7])
theloss(p) = sum(p .* p)
for i=1:5  
  global p
  p = p - 0.05 * gradient(theloss,p)
  println(i," ",p)
end

```

1. Here, we want to get the gradient with respect to _only the first parameter_ to the function, because the second parameter is not numeric.

```julia
f(x,path) = x^2 # path is some other variable, e.g. a string
gradient(f,1) # no method matching f with a single parameter
gradient(f,1,"foo")	# no method matching param(String)

```

---

<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:** [January 12, 2020, 4:33am UTC](https://discourse.julialang.org/t/please-help-with-the-very-simplest-4-line-autodiff-example-flux0-9/33257/2 "2020-01-12T04:33:57Z")

</div>

My suggestion is, unless you really need to, just update to the Zygote-backed Flux 0.10. I find it’s much easier to debug.
