-
-
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
getproperty
error
#1058
Comments
Dug a bit further into this. The immediate error is solved by adding a method for grad_mut(x::AnalyticWeights) = Ref{Any}(nt_nothing(x)) which previously dispatched to the After adding this the error is julia> gradient(values -> AnalyticWeights(values).sum, [1.0, 2.0, 3.0])
ERROR: MethodError: no method matching (::Zygote.var"#AnalyticWeights_pullback#117")(::Base.RefValue{Any})
Closest candidates are:
(::Zygote.var"#AnalyticWeights_pullback#117")(::AbstractArray) at /Users/mzgubic/JuliaEnvs/PortfolioNets.jl/dev/Zygote/src/lib/lib.jl:12
(::Zygote.var"#AnalyticWeights_pullback#117")(::ChainRulesCore.Tangent) at /Users/mzgubic/JuliaEnvs/PortfolioNets.jl/dev/Zygote/src/lib/lib.jl:13
(::Zygote.var"#AnalyticWeights_pullback#117")(::ChainRulesCore.AbstractThunk) at /Users/mzgubic/JuliaEnvs/PortfolioNets.jl/dev/Zygote/src/lib/lib.jl:14
Stacktrace:
[1] (::Zygote.ZBack{Zygote.var"#AnalyticWeights_pullback#117"})(dy::Base.RefValue{Any})
@ Zygote ~/JuliaEnvs/PortfolioNets.jl/dev/Zygote/src/compiler/chainrules.jl:141
[2] Pullback
@ ./REPL[4]:1 [inlined]
[3] (::typeof(∂(#5)))(Δ::Float64)
@ Zygote ~/JuliaEnvs/PortfolioNets.jl/dev/Zygote/src/compiler/interface2.jl:0
[4] (::Zygote.var"#50#51"{typeof(∂(#5))})(Δ::Float64)
@ Zygote ~/JuliaEnvs/PortfolioNets.jl/dev/Zygote/src/compiler/interface.jl:41
[5] gradient(f::Function, args::Vector{Float64})
@ Zygote ~/JuliaEnvs/PortfolioNets.jl/dev/Zygote/src/compiler/interface.jl:76
[6] top-level scope
@ REPL[4]:1 which means it looks like the It seemed related to #685, maybe the problem is related to the fact that julia> mutable struct MyWeights
values
sum
end
julia> MyWeights(values) = MyWeights(values, sum(values)) But that seems to work fine: julia> gradient(values -> MyWeights(values).sum, [1.0, 2.0, 3.0])
(Fill(1.0, 3),) |
I think we actually need to accept |
What exactly is the purpose of |
I think it is a vestigial organ left-over from when Zygote supported mutation. I am not sure anyone really understands it anymore |
It is unfortunately a requirement for diffing through code which uses mutable structs (note, not mutable arrays, which are unsupported). It consists of a more primitive version of the more robust and documented mechanism in JuliaDiff/ChainRulesCore.jl#626, along with a cache to store accumulated gradients of mutable structs. I would love to get rid of it, but a lot of code in the wild relies on it working. Which is unfortunate, because as this issue demonstrates it has been a very leaky and bug-prone abstraction. |
Ahh, I see. Thanks for the replies! However the function |
This is only the case if we subtype with
Resulting in:
Because of |
Ah yes, Line 3 in cf7f7d0
Vector helps with your use case.
|
I tried the following line (so I don't destroy anything): Indeed the error is gone, looks good! Thank you very much! |
I've encountered this in the wild, but here is a minimal breaking example:
(It's possible to get around it by using
w -> sum(w)
(by adding an rrule for a constructor, see below), but the original example isgradient(std, rand(3), AnalyticWeights([1.0, 2.0, 3.0]))
which calls the weights under the hood)The text was updated successfully, but these errors were encountered: