Todyformer: Towards Holistic Dynamic Graph Transformers with Structure-Aware Tokenization

Mahdi Biparva, Raika Karimi, Faezeh Faez, Yingxue Zhang

Dynamic graphs—where nodes and edges evolve over time—are everywhere, from social networks to financial transactions. However, modeling them effectively is a notorious challenge. Traditional Message-Passing Neural Networks (MPNNs) are great at capturing local structure but stumble over long-range dependencies due to "over-smoothing" (where node features become indistinguishable) and "over-squashing" (information bottlenecks). Transformers, the darlings of NLP, excel at long-range sequences but often ignore the inherent structural nuances of graphs and can be computationally ruinous.

Enter Todyformer, a novel architecture that seeks a "holistic" middle ground by combining the structural inductive biases of MPNNs with the temporal reasoning of Transformers.

TL;DR

Todyformer is a hybrid Transformer-based model for dynamic graphs that uses a "patch-and-tokenize" strategy to unify local structural encoding with global temporal modeling. By alternating between MPNN-based local encoders and Transformer-based global encoders, it achieves state-of-the-art results on link prediction and node classification while remaining significantly faster than complex random-walk-based competitors.

What Problem Does This Paper Address?

The authors target two primary bottlenecks in dynamic graph representation learning:

  1. Over-smoothing and Over-squashing: In standard MPNNs, as you add layers to capture distant neighbors, node representations tend to converge to a uniform, uninformative state. Furthermore, trying to squeeze a massive neighborhood's information into a single vector creates a bottleneck (over-squashing).
  2. Computational Inefficiency: Many state-of-the-art dynamic graph models rely on expensive memory modules or complex random-walk algorithms (like CAW) that don't scale well to graphs with millions of edges.

Todyformer aims to solve these by treating the dynamic graph not just as a sequence of events, but as a series of structural "patches" that can be processed efficiently in parallel and then reasoned over globally.

Methods

The Todyformer architecture follows a sophisticated four-stage pipeline:

  1. Temporal Patching: The input dynamic graph is partitioned into $M$ non-overlapping temporal subgraphs (patches) based on edge timestamps. This reduces the "neighborhood explosion" problem by limiting the scope of local message passing.
  2. Structure-Aware Tokenization (Local Encoding): Within each patch, a dynamic GNN (specifically DyG2Vec) acts as a tokenizer. It encodes the local structural and temporal patterns of nodes into latent embeddings.
  3. Node Packing: This is the bridge to the Transformer. Since a node might appear in multiple patches, the "Packer" module collects a node's embeddings across all $M$ patches and arranges them into a sequence. This transforms the graph data into a format a standard Transformer can digest.
  4. Global Encoding: A Transformer with temporal positional encoding processes these node-specific sequences. It learns how a node's local structural role evolves over the entire time horizon.
Figure 1: Illustration of Todyformer encoding-decoding architecture.

Crucially, Todyformer uses an alternating architecture. It stacks these local and global modules, allowing the model to capture multi-scale dependencies. For example, a 3-layer Todyformer can effectively reach patterns up to 9 hops away.

Figure 2: Schematic depiction of the computation flow in the local and global encoding modules, particularly highlighting node packing and unpacking modules in Todyformer.

Datasets

The model was evaluated on a wide array of benchmarks:

  • Standard Dynamic Graph Datasets: MOOC, LastFM, Enron, UCI, SocialEvolution, Wikipedia, and Reddit.
  • Temporal Graph Benchmark (TGBL): A newer, more challenging suite including Wiki, Review, Coin, Comment, and Flight. These datasets are significantly larger (up to 67 million edges) and include more rigorous negative sampling to test model robustness.

Key Insights and Ideas

  • Hybridization is Key: The authors demonstrate that you don't have to choose between GNNs and Transformers. Using GNNs as "tokenizers" provides the necessary structural context that vanilla Transformers lack.
  • Patching as a Regularizer: Dividing the graph into patches naturally mitigates over-squashing because the message-passing is confined to smaller, manageable contexts.
  • Efficiency via Structure: By avoiding computationally expensive random walks and instead using a structured patch-based approach, Todyformer achieves better performance than models like CAW while being much faster during inference.
  • Temporal Order Matters: The ablation studies show that "Patch Index" positional encoding yields the best results, proving that the global temporal sequence of patches is vital for accurate predictions.

Key Results

Todyformer consistently outperformed state-of-the-art (SoTA) models across almost all benchmarks:

  • Future Link Prediction: On standard datasets, it beat the second-best models by margins up to 1.6% in Average Precision (AP).
  • Large-Scale Scaling: On the extra-large TGBL datasets, the gains were even more dramatic, outperforming previous SoTA by 11% on Coin, 39% on Comment, and 7% on Flight.
  • Inference Speed: Todyformer maintains a competitive edge in speed, proving to be lighter and less complex than CAW across all tested datasets.
Table 1: Future Link Prediction performance in AP (Mean ± Std) on the test set.

Limitations and Future Work

While Todyformer is a significant step forward, the authors note a few areas for growth:

  • Global Structural Encoding: The current global encoder is primarily temporal. Incorporating global structural information (beyond the local patch structure) is a suggested direction for future research.
  • Hyperparameter Sensitivity: The model has many moving parts (window size, number of patches, etc.). While the paper provides a sensitivity analysis, finding the optimal configuration for a new dataset may require extensive tuning.
  • Task Specificity: The current decoder is optimized for node-level and link-level tasks; extending this to graph-level classification remains unexplored.

Summary updated

BibTeX
@article{biparva2024todyformer,
  author = {Mahdi Biparva and Raika Karimi and Faezeh Faez and Yingxue Zhang},
  title = {{Todyformer: Towards Holistic Dynamic Graph Transformers with Structure-Aware Tokenization}},
  journal = {Accepted by TMLR},
  year = {2024},
  url = {https://openreview.net/forum?id=nAQSUqEspb},
}
Figure