Unused output of node type leads to index error in Zygote

Open
#731 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@lenianiva is already working on this.

Since Nov 7, 2026.

  • #1740 by @lenianiva — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
julia

Research direction

Start with the failing MWE in the issue and trace the GATConv call through src/layers/conv.jl and src/layers/heteroconv.jl, then inspect the reported gat_conv location in GNNlib. Reproduce the Zygote gradient error with the unused node type C and check the related tests. Done means the gradient completes without a bounds error; an open linked pull request already addresses this issue.

Written by the indexing model from the issue text.

Description

MWE:

using GraphNeuralNetworks, Flux

g = GNNHeteroGraph(
    Dict(
        (:A, :a, :B) => ([1, 2], [3, 4]),
        (:B, :a, :A) => ([1], [2]),
        (:A, :a, :C) => ([1], [1]),
    );
    num_nodes = Dict(:A => 3, :B => 5, :C => 2),
)
layer = HeteroGraphConv([et => GATConv(2 => 2) for et in keys(g.edata)])
x = (A = rand(Float32, 2, 3), B = rand(Float32, 2, 5), C = rand(Float32, 2, 2))

Flux.gradient(x) do x
    y = layer(g, x)
    sum(y[:A]) + sum(y[:B])
end

Error

ERROR: LoadError: BoundsError: attempt to access Tuple{Nothing, ChainRulesCore.ZeroTangent, ChainRulesCore.ZeroTangent} at index [4]
Stacktrace:
  [1] getindex
    @ ./tuple.jl:33 [inlined]
  [2] gradindex(x::Tuple{Nothing, ChainRulesCore.ZeroTangent, ChainRulesCore.ZeroTangent}, i::Int64)
    @ Zygote ~/.julia/packages/Zygote/5O3tb/src/compiler/reverse.jl:24
  [3] gat_conv
    @ ~/.julia/packages/GNNlib/sAfhh/src/layers/conv.jl:154 [inlined]
  [4] (::Zygote.Pullback{Tuple{typeof(gat_conv), GATConv{Dense{typeof(identity), Matrix{Float32}, Bool}, Nothing, Float64, Float32, Matrix{Float32}, typeof(identity), Vector{Float32}}, GNNHeteroGraph{Tuple{Vector{Int64}, Vector{Int64}, Nothing}}, Tuple{Matrix{Float32}, Matrix{Float32}}, Nothing}, Any})(Δ::ChainRulesCore.ZeroTangent)
    @ Zygote ~/.julia/packages/Zygote/5O3tb/src/compiler/interface2.jl:0
  [5] GATConv (repeats 2 times)
    @ ~/.julia/packages/GraphNeuralNetworks/C8IDs/src/layers/conv.jl:346 [inlined]
  [6] forw
    @ ~/.julia/packages/GraphNeuralNetworks/C8IDs/src/layers/heteroconv.jl:63 [inlined]
Dominant language
Julia
Stars
310
Forks
75
Avg merge
2d 15h
Merged PRs (30d)
10

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaGraphs/GraphNeuralNetworks.jl

All issues in JuliaGraphs/GraphNeuralNetworks.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.