FluxML / GeometricFlux.jl

Geometric Deep Learning for Flux
https://fluxml.ai/GeometricFlux.jl/stable/
MIT License
348 stars 30 forks source link

examples/gcn.jl not working #262

Closed arnaudmgh closed 2 years ago

arnaudmgh commented 2 years ago

Related to #76 I believe

Error at the last line (training):

julia> @epochs epochs Flux.train!(loss, ps, train_data, opt, cb=throttle(evalcb, 10))
[ Info: Epoch 1
ERROR: MethodError: no method matching adjacency_matrix(::SimpleGraph{Int64}, ::Type{Int64})
Closest candidates are:
  adjacency_matrix(::LightGraphs.AbstractGraph, ::DataType; dir) at /Users/aamzallag/.julia/packages/LightGraphs/IgJif/src/linalg/spectral.jl:19
  adjacency_matrix(::AbstractArray{T,2} where T, ::DataType) at /Users/aamzallag/.julia/packages/GraphSignals/W9rzh/src/linalg.jl:1
  adjacency_matrix(::FeaturedGraph, ::DataType) at /Users/aamzallag/.julia/packages/GraphSignals/W9rzh/src/linalg.jl:7
Stacktrace:
 [1] adjacency_matrix(::FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}, ::DataType) at /Users/aamzallag/.julia/packages/GraphSignals/W9rzh/src/linalg.jl:7 (repeats 2 times)
 [2] _pullback at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/lib/grad.jl:8 [inlined]
 [3] GCNConv at /Users/aamzallag/.julia/packages/GeometricFlux/kwwxb/src/layers/conv.jl:61 [inlined]
 [4] _pullback(::Zygote.Context, ::GCNConv{Float32,typeof(relu),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}}, ::Array{Float32,2}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [5] applychain at /Users/aamzallag/.julia/packages/Flux/05b38/src/layers/basic.jl:36 [inlined]
 [6] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{GCNConv{Float32,typeof(relu),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}},Dropout{Float64,Colon},GCNConv{Float32,typeof(identity),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}}}, ::Array{Float32,2}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [7] Chain at /Users/aamzallag/.julia/packages/Flux/05b38/src/layers/basic.jl:38 [inlined]
 [8] _pullback(::Zygote.Context, ::Chain{Tuple{GCNConv{Float32,typeof(relu),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}},Dropout{Float64,Colon},GCNConv{Float32,typeof(identity),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}}}}, ::Array{Float32,2}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [9] loss at ./REPL[958]:1 [inlined]
 [10] _pullback(::Zygote.Context, ::typeof(loss), ::Array{Float32,2}, ::Array{Float32,2}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [11] adjoint at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/lib/lib.jl:175 [inlined]
 [12] _pullback at /Users/aamzallag/.julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [13] #15 at /Users/aamzallag/.julia/packages/Flux/05b38/src/optimise/train.jl:83 [inlined]
 [14] _pullback(::Zygote.Context, ::Flux.Optimise.var"#15#21"{typeof(loss),Tuple{Array{Float32,2},Array{Float32,2}}}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [15] pullback(::Function, ::Zygote.Params) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface.jl:172
 [16] gradient(::Function, ::Zygote.Params) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface.jl:53
 [17] macro expansion at /Users/aamzallag/.julia/packages/Flux/05b38/src/optimise/train.jl:82 [inlined]
 [18] macro expansion at /Users/aamzallag/.julia/packages/Juno/n6wyj/src/progress.jl:134 [inlined]
 [19] train!(::Function, ::Zygote.Params, ::Array{Tuple{Array{Float32,2},Array{Float32,2}},1}, ::ADAM; cb::Flux.var"#throttled#42"{Flux.var"#throttled#38#43"{Bool,Bool,typeof(evalcb),Int64}}) at /Users/aamzallag/.julia/packages/Flux/05b38/src/optimise/train.jl:80
 [20] top-level scope at /Users/aamzallag/.julia/packages/Flux/05b38/src/optimise/train.jl:115
 [21] top-level scope at /Users/aamzallag/.julia/packages/Juno/n6wyj/src/progress.jl:134

(also the loading commands at the beginning don't work, you need to give the path of the package)

axla-io commented 2 years ago

Error at the last line (training):...

I believe that this is related to the changes from LightGraphs to Graphs, see commit edece65. So replacing using Graphs.SimpleGraphs with using LightGraphs.SimpleGraphs Should solve this specific problem. This is a bug though, that should be fixed.

arnaudmgh commented 2 years ago

thanks for the hint @axla-code . I tried, and I don't have this error anymore.

It does not work yet, though, I now have a different error:

ERROR: MethodError: no method matching zero(::Type{Any})
Closest candidates are:
  zero(::Type{Union{Missing, T}}) where T at missing.jl:104
  zero(::Type{LibGit2.GitHash}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/LibGit2/src/oid.jl:220
  zero(::Type{Dates.Date}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/Dates/src/types.jl:405
  ...
Stacktrace:
 [1] zero(::Type{Any}) at ./missing.jl:105
 [2] _zeros_eltypes at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/SparseArrays/src/higherorderfns.jl:203 [inlined]
 [3] _noshapecheck_map(::Zygote.var"#1134#1141", ::SparseMatrixCSC{Any,Int64}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/SparseArrays/src/higherorderfns.jl:159
 [4] map(::Zygote.var"#1134#1141", ::SparseMatrixCSC{Any,Int64}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/SparseArrays/src/higherorderfns.jl:1153
 [5] adjoint at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/lib/broadcast.jl:139 [inlined]
 [6] _pullback at /Users/aamzallag/.julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [7] adjoint at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/lib/lib.jl:175 [inlined]
 [8] _pullback at /Users/aamzallag/.julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [9] broadcasted at ./broadcast.jl:1257 [inlined]
 [10] #degrees#7 at /Users/aamzallag/.julia/packages/GraphLaplacians/rAPWS/src/adjmat.jl:51 [inlined]
 [11] _pullback(::Zygote.Context, ::GraphLaplacians.var"##degrees#7", ::Symbol, ::typeof(degrees), ::SparseMatrixCSC{Int64,Int64}, ::Type{Float32}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0 (repeats 2 times)
 [12] #inv_sqrt_degree_matrix#11 at /Users/aamzallag/.julia/packages/GraphLaplacians/rAPWS/src/adjmat.jl:99 [inlined]
 [13] _pullback(::Zygote.Context, ::GraphLaplacians.var"##inv_sqrt_degree_matrix#11", ::Symbol, ::typeof(inv_sqrt_degree_matrix), ::SparseMatrixCSC{Int64,Int64}, ::Type{Float32}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0 (repeats 2 times)
 [14] #normalized_laplacian#13 at /Users/aamzallag/.julia/packages/GraphLaplacians/rAPWS/src/adjmat.jl:131 [inlined]
 [15] _pullback(::Zygote.Context, ::GraphLaplacians.var"##normalized_laplacian#13", ::Bool, ::typeof(normalized_laplacian), ::SparseMatrixCSC{Int64,Int64}, ::Type{Float32}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0 (repeats 2 times)
 [16] GCNConv at /Users/aamzallag/.julia/packages/GeometricFlux/kwwxb/src/layers/conv.jl:62 [inlined]
 [17] _pullback(::Zygote.Context, ::GCNConv{Float32,typeof(relu),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}}, ::Array{Float32,2}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [18] applychain at /Users/aamzallag/.julia/packages/Flux/05b38/src/layers/basic.jl:36 [inlined]
 [19] _pullback(::Zygote.Context, ::typeof(Flux.applychain), ::Tuple{GCNConv{Float32,typeof(relu),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}},Dropout{Float64,Colon},GCNConv{Float32,typeof(identity),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}}}, ::Array{Float32,2}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [20] Chain at /Users/aamzallag/.julia/packages/Flux/05b38/src/layers/basic.jl:38 [inlined]
 [21] _pullback(::Zygote.Context, ::Chain{Tuple{GCNConv{Float32,typeof(relu),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}},Dropout{Float64,Colon},GCNConv{Float32,typeof(identity),FeaturedGraph{SimpleGraph{Int64},Array{Float64,2},Array{Float64,2},Array{Float64,1}}}}}, ::Array{Float32,2}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [22] loss at ./REPL[25]:1 [inlined]
 [23] _pullback(::Zygote.Context, ::typeof(loss), ::Array{Float32,2}, ::Array{Float32,2}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [24] adjoint at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/lib/lib.jl:175 [inlined]
 [25] _pullback at /Users/aamzallag/.julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [26] #15 at /Users/aamzallag/.julia/packages/Flux/05b38/src/optimise/train.jl:83 [inlined]
 [27] _pullback(::Zygote.Context, ::Flux.Optimise.var"#15#21"{typeof(loss),Tuple{Array{Float32,2},Array{Float32,2}}}) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface2.jl:0
 [28] pullback(::Function, ::Zygote.Params) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface.jl:172
 [29] gradient(::Function, ::Zygote.Params) at /Users/aamzallag/.julia/packages/Zygote/EjVY4/src/compiler/interface.jl:53
 [30] macro expansion at /Users/aamzallag/.julia/packages/Flux/05b38/src/optimise/train.jl:82 [inlined]
 [31] macro expansion at /Users/aamzallag/.julia/packages/Juno/n6wyj/src/progress.jl:134 [inlined]
 [32] train!(::Function, ::Zygote.Params, ::Array{Tuple{Array{Float32,2},Array{Float32,2}},1}, ::ADAM; cb::Flux.var"#throttled#42"{Flux.var"#throttled#38#43"{Bool,Bool,typeof(evalcb),Int64}}) at /Users/aamzallag/.julia/packages/Flux/05b38/src/optimise/train.jl:80
 [33] top-level scope at /Users/aamzallag/.julia/packages/Flux/05b38/src/optimise/train.jl:115
 [34] top-level scope at /Users/aamzallag/.julia/packages/Juno/n6wyj/src/progress.jl:134
yuehhua commented 2 years ago

Sorry, the example is not fixed. I'll get it done recently.

arnaudmgh commented 2 years ago

Sorry, ignore the second comment about no method matching zero(::Type{Any}):

I forgot to mention that I was working with an older version of Julia (1.5). When I tried the Flux tutorial with the Iris dataset I got the same error. But after upgrading to 1.7, the error was gone. So I believe this is a Flux problem when using Julia 1.5 with a recent tutorial.

yuehhua commented 2 years ago

@arnaudmgh You can try new version with julia v1.7, and there are two examples about GCN model. https://fluxml.ai/GeometricFlux.jl/dev/tutorials/semisupervised_gcn/