Abstract
Graph Transformers (GTs) have emerged as powerful tools for capturing long-range dependencies in graph-structured data. However, they often lack the structural inductive biases inherent in traditional Graph Neural Networks (GNNs), leading to "inattentive" models that struggle with depth and structural focus. This paper introduces Gradformer, a novel GT architecture that integrates an exponential decay mask directly into the self-attention mechanism. By multiplying the attention matrix with a structure-derived mask, Gradformer prioritizes local neighborhood information while maintaining global reach. This approach effectively addresses the "structural blind spot" of standard GTs, enabling the training of significantly deeper models and achieving state-of-the-art performance across diverse benchmarks, including social, biological, and chemical datasets.
Introduction
While Graph Transformers (GTs) have revolutionized graph machine learning by capturing long-range dependencies, they suffer from a significant "structural blind spot." Standard self-attention treats every node in a graph as equally reachable, often ignoring the actual edges and distances that define the graph's topology.
Existing solutions usually involve Positional Encodings (PE) (like Laplacian eigenvectors) or Attention Biases (adding a value based on distance). However, these methods often result in models with dense, noisy attention patterns that fail to focus on the most relevant structural features. Furthermore, many GTs struggle with depth; as you add more layers, performance often plateaus or even crashes due to over-smoothing or training instability.
The Gradformer Approach
The core innovation of Gradformer is the Exponential Decay Mask. Instead of just adding a bias, Gradformer multiplies the attention matrix by a mask $M$ derived from the graph's structure.
Methods
- Exponential Decay: The mask value for a pair of nodes $(v_i, v_j)$ is calculated as $\lambda^{\psi(v_i, v_j)}$, where $\psi$ is the shortest path distance and $\lambda$ is a decay factor. As distance increases, the attention weight "fades" exponentially.
- Learnable Constraints ($sp$): The authors introduce a learnable "start point" ($sp$) parameter. The decay only triggers if the distance exceeds $sp$. This allows different attention heads to specialize: some heads can learn to stay strictly local (small $sp$), while others can attend to the whole graph (large $sp$).
- Unified Framework: Gradformer is a generalization of both GNNs (which are purely local) and vanilla Transformers (which are purely global). By tuning the decay, the model finds the optimal balance between the two.
Structural Bias and Attention Patterns
Unlike additive biases, multiplicative masks can effectively "zero out" or significantly dampen redundant information from distant nodes. This leads to much cleaner attention patterns that are better aligned with the graph's underlying structure.
Key Results and Insights
- State-of-the-Art Performance: Gradformer outperformed 14 baseline models (including GraphGPS, Graphormer, and SAN) on 5 out of 8 primary datasets. It showed particularly strong improvements on smaller datasets like NCI1 and PROTEINS (+2.13% and +2.28% respectively).
- Solving the "Deep GT" Problem: Most GTs see a performance cliff when moving from shallow to deep architectures. Gradformer remains stable or even improves with depth. For example, on the CLUSTER dataset, Gradformer improved from 77.78% (12 layers) to 78.55% (48 layers), whereas the baseline GraphGPS crashed from 78.06% to 70.91%.
- Head Diversity: By making the decay parameters learnable, the model automatically discovers a mix of "local experts" and "global observers" necessary to understand complex graph data.
- Efficiency: The decay mask adds negligible computational overhead compared to standard $O(n^2)$ self-attention, as it only requires a pointwise multiplication.
Conclusion
Gradformer demonstrates that "baking" structural inductive biases directly into the attention mechanism via multiplicative masking is a powerful strategy for graph representation learning. By balancing local and global information through learnable exponential decay, Gradformer not only achieves superior accuracy but also overcomes the depth limitations that have long hindered the scaling of Graph Transformers.
Summary updated