qitianwu/DIFFormer
The official implementation for ICLR2023 spotlight paper "DIFFormer: Scalable (Graph) Transformers Induced by Energy Constrained Diffusion"
What it solves
Most real-world data comes in messy forms: images, text, sensor readings, or particles in a detector. These are often related to each other in hidden ways, but standard machine-learning models treat each item independently or rely on explicitly given connections (like a graph of friends). DIFFormer is a general-purpose encoder that learns structured representations of items while also discovering and using the hidden relationships between them, even when no explicit graph is provided. It does this efficiently, so it can scale to large graphs with millions of nodes.
How it works
DIFFormer is built on a diffusion process with an energy constraint. At each step, the model estimates the pairwise influence (called attention) between any two items, whether or not they are connected in an input graph. It then updates each item's embedding by propagating features from other items according to those influences. The whole process minimizes a global energy function, guiding the model toward stable, meaningful representations.
The model comes in two variants: DIFFormer-s and DIFFormer-a. DIFFormer-s uses a simple kernel that makes the attention computation linear (O(N) complexity), meaning it can process huge datasets quickly. DIFFormer-a uses a sigmoid kernel with quadratic complexity (O(N^2)), which is more expressive but slower. Both variants are implemented in the codebase.
A DIFFormer layer combines three components: global attention (the key idea), graph convolution (to use explicit graph structure when available), and a residual connection (to help training). You can choose to use the model with or without a graph structure, and you can feed it single graphs, batches of instances, or batches of disconnected graphs.
Who it's for
Researchers and engineers who need to encode structured data into embeddings for downstream tasks like node classification, image/text classification, spatial-temporal prediction, or particle property prediction. The README also suggests using DIFFormer as a general-purpose encoder in larger frameworks for generation, prediction, or decision-making.
Highlights
- Official implementation of the ICLR 2023 spotlight paper, with an extended version accepted to JMLR in 2025.
- Supports linear complexity (DIFFormer-s) for scalability to large graphs like OGBN-Proteins and Pokec.
- Provides two attention variants (simple and sigmoid) to trade off speed and expressiveness.
- Works with or without an explicit graph, on a set of instances, a single graph, or a batch of disjoint graphs.
- Includes code for node classification, image/text classification, spatial-temporal prediction, and particle property prediction.
- Offers pre-trained checkpoints for two large datasets to reproduce results without long training times.
Related
- Project
- Project
- Project
- Project