Beyond Flat Walks:
Compositional Abstraction for Autoregressive Graph Generation

Kaiwen Bian * 1,2 Andrew H. Yang * 1 Ali Parviz 1 Gal Mishne † 1 Yusu Wang † 1
1 University of California San Diego 2 Salk Institute for Biological Studies
* Equal contribution  ·  † Equal advising
Fortieth Conference on Neural Information Processing Systems (NeurIPS 2026), Main Track
Paper (coming soon) Code Hugging Face (coming soon) Citation

Abstract

Autoregressive graph generators typically linearize graphs through flat node-edge walks, which can obscure higher-order structure in large, complex graphs. We introduce a hierarchical graph abstraction and coarse-to-fine generation pipeline that separates coarsening, tokenization, and decoding. This exposes three design axes: community coarsening, hierarchical tokenization, and order randomization. Across these axes, traversal-based hierarchy consistently improves distributional and structural fidelity, while its V.U.N. cost depends strongly on the coarsening and randomization policy. In particular, the fidelity–V.U.N. trade-off observed under within-community randomization is substantially reduced when traversal order is randomized across the full hierarchy. With a fixed backbone, training recipe, and matched training time across five molecular and four non-molecular benchmarks, hierarchical serialization yields consistent distributional and structural gains on all molecular datasets, while the non-molecular results show that these gains depend on how well the supplied hierarchy aligns with structure in the target distribution. Together, these results characterize when and how hierarchical serialization benefits autoregressive graph generation.

A flat walk hides the structure a graph is built from

To generate graphs with a language model, you first have to write a graph down as a sentence. The standard sentence is a flat walk: start at a node, step from neighbor to neighbor, and whenever the walk returns to a node it has already written, record a bracket of back-edges. This is lossless and efficient, and on small molecules it works well. But nothing in the walk knows what a ring, a functional group, or a community is. That structure is left implicit in the token stream, and the model has to rediscover it on its own.

We ask whether the sentence itself can carry the structure. Everything else is held fixed: the same causal transformer, the same training recipe, and matched training time. Only the way the graph is written down changes. The figure below plays the two serializations of one molecule side by side.

Figure 1. One molecule, two sentences.

The flat SENT walk and the hierarchical HDT traversal of the same molecule, played in lockstep from the actual tokenizer output (atom- and bond-type tokens omitted). In both panels atoms take the color of their Motif-Community community, and the bar under each panel lists the community of each emitted atom in order. The walk weaves between ring systems, so communities are interleaved throughout the sequence. HDT finishes each community before opening the next, so they arrive as contiguous blocks, announced by an [ENTER] token. Hover an atom to find it in both tapes.

The intuition is coarse before fine. Every hierarchical tokenizer we study emits the higher-level community structure before the atom-level detail inside it, so when the model has to place an atom, it has already written which community that atom belongs to. A fine-to-coarse order would defeat the purpose: the model would have to commit to local structure before seeing the organization meant to guide it. The cost is length. Writing the hierarchy down takes tokens, and HDT sequences are roughly twice as long as SENT’s, which is why every comparison in the paper matches wall-clock training time rather than steps or epochs.

The pipeline: coarsen, serialize, predict, decode

The framework splits generation into stages that can be studied separately. Coarsening builds a partition tree H\mathcal{H} from the input graph G. Tokenization serializes H\mathcal{H} into a flat sequence in coarse-before-fine order. A standard causal transformer learns that sequence by next-token prediction, and decoding inverts the tokenization exactly, so any syntactically valid sample becomes a graph. All of our contributions concern the serialization; the model is an ordinary GPT-2.

interactive
ENCODE (EVERY TRAINING GRAPH)GENERATEtrainGraph Gatoms + bondsCoarsenHAC · Motif CommunityPartition tree ℋcommunities, τ = 4HDT serializerone DFS over ℋTokens tcoarse before fineCausal transformerGPT-2 XS · next tokenSampled tokenst ∼ pθ(·)Decoderexact inverseGenerated graph Ĝdecode ∘ tokenize ∘ coarsen(G) ≅ G
Coarsen, serialize, predict, decode

A graph is coarsened into a partition tree ℋ, ℋ is serialized into one flat token sequence that states the community structure before the atom-level detail inside it, and an ordinary causal transformer learns that sequence by next-token prediction.

Generation runs the transformer and parses its output back into a graph. Every stage except the transformer is a fixed, lossless transformation, so all differences between methods come from how the graph is presented to the model.

Figure 2. The coarse-to-fine pipeline, stage by stage.

Pick a tab to light up the modules active in each stage. The panels run on real outputs: camptothecin under Motif-Community coarsening (the paper’s Figure 1; the HDT tape here is token for token the one in the figure), and for decoding, the novel COCONUT HDT-MC sample of the paper’s Figure 2. In “Serialize”, the highlighted line of Algorithm 1 follows the token being written, the partition tree marks the open communities, and every bond appears as an orange back-edge arc under the leaves once it has been written. In “Learn”, the causal mask shows which tokens are visible (input) when predicting the next one (target).

Decoding is exact for the encoder–decoder pair: decode ∘ tokenize ∘ coarsen(G) ≅ G, because the partition covers every node and each edge is written exactly once. That is a property of the tokenizer, not a promise about samples: a generated sequence may be malformed, and then it is counted as invalid rather than repaired. Validity is measured for every method, including the flat baseline.

Three design axes

Separating the stages exposes three independent choices: how the graph is coarsened, how the hierarchy is written into tokens, and how the traversal order is randomized during training. The figures and table below run each axis on real molecules.

How the graph is coarsened

We use one domain-agnostic strategy everywhere and one chemistry-aware strategy on molecules. HAC, hierarchical agglomerative clustering with an adjacency constraint, merges clusters bottom-up only when they share an edge, yielding tight communities of controlled size for any graph. Motif Community (MC) detects ring systems with SMARTS queries, merges overlapping rings, and absorbs leftover atoms where it can. Recursion continues until communities fall below a small threshold (τ = 4), so H\mathcal{H} is shallow on drug-like molecules (mean depth 1.13 on MOSES) and deeper on large ones (1.86 on Macrocycle).

Figure 3. Where the communities come from.

Each molecule under the three coarsenings used in the paper, computed by the repository’s coarseners. Communities are pulled slightly apart; dashed bonds cross top-level communities and dashed outlines mark nested sub-communities. The icicle shows the partition tree H\mathcal{H} level by level. HAC communities need not be recognizable motifs; MC’s granularity depends on the motifs present; HDTC’s MC+FG partition additionally labels every community as ring, functional group or singleton.

How the hierarchy is written into tokens

Given H\mathcal{H}, the question is how explicit the hierarchy should be in the token stream. HSENT declares it: a catalogue of community blocks followed by a separate bipartite section that wires them together. HDTC is a typed variant for molecules that labels each block and appends a super-graph of inter-community bonds. HDT, the tokenizer we use throughout, traverses it: one depth-first pass in which cross-community bonds are ordinary back-edges, syntactically identical to bonds inside a community.

Table 1. Tokenizer characteristics. n, m, c, k are nodes, edges, cross-community edges and top-level communities; length ratios are means over the molecular benchmarks.
TokenizerHierarchyCoarseningCross-community edgesToken costLength vs SENT
SENTflat (single walk)not usedN/AO(n + m)1×
HSENTdeclarative (catalog + wiring)anyexplicit bipartite block (i, j)O(n + m + c + k²)∼3×
HDTtraversal-based (DFS of H\mathcal{H})anyDFS back-edges (implicit)O(n + m)∼2×
HDTCtraversal-based, typed blocks (R/F/S)MC+FG onlyexplicit super-graph tupleO(n + m + c)∼2×

Declaring the hierarchy did not pay off. On GuacaMol and MOSES, both HSENT configurations have lower validity and V.U.N. and higher MoleculePGD than the corresponding HDT configurations, and HDTC trails HDT on the same metrics, while HSENT sequences run about 2.9× SENT’s length against 1.9× for HDT. One plausible reading: a declarative grammar poses a second prediction problem. A sample can declare a set of communities and then wire them in a way that contradicts the declaration. In HDT there is no separate wiring record to contradict; community membership lives entirely in the [ENTER] / [EXIT] nesting.

How the order is randomized

A graph admits many valid serializations, and resampling the traversal at every training presentation is free data augmentation. A flat random walk gets this for free: SENT draws a new walk each epoch. A deterministic traversal shows the model one string per graph. We compare two policies that keep the graph and H\mathcal{H} fixed. Within-community randomization (-R) keeps the stored community order and randomizes the traversal inside each terminal community. Hierarchy-wide randomization (-FR) also samples an adjacency-constrained DFS over communities at every level, entering each community through an atom adjacent to the one it was reached from.

Figure 4. One graph, many sentences.

Resample to draw another serialization of the same molecule under each policy; all samples are produced by the repository’s HDT tokenizer with the corresponding policy. Node labels are serialization ids, assigned in first-visit order. Under -R the community entry order (colored row) never changes; under -FR it does, subject to adjacency.

Hierarchy improves distributional fidelity on every molecular benchmark

We train the same GPT-2 XS backbone (≈ 11M parameters) on five molecular benchmarks (GuacaMol, MOSES, COCONUT 2.0, a disjoint split of GEOM-Drugs, and Macrocycle) with one training recipe and matched training time, and compare the flat baseline with the two hierarchical configurations fixed in advance, HDT-HAC-R and HDT-HAC-FR.

SENTHDT-HAC-RHDT-HAC-FRlower is better
0123GuacaMolMOSESCOCONUT 2.0GEOM-DrugsMacrocycle
Figure 5. Unconditional generation across the five molecular benchmarks.

The paper’s Table 3 and Figure 3. Means over generation seeds 42–44 from one checkpoint per model; hover a dataset for values. “Change vs SENT” is signed so that positive is better. Standard deviations, the remaining variants (HDT-MC-R, HDT-MC-FR), the training-sample reference and the novel-only protocol are in the paper’s Appendix A.10 and A.12.

The gap is largest, and most consistent, on the metrics that compare distributions rather than count successes. Against SENT, HDT-HAC-R lowers FCD by 51.6% to 64.6% and MoleculePGD by 34.3% to 86.6% on all five benchmarks, and improves SNN, fragment similarity and scaffold similarity on all five as well. The margins are large relative to the seed spread: on GuacaMol, FCD falls from 1.799 ± 0.045 to 0.871 ± 0.019, and on Macrocycle, MoleculePGD falls from 0.639 ± 0.003 to 0.085 ± 0.002. All four hierarchical configurations have lower FCD and MoleculePGD than SENT on every benchmark, and the improvements persist when metrics are recomputed only on novel molecules, so they are not explained by reproducing training molecules. SENT keeps a slightly higher internal diversity on all five benchmarks, by less than 0.02.

Randomizing across the hierarchy closes most of the V.U.N. gap

Fidelity is not the whole story. Switch the chart above to V.U.N. (the fraction of samples that are valid, unique and novel). With within-community randomization, HDT-HAC-R trails SENT by 3.6% on GuacaMol, 4.0% on MOSES, 17.0% on COCONUT 2.0 and 37.2% on Macrocycle, where novelty falls from SENT’s 0.999 to 0.658: the model reproduces training molecules more often.

Randomizing the traversal across the whole hierarchy largely removes this cost. Across the two fully randomized configurations the largest V.U.N. deficit is 10.85%, and for HDT-MC-FR it is 2.98%. HDT-MC-FR still improves FCD, MoleculePGD, SNN and fragment similarity over SENT on all five benchmarks, and has slightly higher mean V.U.N. on GuacaMol. A residual deficit remains on Macrocycle (V.U.N. 0.762 for HDT-HAC-FR against SENT’s 0.854), carried by validity rather than novelty. How the hierarchy is presented during training matters as much as whether it is present.

Beyond molecules: hierarchy helps when it matches the data

The framework only needs a coarsening, so it applies to any graph. On four non-molecular benchmarks, with the same domain-agnostic HAC, the picture is no longer uniform, and that is informative. The figure lets you feel why: turn up the community gravity and see whether the coarsening carves the graph into clean islands or into arbitrary pieces.

community gravity0.55
Hierarchy helps
  • V.U.N. 0.540 (SENT) → 0.879 (HDT-HAC-R, +62.8%) → 0.960 (HDT-HAC-FR)
  • MMD Ratio 10.72 → 1.57; Degree MMD 0.0003, equal to the training-sample reference
  • No chemical catalogue needed: HAC finds the units
Figure 6. One graph from each non-molecular benchmark, with HAC communities.

A live force-directed layout. The gravity slider attracts every node toward the centroid of its community and pushes communities apart; at zero it is a plain spring layout. Proteins is a held-out D&D graph and Planar a held-out SPECTRE graph; the block-model graphs are drawn from each benchmark’s generator law (the SBM draw conditioned on at least three blocks), so their planted blocks are known and can be shown. The cards summarize the paper’s Section 4.4 and Tables 14, 15 and 19.

On Proteins, HDT-HAC-R improves V.U.N. by 62.8% over SENT and reaches the lowest MMD Ratio among the methods in the paper’s literature table, so the benefit does not depend on a chemical catalogue. On Sparse SBM it improves V.U.N. by 59.3% and cuts Degree MMD, Orbit MMD and Ratio by more than 90%. On Planar, where there is no community structure to find, both hierarchical configurations are worse than the flat walk on every graph MMD.

When the hierarchy misleads

The standard SBM is the instructive failure. Default HAC recovers the planted blocks well at the top level, but keeps splitting: communities averaging about 31 nodes are recursively cut into leaves averaging 2.25 nodes. The resulting model reaches validity 0.926, yet its uniqueness and novelty fall to about 0.41 and its V.U.N. is only 0.276, against SENT’s 0.669. High validity alone does not establish successful generation.

Figure 7. Over-refinement on SBM, and two ways out.

One graph drawn from the SBM generator law (conditioned on at least three blocks, for legibility) under the three hierarchies of the paper’s Tables 18–19 (panel A). Leaf communities are colored individually: with τ = 4 the planted blocks shatter into confetti. Raising the stopping threshold to τ = 44 leaves the blocks intact; the planted hierarchy (PH) is a privileged control that supplies the generator’s own memberships during training (generation stays unconditional). Bars give validity, uniqueness, novelty and V.U.N. for -R and -FR; the dashed line is SENT.

Two fixes confirm the diagnosis. Raising the stopping threshold to τ = 44 raises V.U.N. to 0.709 and 0.694 for -R and -FR; the planted hierarchy reaches 0.887 and 0.848. On connected Recursive SBM, HAC with τ = 10 reaches V.U.N.† 0.854 under -R, close to the planted hierarchy’s 0.858, whereas -FR stays far below the planted -FR (0.083 against 0.744). The benefit comes from alignment between the hierarchy and the data, and how much of it survives depends on the randomization policy.

In context

For orientation, here are the controlled runs next to published numbers. Rows marked ∗ are transcribed as published; budgets and evaluation lineages differ, so this is placement rather than a superiority claim. The controlled comparison is the one above.

ModelValid ↑Unique ↑Novel ↑Filters ↑FCD ↓SNN ↑
VAE - SMILES∗97.799.869.599.70.570.58
JT-VAE - FRAGMENTS∗100.0100.099.997.81.000.53
GraphINVENT∗96.499.8n/a95.01.220.54
DiGress∗85.7100.095.097.11.190.52
SENT (GPT2-s)∗87.4100.085.998.60.910.55
SENT (GPT2-xs)97.7100.099.094.20.700.506
HDT-HAC-R (GPT2-xs)97.899.995.098.10.250.583
HDT-HAC-FR (GPT2-xs)98.5100.097.197.50.260.560
Figure 8. Placement within the graph-generation literature.

Paper Table 4, laid out following Chen et al. (2025). Our three GPT2-XS rows share one backbone, recipe and matched training time; ∗ marks numbers transcribed from the original publications.

Generated samples

Numbers summarize distributions; the samples show what they look like. Below are the unconditional-generation samples from the paper for every benchmark: held-out references, the flat SENT baseline, and our two hierarchical configurations, with each model’s headline numbers beside its row.

Figure 9. Unconditional generation galleries.

Samples from the paper’s Appendix A.19 (Figures 7–15), shown for the reference, SENT, HDT-HAC-R and HDT-HAC-FR rows. Each row holds five deterministic samples drawn without replacement; generated rows use the seed-42 evaluation arm of the corresponding model, and the reference row uses the benchmark’s held-out evaluation arm. Numbers beside each row are means over seeds 42–44 from the paper (Table 3 for molecules; Tables 14, 15, 19 and 21 for graphs).

Takeaways

Why it helps

Writing the community structure before the atoms puts the graph’s organization into the prefix the model conditions on. With a fixed model and matched compute, that alone lowers FCD and MoleculePGD on all five molecular benchmarks.

When it helps

When the hierarchy captures structure that is actually present: molecules, proteins, sparse block models. A mismatched coarsening (over-refined SBM) hurts, and with no structure to find (Planar) the benefit disappears.

How to make it help

Traverse the hierarchy rather than declare it (HDT over HSENT / HDTC), randomize the traversal across the whole hierarchy (-FR) to recover V.U.N., and pick a coarsening whose granularity fits the domain.

Limitations

Hierarchy has a computational cost. HDT’s lossless coarse-before-fine encoding lengthens sequences by roughly 2× over SENT on small molecules and more on large graphs, so the same backbone spends roughly 4× the attention memory and compute; at matched training time the hierarchical variants take between a third and two-thirds of SENT’s optimizer updates. The benefit also depends on the coarsening: a coarsening has to be assessed for each domain, and hierarchies do not transfer across datasets. Finally, a residual V.U.N. deficit remains on Macrocycle even with full randomization.

Citation

@inproceedings{bian2026beyond,
title = {{Beyond Flat Walks: Compositional Abstraction for Autoregressive Graph Generation}},
author = {Bian, Kaiwen and Yang, Andrew H. and Parviz, Ali and Mishne, Gal and Wang, Yusu},
booktitle = {Advances in Neural Information Processing Systems},
year = {2026}
}