Skip to content

Support compiling GNNLux models with Reactant - #730

Draft
simsurace wants to merge 4 commits into
masterfrom
gnnlux-reactant
Draft

simsurace wants to merge 4 commits into
masterfrom
gnnlux-reactant

Conversation

@simsurace

@simsurace simsurace commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Builds on #726, which made graphs traceable and GCNConv compilable with Reactant. This PR extends that to batched graphs, pooling, attention, gradients and training, and ports the GNNLux tutorials to Reactant and Enzyme, the standard Lux workflow. Follows up on #655.

Changes

GNNlib

  • reduce_nodes, reduce_edges, softmax_nodes, softmax_edges and softmax_edge_neighbors now scatter into an output of explicit size (the number of graphs, or of nodes) instead of inferring it from the largest index. Reactant can't infer the size when the graph is traced, so this makes GlobalPool and the attention layers compile. It also fixes batched graphs whose trailing graphs have no nodes: they now get their output columns.

GNNGraphs

  • New pad_graph(g, num_nodes, num_edges, num_graphs), modelled on jraph's pad_with_graphs. It pads a graph to fixed numbers of nodes, edges and graphs, putting the padding in extra graphs. Padding every mini-batch to the same size lets Reactant compile a model or training step once and reuse it for all batches.
  • New graph_sizes field on GNNGraph: the number of nodes in each graph of a batch, nothing for a single graph. It duplicates graph_indicator, but its length is the number of graphs, so the graph count becomes part of the array shapes a compiled function checks. Without it, a compiled model called on a batch padded to a different number of graphs (with the same node and edge totals) silently returned output for the old number of graphs. Now it raises RuntimeProgramInputMismatch, like a node or edge mismatch. The positional constructor derives it from graph_indicator, and transformations that keep the graph indicator pass it through.

GNNLux tutorials

Tests

  • GNNLux gets Reactant tests in its main test suite: forward passes on single and batched graphs, Enzyme gradients and training inside a compiled program, and padded mini-batches, including the error for graphs of a different size.
  • GNNGraphs tests for pad_graph and graph_sizes, on CPU and GPU.

The root docs project leaves the workspace: MultiDocumenter pins JSON 0.21, which holds Reactant at 0.2.217, a version that does not build on Julia 1.13.

Changelog entries

Per the changelog policy, these are for carrying over:

GNNGraphs.jl 1.7.0-DEV

  • Added pad_graph, which pads a graph to given numbers of nodes, edges and graphs, putting the padding in extra graphs. Padding every mini-batch to the same size lets Reactant.jl compile a model or a training step once and reuse it for all batches ([Support compiling GNNLux models with Reactant #730]).
  • Added the graph_sizes field to GNNGraph, holding the number of nodes in each graph of a batch (nothing for a single graph). Its length is the number of graphs, so a model compiled with Reactant.jl raises an error when called on a batch with a different number of graphs, instead of silently returning wrong results ([Support compiling GNNLux models with Reactant #730]).

GNNlib.jl 1.5.0-DEV

  • reduce_nodes, reduce_edges, softmax_nodes, softmax_edges and softmax_edge_neighbors now scatter into an output of explicit size (the number of graphs, or of nodes) instead of inferring it from the largest index. This makes GlobalPool and the attention layers compile with Reactant.jl, and returns the correct number of columns for batched graphs whose trailing graphs have no nodes ([Support compiling GNNLux models with Reactant #730]).

Version bumps are already on master from #726 (GNNGraphs 1.7.0-DEV, GNNlib 1.5.0-DEV).

🤖 Generated with Claude Code

simsurace added a commit that referenced this pull request Nov 5, 2026
@simsurace
simsurace marked this pull request as draft November 5, 2026 16:40
@CarloLucibello

Copy link
Copy Markdown
Member

need rebase now that #726 is merged

simsurace and others added 4 commits November 29, 2026 23:53
reduce_nodes, reduce_edges and the graph-wise softmaxes inferred their
output size from the largest index, which Reactant cannot do when the
graph is traced. They now scatter into an output of explicit size (the
number of graphs, or of nodes). This makes GlobalPool and the attention
layers compile, and gives batched graphs whose trailing graphs have no
nodes the right number of output columns.

GNNLux gets tests for the forward pass under Reactant and for Enzyme
gradients and training inside a compiled program.

The root `docs` project leaves the workspace: MultiDocumenter pins JSON
0.21, which holds Reactant at 0.2.217, a version that does not build on
Julia 1.13.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Train the tutorials with `Training.single_train_step!(AutoEnzyme(), ...)`
on a `reactant_device()`, as Lux recommends, instead of Zygote, and
regenerate their pages.
…torial

pad_graph pads a graph to fixed numbers of nodes, edges and graphs, so
Reactant can compile a model or training step once and reuse it for every
mini-batch. The graph classification tutorial goes back to master's
mini-batch training, padding each batch and masking the padding graphs out
of the loss.
graph_sizes holds the number of nodes in each graph of a batch. It
duplicates graph_indicator, but its length is the number of graphs, which
makes that number part of the array shapes a compiled Reactant function
checks. A compiled model called on a batch with a different number of
graphs now raises an error instead of silently returning wrong results.

The positional constructor derives graph_sizes from graph_indicator, and
transformations that keep the graph indicator pass graph_sizes through.
@simsurace

Copy link
Copy Markdown
Member Author

I will return to this shortly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants