Flatten Graphs as Sequences: Transformers are Scalable Graph Generators

Dexiong Chen, Markus Krimmel, Karsten Borgwardt

Introduction

Generating complex, structured data such as molecular graphs, social networks, and protein structures remains one of the most significant challenges in machine learning. Historically, the field has been divided between two primary paradigms: diffusion-based models and autoregressive models. While diffusion models are effective at capturing global structure, they often suffer from quadratic complexity ($O(N^2)$) relative to the number of nodes, leading to slow inference and high memory demands. Conversely, existing autoregressive models often rely on specialized architectures that fail to leverage the scaling laws and architectural breakthroughs seen in Large Language Models (LLMs).

This paper introduces AUTOGRAPH, an autoregressive framework that bridges this gap by treating graph generation as a language modeling task. By flattening graphs into sequences using a novel traversal method, AUTOGRAPH achieves state-of-the-art performance while being 100x faster at inference and 3x faster at training than leading diffusion-based models.

The Representation Gap and SENT Traversal

The primary obstacle in applying Transformers to graphs is the "representation gap": the lack of a mathematically robust method to linearize a graph into a sequence of tokens that preserves local structure and scales linearly with the number of edges. To solve this, the authors propose Segmented Eulerian Neighborhood Trails (SENT).

Unlike simple random walks, a SENT ensures that every edge in the graph is visited exactly once. The method allows for "segments" (breaks) to accommodate disconnected components or complex topologies. Crucially, the authors prove that any prefix of a SENT sequence represents an induced subgraph. This creates a direct mathematical link between sub-sequences in language and sub-structures in graphs, allowing the model to learn the incremental construction of valid topologies.

Architecture and Tokenization

AUTOGRAPH converts graphs into sequences of node indices and special tokens. To ensure the model learns structural patterns rather than arbitrary labels, nodes are reindexed based on their first appearance in the traversal. The tokenization scheme includes:

  • Node Indices: Representing the nodes being connected.
  • Segment Breaks (/): To handle disjoint components.
  • Neighborhood Sets (< >): To denote specific connectivity patterns.

Because the graph is represented as a linear sequence, the authors utilize a standard, decoder-only Transformer backbone (specifically a LLaMA-style architecture). This allows the model to scale efficiently, as the sequence length is proportional to the number of edges ($O(m)$), making it inherently more suitable for the sparse graphs common in real-world applications.

Experimental Results

The researchers evaluated AUTOGRAPH across a diverse range of benchmarks, including synthetic planar graphs, protein contact maps, point clouds, and molecular datasets (QM9, MOSES, and GuacaMol).

Performance and Speed

AUTOGRAPH demonstrated significant advantages over DiGress, a leading diffusion model:

  • Inference Speed: AUTOGRAPH is approximately 100x faster during generation.
  • Training Efficiency: The model is 3x faster to train.
  • Structural Accuracy: It achieved state-of-the-art (SOTA) results on Proteins and Point Clouds datasets based on Maximum Mean Discrepancy (MMD) ratios, indicating a high degree of distributional similarity between generated and real-world graphs.

Pre-training and Transfer Learning

The authors introduced a new pre-training dataset generated via the NetworkX library, containing various graph types (Classic, Lattice, Small-world). Results on the GuacaMol dataset showed that pre-training on general graphs significantly improves molecular validity, suggesting that the model learns a generalized "grammar" of graph structure that transfers across domains.

Key Insights: Graphs as Dialects

A central takeaway of this research is that graph generation does not strictly require graph-specific architectures. If a graph is linearized correctly using SENT, the structural dependencies mirror linguistic dependencies closely enough that a standard LLM can "speak" the language of graphs. This enables unique capabilities such as Zero-Shot Motif Scaffolding, where the model is "prompted" with a specific chemical motif (e.g., a specific ring structure) and naturally completes the molecule around it without specialized fine-tuning.

Limitations and Future Directions

Despite its success, the authors identify several areas for future work:

  1. Dataset Scale: Graph generation lacks the trillion-token datasets available to natural language models. Building a true "Graph Foundation Model" will require significantly larger, curated datasets.
  2. Evaluation Metrics: Current metrics like MMD can be sensitive to hyperparameters; more robust benchmarks are needed to evaluate the "reasoning" and functional utility of generated graphs.
  3. Continuous Attributes: While AUTOGRAPH handles categorical attributes effectively, extending the framework to continuous or high-dimensional node features remains an open challenge.

Conclusion

AUTOGRAPH demonstrates that by flattening graphs into sequences, we can leverage the power of Transformers to create highly scalable and efficient graph generators. By achieving SOTA performance with linear scaling, it paves the way for a new generation of foundation models for structural data.

Summary updated

BibTeX
@inproceedings{chen2025flatten,
  author = {Dexiong Chen and Markus Krimmel and Karsten Borgwardt},
  title = {{Flatten Graphs as Sequences: Transformers are Scalable Graph Generators}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=eszmES7j1F},
}
Figure