Closed newalexander closed 6 months ago
[3] (::ChainRulesCore.ProjectTo{SparseMatrixCSC, NamedTuple{(:element, :axes, :rowval, :nzranges, :colptr), Tuple{ChainRulesCore.ProjectTo{Float64, NamedTuple{(), Tuple{}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}, Vector{Int64}, Vector{UnitRange{Int64}}, Vector{Int64}}}})(dx::Matrix{ForwardDiff.Dual{ForwardDiff.Tag{DataType, Float64}, Float64, 1}}) @ ChainRulesCore ~/.julia/packages/ChainRulesCore/uxrij/src/projection.jl:580
It seems like it's creating a SparseMatrixCSC of Float64. @DhairyaLGandhi how would I investigate why?
any update on this? I too encountered this problem today.
Hi think this issue should be reported to SparseDiffTools.jl and probably fixed in ChainRules.jl
was a bit of an odd response in https://github.com/CarloLucibello/GraphNeuralNetworks.jl/issues/125 that lead to this issue. The issue should be reported in ChainRules.jl because it's ChainRules.jl that needs a fix. There's no code that could/should be changed to handle this here, any code change would have to happen in ChainRules.jl to fix this. So waiting on a SparseDiffTools.jl change is not going to lead anywhere 😅.
Here's a version of the issue that uses no code from SparseDiffTools:
using Zygote, SparseArrays, ForwardDiff
x, v = rand(Float32, 5), rand(Float32, 5)
A = sprand(Float32, 5, 5, 0.5)
loss(_x) = sum(tanh.(A * _x))
T = typeof(ForwardDiff.Tag(nothing, eltype(x)))
y = ForwardDiff.Dual{T, eltype(x), 1}.(x, ForwardDiff.Partials.(tuple.(reshape(v, size(x)))))
g = x -> first(Zygote.gradient(loss, x))
y = _default_autoback_hesvec_cache(x, v)
ForwardDiff.partials.(g(y), 1)
Let's take that upstream.
https://github.com/JuliaDiff/ChainRulesCore.jl/issues/648 is the upstream issue.
Hello! I can't seem to use
autoback_hesvec
when the function includes a sparse CSC matrix.with the full message
This is with
[47a9eef4] SparseDiffTools v1.20.0
and[082447d4] ChainRules v1.26.0
. The issue was originally noticed here, where it was suggested to be reported here instead.