Hello, I am new to Julia and Flux. I was running the sample code. I got the following error. I am using Julia 1.1.
julia> using Flux.Tracker
julia> f(x) = 3x^2 + 2x + 1
f (generic function with 1 method)
julia> df(x) = Tracker.gradient(f, x; nest = true)[1]
df (generic function with 1 method)
julia> df(2)
14.0 (tracked)
julia> d2f(x) = Tracker.gradient(df, x; nest = true)[1]
d2f (generic function with 1 method)
julia> d2f(2)
6.0 (tracked)
julia> f(W, b, x) = W * x + b
f (generic function with 2 methods)
julia> Tracker.gradient(f, 2, 3, 4)
(4.0 (tracked), 1.0 (tracked), 2.0 (tracked))
julia> W = param(2)
2.0 (tracked)
julia> b = param(3)
3.0 (tracked)
julia> f(x) = W * x + b
f (generic function with 2 methods)
julia> grads = Tracker.gradient(() -> f(4), params(W, b))
ERROR: UndefVarError: params not defined
Stacktrace:
[1] top-level scope at none:0
julia> using Flux
julia> grads = Tracker.gradient(() -> f(4), params(W, b))
Grads(...)
This makes it run. But is it intended to be like this?
You need to do using Flux, yeah. We can perhaps clarify the docs here.
Hello, I'm facing same issue when running a model from the docs (simple linear model)
using Flux
W = rand(2, 5)
b = rand(2)
predict(x) = W*x .+ b
function loss(x, y)
y′ = predict(x)
sum((y.-y′).^2)
end
x, y = rand(5), rand(2)
loss(x, y)
gs = gradient(()->loss(x, y), params(W, b))
it keep give me "params not defined"
Seems like replacing params by Flux.params works.
gs = gradient(() -> loss(x, y), Flux.params(W, b))
We could address it in the docs and qualify params appropriately.
I think params has been qualified in the docs
Most helpful comment
Hello, I'm facing same issue when running a model from the docs (simple linear model)
it keep give me "params not defined"