Manuscript Offprint

arXiv:2610.19625

DAGFormer: Global Topology Prediction for Transformer Cross-Layer Connections

Xiaocong Yang, Yuren Hao, ChengXiang Zhai

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

We propose DAGFormer, a Transformer language model whose cross-layer connections are planned by a jointly trained topology predictor. Beyond the residual connections in a standard Transformer, DAGFormer adds direct connections from earlier layers to later ones, and the predictor controls the strength of every connection based on input tokens. Unlike existing cross-layer routing architectures, which set each layer's connections separately, DAGFormer plans the routing of the whole model at once. On matched OLMo-2 pairs from 75M to 1B parameters, DAGFormer lowers WikiText-2 perplexity by 17% to 25% over the vanilla Transformer, and a 1B DAGFormer trained on 5B tokens outperforms the vanilla model trained on 10B. Against four routing baselines with the same data and budget, it reaches the lowest perplexity at 75M, 300M and 1B. The gain carries over to 13 commonsense, science, reading and math evaluation tasks (2.0 to 2.5 points higher mean accuracy at 300M and 1B) and to instruction finetuning (63% to 70% AlpacaEval win rate against the vanilla Transformer, leading every routing baseline), and under structured pruning DAGFormer degrades the least in five of six settings.

1 Introduction

A Transformer (Vaswani et al., 2017) composes its layers through residual connections (He et al., 2016): every attention head and MLP reads the same running sum and writes back into it. Mechanistic analyses describe this residual stream as the communication channel between model components (Elhage et al., 2021). Its bandwidth is shared by every layer, so which earlier computation a layer can read is fixed by design: a late layer sees an early result only inside a sum to which every intermediate layer has added its own.

A line of work relaxes this fixed connectivity. Dense connections (Huang et al., 2017) and depth-weighted averaging with learned static weights (Pagliardini et al., 2024) let a layer read earlier layers' outputs directly. Hyper-connections (Zhu et al., 2025) widen the residual stream into several streams whose mixing weights are learned and, in the dynamic variant, input-dependent, and mHC (Xie et al., 2026) constrains those mixing matrices so the scheme trains stably at scale. Multi-way dynamic dense connections (Xiao et al., 2025) compute input-dependent weights over all earlier layers' outputs, separately for the query, key, value and residual inputs of a block. Each token can then follow its own path through the layers, and these models reach the loss of Transformers trained with substantially more budget (Zhu et al., 2025; Xiao et al., 2025).

All of the dynamic variants above, however, make the same design choice: routing is local. Each layer carries its own router, which reads the hidden state entering that layer and decides what that layer reads and, in hyper-connections and mHC, where its output is written. The cross-layer routing topology is therefore assembled greedily, one layer at a time, and no module takes a global view of it. Consequently, cross-layer coordination cannot be planned explicitly from the input, and the topology cannot be inspected as an individual object.

In this paper, we propose DAGFormer, where the global routing topology is predicted with a separate module that reads only the input tokens, before the backbone processes each token. DAGFormer implements this idea on an OLMo-2 backbone (Walsh et al., 2025) with added cross-layer connections on attention heads. Instead of reading the running residual stream, each attention head computes its query, key and value from weighted mixtures of the embedding and all earlier layer outputs. The residual input of each layer is also such a mixture.

∗^{*} Equal contribution.

Figure

Figure 1: DAGFormer. For token xtx_t the predictor outputs the planned graph as four triangular matrices A^Q\hat{A}^Q, A^K\hat{A}^K, A^V\hat{A}^V and A^R\hat{A}^R that collect the planned weights α^(l)\hat{\alpha}^{(l)} of Eq. 1: one column per earlier output and, per layer, one row per head for QQ, KK and VV (the weights α^q,h,j(l)\hat{\alpha}_{q,h,j}^{(l)}) and a single row for RR (the weights α^r,j(l)\hat{\alpha}_{r,j}^{(l)}). Only the edges into layer 5, its outlined rows, are drawn, as rings on its heads (value in front; key, query and residual behind) with edge width proportional to the magnitude of the entry; every routed layer reads along its own rows in the same way, after the auxiliary local refinement of Eq. 2 (not drawn for demonstration). All weights shown are real values from a trained DAGFormer on training data.

A small causal encoder predicts all of these mixing weights: it reads the same token ids as the backbone, embedded with its own randomly initialized 256-dimensional table rather than the backbone's embeddings, and is pretrained jointly with the backbone, as shown in Figure 1. Additionally, an auxiliary local refinement, zero-initialized, lets each layer correct the predicted weights of its own heads from its input, so the predictor plans the graph and each layer refines its rows of it.

To study this model architecture, we train matched pairs of the standard OLMo-2 Transformer (vanilla Transformer) and DAGFormer from 75M to 1B parameters on Dolma (Soldaini et al., 2024), charging the routing cost in every compute comparison. DAGFormer is better at every size and at equal compute, and a 1B DAGFormer beats the 1B vanilla Transformer trained on twice as many tokens. It also beats four routing baselines trained with the same pipeline at every size but 150M, and the gain carries over to evaluation tasks and instruction finetuning. Ablations show that the shared predictor carries most of the gain, and under structured pruning DAGFormer loses the least of all baselines in five of six settings.

Our contributions are as follows:

• DAGFormer, a Transformer variant with dynamic cross-layer connections on attention heads, where the connections are predicted from the input tokens by a separate topology predictor which is pretrained together with an OLMo-2 backbone from scratch (Section 2).

• A matched scaling study from 75M to 1B with the routing cost charged and with DenseFormer, hyper-connection, mHC and MUDDFformer baselines on the same pipeline, carried through instruction finetuning and instruction-following evaluation (Section 3).

• Ablations of the routing source and a structured-pruning study showing that the learned topology makes models degrade more gracefully, without re-planning by the predictor (Sections 4, 5 and 6).

References (63)