-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
no gradients if we save the Flux.params into a variable #1346
Comments
Edit after posting the issue. The behavior might be the expected one. I think it must be the case as we want to use only explicit loss functions. |
It looks like the explicit parameters version is actually correct and the other two are wrong, because they give the same answer when you remove the regularization term. I'm trying to figure out why no gradient is being returned for |
@ToucheSir just noticed the correct way to call the implicit function is like this |
Yes, but as seen in your edited example you can also call |
The answers presently above look correct to me. Perhaps a simpler example of what they illustrate is this. None of these seem wrong, but the ones mixing explicit arguments and global references are perhaps surprising. julia> using Zygote, LinearAlgebra, ForwardDiff
julia> v = [2.0, 3.0];
julia> gradient(x -> dot(x,x), v)
([4.0, 6.0],)
julia> gradient(x -> dot(x,v), v) # one global reference
([2.0, 3.0],)
julia> ForwardDiff.gradient(x -> dot(x,v), v) # agrees
2-element Vector{Float64}:
2.0
3.0
julia> gradient(x -> dot(v,v), v) # two global references
(nothing,)
julia> ForwardDiff.gradient(x -> dot(v,v), v) # agrees
2-element Vector{Float64}:
0.0
0.0
julia> gradient(() -> dot(v,v), Params([v])) # implicit mode
Grads(...)
julia> ans[v] # same answer as the first, but via global ref.
2-element Vector{Float64}:
4.0
6.0 |
See the following MWE:
The values of the gradients are bellow.
∇m_explicit
and∇m_slow
are equal and correct, but∇m
isnothing
.The text was updated successfully, but these errors were encountered: