Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

60-minute blitz out of date #118

Closed
jklaise opened this issue Mar 16, 2019 · 4 comments
Closed

60-minute blitz out of date #118

jklaise opened this issue Mar 16, 2019 · 4 comments

Comments

@jklaise
Copy link

jklaise commented Mar 16, 2019

I'm working through the 60-minute blitz, but it appears it is out of date:

  • derivative appears to be succeeded by gradient
  • Even so, taking the second derivative of the polynomial example doesn't work:
using Flux.Tracker: gradient
f(x) = 3x^2 + 2x + 1
df(x) = gradient(f, x)
df(5) # (32.0 (tracked),)
ddf(x) = gradient(df, x)
ddf(5) # expect 6

Last line results in

ERROR: Function output is not scalar
Stacktrace:
 [1] losscheck(::Tuple{Flux.Tracker.TrackedReal{Float64}}) at /home/janis/.julia/packages/Flux/8XpDt/src/tracker/back.jl:171
 [2] gradient_(::Function, ::Int64) at /home/janis/.julia/packages/Flux/8XpDt/src/tracker/back.jl:72
 [3] #gradient#24 at /home/janis/.julia/packages/Flux/8XpDt/src/tracker/back.jl:182 [inlined]
 [4] gradient at /home/janis/.julia/packages/Flux/8XpDt/src/tracker/back.jl:182 [inlined]
 [5] ddf(::Int64) at ./REPL[69]:1
 [6] top-level scope at none:0
@thebhatman
Copy link

@jklaise I don't think higher order derivatives can be calculated this way in Flux. IMO, it's best to use Hessians to obtain second order derivatives. You can do something like this:

julia> using Flux

julia> using ReverseDiff

julia> f(x) = @. 3*x^2 + 2*x + 1
f (generic function with 1 method)

julia> ReverseDiff.hessian(f,[5])
1×1 Array{Int64,2}:
 6

@MikeInnes
Copy link
Member

You can do this but you'll want to follow the syntax given in the latest version of the docs.

We should update the tutorial, but FWIW you should be able to activate the project and get a compatible version of Flux.

@jklaise
Copy link
Author

jklaise commented Mar 22, 2019

@MikeInnes thanks for the pointer, I think I got confused between several different versions of the API. I'll see if I can finish the blitz successfully and update the tutorial.

@aminya
Copy link

aminya commented Sep 28, 2019

This was fixed by #143 . This can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants