-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
LowerTriangular causes error #1381
Comments
I think this is a mismatch between "structural" and "natural" gradients, which is one of the motivations for the gradient projection machinery. MWE: julia> using Zygote, LinearAlgebra
julia> x = UpperTriangular([1 2; 3 4]);
julia> dump(x)
UpperTriangular{Int64, Matrix{Int64}}
data: Array{Int64}((2, 2)) [1 2; 3 4]
julia> gradient(x -> x[1,1], x)[1] # getindex on an AbstractMatrix "natural", then ProjectTo back to subspace
2×2 UpperTriangular{Float64, Matrix{Float64}}:
1.0 0.0
⋅ 0.0
julia> gradient(x -> x.data[1,1], x)[1] # default "structural" representation, as for any struct
(data = [1.0 0.0; 0.0 0.0],)
julia> gradient(x -> UpperTriangular(x)[1,1], x.data)[1]
2×2 UpperTriangular{Float64, Matrix{Float64}}:
1.0 0.0
⋅ 0.0
julia> gradient(x -> UpperTriangular(x).data[1,1], x.data)[1]
ERROR: MethodError: no method matching UpperTriangular(::NamedTuple{(:data,), Tuple{Matrix{Float64}}}) With JuliaDiff/ChainRulesCore.jl#446 : julia> gradient(x -> x.data[1,1], x)[1] # structural now converted back to natural
2×2 UpperTriangular{Float64, Matrix{Float64}}:
1.0 0.0
⋅ 0.0
julia> gradient(x -> UpperTriangular(x).data[1,1], x.data)[1]
2×2 UpperTriangular{Float64, Matrix{Float64}}:
1.0 0.0
⋅ 0.0 |
Yeah I see - thanks, I was wondering if it was something like that. From JuliaDiff/ChainRulesCore.jl#446 (comment) it seems resolving this is a bigger body of work, perhaps? Do you know if there are any workarounds we could apply in the meantime? |
It ought to be possible to hack just one case, I thought |
OK thanks for the attempt @mcabbott. I kinda wish I knew where to start - is there some internals documentation for Zygote etc somewhere so I can get a rough picture of how it hangs together? |
We are trying to optimize over some code which contain something along the lines of:
And get the error:
Unfortunately I don't understand
@adjoint
andrrules
and how to define a pullback correctly. It seems forHermitian
andSymmetric
there are special cases to deal with being passed aNamedTuple{(:data,)}
. Does something like that need being defined forLowerTriangular
/UpperTriangular
etc? Honestly I'm totally lost how aNamedTuple
ends up being injected here (is that a general thing with structs?).The strangest thing about all this, is we experience this error in our tests, and this error is generated in the first test set but the second (identical!) test set works perfectly fine. Does anyone have any ideas what might be going on?
CC @lukekh
The text was updated successfully, but these errors were encountered: