Graph Isomorphism Networks (GIN) Explained: How They Work in Practice

Graph isomorphism network (GIN): how injective sum aggregation matches the 1-WL test, its limits, GINE edge features, PyG code and molecular use.

Graph Isomorphism Networks (GIN) Explained: How They Work in Practice
Written by TechnoLynx Published on 11 Jul 2026

A graph isomorphism network (GIN) is a message-passing graph neural network. Each layer updates a node by passing (1+ε) times the node’s own state, plus the plain sum of its neighbours’ states, through a multi-layer perceptron (MLP). Xu, Hu, Leskovec and Jegelka introduced it at ICLR 2019 in “How Powerful are Graph Neural Networks?”. They proved it is the most expressive architecture among neighbourhood-aggregation GNNs and as powerful as the Weisfeiler-Lehman graph isomorphism test. That result cuts both ways. GIN is the best a message-passing GNN can do, and it shares the 1-WL test’s shortcomings.

How a graph isomorphism network updates a node

The GIN layer is short enough to read in one line:

h_v^(k) = MLP^(k)( (1 + ε^(k)) · h_v^(k−1) + Σ_{u ∈ N(v)} h_u^(k−1) )

The layer has three parts, and each one has a job. The sum over neighbours treats the neighbourhood as a multiset, so a node with three identical neighbours gets a different aggregate from a node with one. The MLP then realises a universal function approximator on multisets. When the input features are one-hot encodings, the first layer needs no MLP before the summation, because summing one-hot vectors is already injective.

The mean aggregator used by GCN is not an injective multiset function, which limits GCN’s expressive power.

Why is GIN as powerful as the Weisfeiler-Lehman test, and what does that buy you?

GIN reaches 1-WL power by approximating injective set functions with MLPs, the role the injective hash plays in the 1-WL test. The Weisfeiler-Lehman algorithm is a classical isomorphism test based on colour refinement. Each node keeps a colour that is refined in each iteration by aggregating its neighbours’ colours, and the refinement stabilises after a few iterations. To compute the update, WL uses an injective hash, so two nodes get the same new colour only if their inputs were identical.

GIN replaces that hash with MLPs that approximate injective set functions, which is how it gets to 1-WL power. If every layer’s function is injective, WL expressivity is reached, as Xu et al. argued. Xu et al. also showed that no other neighbourhood-aggregating (message-passing) GNN can be more powerful than 1-WL. Later work restates the same bound: MPNNs match 1-WL when their functions are injective, and GIN sits at that level. GNNs have the same expressiveness as 1-WL for distinguishing non-isomorphic (sub)graphs, and so they share its shortcomings.

What the bound means when you train one

The theorem is a ceiling. Three practical points follow from that.

First, WL power depends on the layer functions being injective. The inputs a GIN layer must map to distinct outputs correspond one-to-one with unfolding trees, and as depth grows, so do the number of unfolding trees and the discriminative work asked of GIN’s MLPs.

Second, depth sets the radius. At layer l, a node’s embedding can at best represent a breadth-first-search tree of depth l rooted at that node.

Third, the bound limits what the model can learn as well as which graphs it can separate. Chen et al. showed that a GNN class’s ability to separate non-isomorphic graphs is equivalent to its ability to approximate invariant functions.

Regular graphs and rings: where the 1-WL ceiling shows up

One known failure is regular graphs. Two regular graphs with the same number of nodes and the same degree cannot be told apart by the WL test, even when they are not isomorphic. Chen et al. made this concrete with Circular Skip Link (CSL) graphs, which are undirected regular graphs with node degree 4. On the task of classifying CSL graphs, GIN did not outperform a naive classifier. The authors called that unsurprising, because WL tests are proven to fail on such pairs and GIN can do no better than WL.

Cycles are the other failure, and they matter for molecular graphs. Practical message-passing networks can fail even at detecting small cycles. The reason comes from the BFS-tree view above. Nodes are anonymous, so a node revisited at a later layer is embedded as if it were a new node. If the input graph contains a cycle, you can always build a different graph that gives the same embedding, which makes cycle detection from a node’s embedding fundamentally impossible. The same 1-WL bound stops MPNNs from recognising basic substructures like cycles. Adding edge features does not remove it: GIN and GINE both remain unable to detect cycles properly, which is a serious limitation for organic-chemistry graphs. More generally, Chen, Chen, Villar and Bruna (2020) proved that MPNNs cannot perform induced-subgraph counting of any substructure with three or more nodes, although they can count star-shaped substructures.

Ways past 1-WL, in brief

There are several ways past the ceiling.

  • k-WL and k-FWL: the k-dimensional tests track the state of k-tuples of nodes rather than single nodes, which gives a hierarchy of stronger tests.
  • Relational pooling with GIN: combining relational pooling (RP) with GIN separates some regular graphs that GIN alone fails on.
  • r-loopy GIN: this variant also collects messages along paths between pairs of neighbours, so it can count cycles up to length r+2. Every r-loopy WL test is strictly more powerful than 1-WL. Its cost scales linearly with edges plus those paths: ZINC12K has 598K edges but only 374K such paths for path lengths 1 to 5.
  • GINE+: a correction to the GIN convolution that lets the network detect small cycles at almost no extra computation or parameters.

How do you handle edge features in a graph isomorphism network?

To handle edge features, use GINE. GINE adds each edge’s features to the neighbour’s state inside the sum, before a nonlinearity. The original GIN was designed for simple graphs where each node has one discrete label and there is no edge information. The classical WL test is likewise not built for edge features a priori, although higher-dimensional versions extend to them easily. On the theory side, Beddar-Wiesing et al. (2022, revised 2024) extended the 1-WL equivalence to attributed graphs with attributes on both nodes and edges. They proved that GNNs keep the same capability as the matching 1-WL test there.

GINE comes from Hu et al.’s “Strategies for Pre-training Graph Neural Networks” (ICLR 2020), and PyTorch Geometric implements it as:

x’i = h_Θ( (1 + ε) · x_i + Σ{j ∈ N(i)} ReLU( x_j + e_{j,i} ) )

The original formulation writes the edge term as an embedding E(e_ij) of the edge’s label, with ε learned and σ a nonlinearity such as ReLU. Because e_{j,i} is added element-wise to x_j, the edge vector must have the same width as the node state. One way to meet that is to encode edge features before the layer. The r-loopy GIN authors, for example, pass node and edge features through an encoder and a linear layer, process edge features with a two-layer learnable MLP inside each layer, and swap GIN for GINE layers.

import torch
from torch import nn
from torch_geometric.nn import GINEConv, global_add_pool

class GINE(nn.Module):
    def __init__(self, node_dim, edge_dim, hidden, out_dim, num_layers=3):
        super().__init__()
        self.node_enc = nn.Linear(node_dim, hidden)
        self.edge_enc = nn.Linear(edge_dim, hidden)  # match node width
        self.convs = nn.ModuleList([
            GINEConv(nn.Sequential(nn.Linear(hidden, hidden), nn.ReLU(),
                                   nn.Linear(hidden, hidden)), train_eps=True)
            for _ in range(num_layers)
        ])
        self.head = nn.Linear(hidden, out_dim)

    def forward(self, x, edge_index, edge_attr, batch):
        x, e = self.node_enc(x), self.edge_enc(edge_attr)
        for conv in self.convs:
            x = conv(x, edge_index, e).relu()
        return self.head(global_add_pool(x, batch))

Implementing a GIN layer in PyTorch Geometric

PyTorch Geometric’s GINConv is the graph isomorphism operator from the Xu et al. paper. It takes the MLP h_Θ as its nn argument and has the equivalent matrix form h_Θ((A + (1+ε)·I)·X). The PyG GIN example, whose default dataset is MUTAG, builds the whole classifier from a few pieces: a stack of GINConv layers, each wrapping its own MLP with train_eps=False, a ReLU after each convolution, global_add_pool as the readout, and a final MLP with dropout 0.5 as the classifier. A condensed version:

from torch_geometric.nn import GINConv, MLP, global_add_pool

class GIN(torch.nn.Module):
    def __init__(self, in_channels, hidden_channels, out_channels, num_layers):
        super().__init__()
        self.convs = torch.nn.ModuleList()
        for _ in range(num_layers):
            mlp = MLP([in_channels, hidden_channels, hidden_channels])
            self.convs.append(GINConv(nn=mlp, train_eps=False))
            in_channels = hidden_channels
        self.mlp = MLP([hidden_channels, hidden_channels, out_channels],
                       norm=None, dropout=0.5)

    def forward(self, x, edge_index, batch):
        for conv in self.convs:
            x = conv(x, edge_index).relu()
        x = global_add_pool(x, batch)
        return self.mlp(x)

The example’s defaults are 5 layers, 32 hidden channels, batch size 128 and a learning rate of 0.01 with Adam. The example sums node embeddings at readout with global_add_pool. The original GIN readout goes one step further: it sums each layer’s node embeddings and concatenates the per-layer sums into the graph embedding. Graph-level readout design is a topic of its own; some molecular work uses mean pooling instead.

Running GIN on a GPU: sparse aggregation and memory

GIN is one of the GNNs that reduce to a sparse matrix multiplication. PyG’s notes on memory-efficient aggregations give GINConv as the example, since MLP((1+ε)·x_i + Σ x_j) equals MLP((1+ε)·X + AX). As a rule of thumb, the sparse-matmul route holds for GNNs whose messages use neither the central node’s features nor multi-dimensional edge features. GINE’s messages depend on e_{j,i}, so by that rule it falls outside the shortcut. A gather-and-scatter implementation of message passing creates a message tensor with one row per edge before it reduces them. Kernel choice, batching and when the GPU actually pays off are covered in our deeper piece on GPU-accelerating graph isomorphism networks.

Where GIN earns its keep: molecular property prediction

A molecule is already a graph. In the Open Graph Benchmark’s ogbg-molhiv and ogbg-molpcba datasets, each graph is a molecule pre-processed with RDKit, with atoms as nodes and chemical bonds as edges. The two datasets are a small and a medium molecular property prediction set adopted from MoleculeNet, and they are among MoleculeNet’s largest. The OGB reference script for these datasets defaults to gin-virtual, a GIN with a virtual node, using 5 message-passing layers, 300-dimensional embeddings, dropout 0.5, batch size 32 and 100 epochs on ogbg-molhiv. Other work follows the same pattern: a 2023 study of bit-flip attacks evaluated the recommended 5-layer GIN with a virtual node on six ogbg-mol datasets.

One multi-task molecular property prediction study used a customised GIN from Hu et al. as its molecule encoder. They chose it because, combined with pre-training, it had reached top results on several molecular property prediction tasks. The GINE+ authors note that data-based predictors can cut prediction time by many orders of magnitude compared with simulation-based methods, and that GNNs have been shown to be particularly effective at the task.

There is a tension here. Biochemistry is mainly the analysis of local structure, including rings, which is exactly what 1-WL-bounded networks struggle to detect. If the property depends on ring membership or ring size, variants built to detect cycles, such as r-loopy GIN or GINE+, address it directly. When a GIN encoder feeds a larger generative pipeline, TechnoLynx builds the surrounding system through its Generative & Agentic AI R&D work.

GIN, GINE and the variants past 1-WL at a glance

Variant What changes from GIN Expressiveness, per the source Practical note
GIN (GINConv) Baseline: MLP of (1+ε)·self plus neighbour sum As powerful as 1-WL; fails on same-degree regular graphs such as CSL Reduces to a sparse matrix multiplication
GINE (GINEConv) Adds edge features inside the sum: ReLU(x_j + e_ji) Still cannot properly detect cycles Edge width must match node width
GIN with virtual node Adds a virtual node to the graph Gain not stated; without one, convolutions are at most as discriminative as WL OGB molecular baseline default
RP + GIN Relational pooling combined with GIN Separates some regular graphs GIN alone cannot Cost not stated in the source
r-loopy GIN Messages along paths between neighbours Counts cycles up to length r+2; strictly above 1-WL Cost linear in edges plus paths
GINE+ Increases the convolution radius without enlarging the perceptive field Learns to detect small cycles Near-zero added compute and parameters

Check 1-WL equivalence in your data before tuning GIN

When a GIN model plateaus on a graph classification task, the first question to ask is whether the training set contains graphs that are 1-WL equivalent but carry different labels. If such pairs exist, no depth, width or learning rate will let GIN separate them. If they do not exist, the ceiling is not your problem, and the effort belongs in the MLPs, the readout and the features.

Back See Blogs
arrow icon