DAGFormer: Global Topology Prediction for Transformer Cross-Layer Connections
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.
Figures & tables
| baselines (WikiText-2 NLL ) | |||||||
| size | vanilla | DenseFormer | hyper-conn. | mHC | MUDDFormer | DAGFormer | gap to vanilla |
| 75M | 4.997 | 5.027 | 4.964 | 4.913 | 4.974 | 4.711 | +0.29 |
| 150M | 4.268 | 4.246 | 4.220 | 4.209 | 4.041 | 4.085 | +0.18 |
| 300M | 3.808 | 3.745 | 3.692 | 3.652 | 3.649 | 3.544 | +0.26 |
| 1B, 5B tokens | 3.569 | 3.513 | 3.492 | 3.438 | 3.423 | 3.307 | +0.26 |
| 1B, 10B tokens | 3.446 | – | – | – | – | 3.219 | +0.23 |
| mean accuracy (%) per kind of task | |||||||
| size | model | commonsense (5) | science (4) | reading (2) | math (2) | Mean | mean rank |
| 300M | vanilla | 39.8 | 36.5 | 38.1 | 11.7 | 34.2 | 4.15 |
| DenseFormer | 38.9 | 36.5 | 40.8 | 12.7 | 34.4 | 4.23 | |
| hyper-conn. | 38.5 | 38.5 | 38.3 | 12.3 | 34.4 | 3.69 | |
| mHC | 39.2 | 38.8 | 41.8 | 12.9 | 35.4 | 2.54 | |
| MUDDFormer | 39.7 | 38.6 | 40.9 | 11.5 | 35.2 | 3.08 | |
| +Alpaca | +SmolTalk | ||||
| size | model | NLL | win | NLL | win |
| 300M | vanilla | 2.392 | – | 1.760 | – |
| DenseFormer | 2.342 | 0.55 | 1.722 | 0.57 | |
| hyper-conn. | 2.298 | 0.59 | 1.684 | 0.58 | |
| mHC | 2.277 | 0.58 | 1.664 | 0.62 | |
| MUDDFormer | 2.256 | 0.63 | 1.639 | 0.64 | |
| held-out NLL | ||||||
|---|---|---|---|---|---|---|
| size | model | params | WikiText | Math | GSM8K | balanced |
| 75M | vanilla | 77M | 4.997 | 4.271 | 4.242 | 5.167 |
| vanilla, hidden 656 | 107M | 4.769 | 4.057 | 4.052 | 4.961 | |
| vanilla, 13 layers | 106M | 4.871 | 4.215 | 4.174 | 5.094 | |
| DAGFormer | 106M | 4.711 | 3.984 | 3.973 | 4.937 | |
| 150M | vanilla | 153M | 4.268 | 3.599 | 3.608 | 4.471 |
| 75M | 150M | 300M | |||||||
|---|---|---|---|---|---|---|---|---|---|
| NLL | damage (%) | NLL | damage (%) | NLL | damage (%) | ||||
| model | 0% | 50% | 70% | 0% | 50% | 70% | 0% | 50% | 70% |
| vanilla | 2.387 | 9.0 | 17.9 | 1.854 | 9.9 | 21.2 | 1.676 | 7.4 | 17.8 |
| DenseFormer | 2.383 | 9.5 | 18.7 | 1.830 | 9.5 | 20.7 | 1.641 | 7.9 | 18.5 |
| hyper-conn. | 2.306 | 9.5 | 19.5 | 1.804 | 9.7 | 21.4 | 1.604 | 7.7 | 17.8 |
| mHC | 2.328 | 9.0 | 20.1 | 1.813 | 9.5 | 21.0 | 1.585 | 8.4 | 18.4 |
Appendix figures & tables21 assets
Supplementary material from the paper’s appendix.
Appendix
| training: time per token relative to vanilla | prefill | ||||||
| size | vanilla (tok/s) | DenseFormer | hyper-conn. | mHC | MUDDFormer | DAGFormer | vanilla (tok/s) |
| 75M | 108.8K | 1.02 | 1.36 | 1.63 | 1.17 | 1.44 | 851K |
| 150M | 79.7K | 1.03 | 1.50 | 1.66 | 1.21 | 1.57 | 474K |
| 300M | 49.1K | 1.03 | 1.59 | 1.68 | 1.28 | 1.77 | 245K |
| 1B | 18.3K | 1.03 | 1.56 | 1.51 | 1.19 | 1.65 | 76K |
| MC acc. | bits per byte | |||
| model | stage | GSM8K | WikiText | |
| 300M, 21B corpus | ||||
| vanilla | base | 0.369 | 1.458 | 1.128 |
| DAGFormer | base | 0.391 | 1.344 | 1.057 |
| vanilla | +Alpaca | 0.371 | 1.452 | 1.184 |
| DAGFormer | +Alpaca | 0.390 | 1.295 | 1.108 |
| accuracy (%) | |||||||||||||||
| size | model | ARC-e | ARC-c | HSwag | PIQA | WinoG | OBQA | SciQ | BoolQ | LAMB | CSQA | SIQA | MathQA | GSM8K | Mean |
| 300M | vanilla | 38.1 | 20.6 | 27.4 | 61.2 | 52.2 | 24.6 | 62.5 | 56.7 | 19.5 | 20.5 | 37.7 | 22.4 | 1.0 | 34.2 |
| DenseFormer | 37.8 | 21.2 | 27.3 | 60.8 | 51.1 | 22.4 | 64.5 | 60.8 | 20.7 | 19.7 | 35.9 | 22.9 | 2.5 | 34.4 | |
| hyper-conn. | 39.6 | 22.5 | 27.8 | 60.8 | 48.6 | 25.8 | 65.9 | 55.0 | 21.6 | 19.7 | 35.8 | 21.6 | 3.0 | 34.4 | |
| mHC | 38.7 | 22.9 | 27.6 | 61.2 | 50.0 | 26.2 | 67.4 | 61.3 | 22.2 | 19.0 | 38.0 | 23.3 | 2.5 | 35.4 | |
| MUDDFormer | 38.3 | 22.6 | 28.5 | 60.8 | 52.2 | 25.0 | 68.4 | 58.7 | 23.0 | 19.7 | 37.3 | 22.0 | 1.0 | 35.2 | |
| accuracy (%) | ||||||||||||||||
| size | stage | model | ARC-e | ARC-c | HSwag | PIQA | WinoG | OBQA | SciQ | BoolQ | LAMB | CSQA | SIQA | MathQA | GSM8K | Mean |
| 300M | base | vanilla | 38.1 | 20.6 | 27.4 | 61.2 | 52.2 | 24.6 | 62.5 | 56.7 | 19.5 | 20.5 | 37.7 | 22.4 | 1.0 | 34.2 |
| DenseFormer | 37.8 | 21.2 | 27.3 | 60.8 | 51.1 | 22.4 | 64.5 | 60.8 | 20.7 | 19.7 | 35.9 | 22.9 | 2.5 | 34.4 | ||
| MUDDFormer | 38.3 | 22.6 | 28.5 | 60.8 | 52.2 | 25.0 | 68.4 | 58.7 | 23.0 | 19.7 | 37.3 | 22.0 | 1.0 | 35.2 | ||
| DAGFormer | 38.8 | 22.1 | 28.2 | 61.7 | 52.3 | 24.4 | 73.7 | 60.4 | 26.5 | 19.6 | 37.8 | 23.1 | 2.5 | 36.2 | ||
| +Alpaca | vanilla | 37.1 | 21.8 | 27.7 | 60.6 | 53.7 | 25.6 | 59.3 | 59.1 | 20.8 | 20.0 | 37.4 | 22.6 | 2.5 | 34.5 | |
| SFT | DAGFormer vs. vanilla | win rate [CI] | W/L |
|---|---|---|---|
| Alpaca | 300M vs. 300M, seed 1 | 0.57 [0.50, 0.64] | 16/10 |
| Alpaca | 300M vs. 300M, seed 2 | 0.61 [0.54, 0.67] | 19/8 |
| Alpaca | 1B@5B vs. 1B@5B | 0.58 [0.51, 0.66] | 26/12 |
| Alpaca | 1B@5B vs. 1B@10B | 0.56 [0.48, 0.64] | 23/17 |
| Alpaca | 1B@10B vs. 1B@10B | 0.56 [0.48, 0.63] | 19/14 |
| SmolTalk | 300M vs. 300M, seed 1 | 0.69 [0.63, 0.75] | 27/2 |
| +Alpaca | +SmolTalk | ||||
| size | routed model | win rate | W/T/L | win rate | W/T/L |
| 300M | DAGFormer | 0.65 † [0.60, 0.70] | 124/69/55 | 0.70 † [0.65, 0.75] | 138/69/41 |
| MUDDFormer | 0.63 † [0.58, 0.68] | 117/78/53 | 0.64 † [0.59, 0.69] | 120/73/55 | |
| DenseFormer | 0.55 † [0.50, 0.61] | 91/84/73 | 0.57 † [0.52, 0.63] | 101/81/66 | |
| hyper-conn. | 0.59 † [0.54, 0.64] | 109/80/60 | 0.58 † [0.53, 0.64] | 106/76/66 | |
| mHC | 0.58 † [0.53, 0.63] | 100/89/60 | 0.62 † [0.57, 0.67] | 118/73/57 | |
| run | size | WikiText-2 | MathInstruct | GSM8K | balanced |
|---|---|---|---|---|---|
| vanilla | 75M | 4.997 | 4.271 | 4.242 | 5.167 |
| vanilla, hidden 656 | 75M | 4.769 | 4.057 | 4.052 | 4.961 |
| vanilla, 13 layers | 75M | 4.871 | 4.215 | 4.174 | 5.094 |
| DenseFormer | 75M | 5.027 | 4.303 | 4.249 | 5.196 |
| hyper-connections (static) | 75M | 5.042 | 4.301 | 4.246 | 5.191 |
| hyper-connections (DHC 4) | 75M | 4.964 | 4.202 | 4.157 | 5.114 |
| 75M, WikiText-2 NLL | 2.5e-4 | 5e-4 | 1e-3 | 2e-3 |
|---|---|---|---|---|
| vanilla | 5.878 | 4.997 | 4.654 | 4.563 |
| DAGFormer | 5.558 | 4.711 | 4.413 | 4.329 |
| gap | 0.32 | 0.29 | 0.24 | 0.23 |
| routing source (75M) | routing | held-out NLL | tasks | |||
|---|---|---|---|---|---|---|
| params | own | WikiText | Math | GSM8K | acc. | |
| none (vanilla) | 0 | 4.213 | 6.593 | 5.373 | 5.404 | 25.7 |
| static table, no input | 500 | 4.171 | 6.529 | 5.243 | 5.279 | n/a |
| per-layer predictors | 35.6M | 4.058 | 6.256 | 5.025 | 5.148 | 26.0 |
| predictor only | 28.7M | 4.031 | 6.207 | 4.981 | 5.116 | 26.2 |
| predictor + refinement | 29.1M | 4.014 | 6.163 | 4.932 | 5.080 | 26.5 |
| size | 75M | 150M | 300M | 1B |
|---|---|---|---|---|
| layers / width / heads | 6 / 512 / 8 | 8 / 768 / 12 | 12 / 1024 / 16 | 16 / 2048 / 16 |
| MLP width | 2048 | 3072 | 4096 | 8192 |
| backbone params (M) | 76.6 | 152.6 | 304.1 | 1279.4 |
| routing params (M) | 29.1 | 30.0 | 32.3 | 36.7 |
| steps | 3000 | 6000 | 12000 | 9540 (+9540) |
| tokens (B) | 1.57 | 3.15 | 6.29 | 5.0 (10.0) |
| size | corpus | WikiText-2 | MathInstruct | GSM8K | balanced Dolma | ||||
|---|---|---|---|---|---|---|---|---|---|
| vanilla | DAGFormer | vanilla | DAGFormer | vanilla | DAGFormer | vanilla | DAGFormer | ||
| 75M | 12B | 4.980 | 4.775 | 4.267 | 4.053 | 4.216 | 3.998 | 5.175 | 4.992 |
| 75M | 12B’ | 4.997 | 4.711 | 4.271 | 3.984 | 4.242 | 3.973 | 5.167 | 4.937 |
| 150M | 12B | 4.297 | 4.100 | 3.630 | 3.424 | 3.626 | 3.465 | 4.514 | 4.334 |
| 150M | 12B’ | 4.268 | 4.085 | 3.599 | 3.383 | 3.608 | 3.402 | 4.471 | 4.305 |
| 300M | 21B | 3.808 | 3.544 | 2.742 | 2.565 | 3.232 | 2.937 | 3.832 | 3.606 |
| routing source | own cache | WikiText-2 | MathInstruct | GSM8K | MC w/o BoolQ |
|---|---|---|---|---|---|
| base / Alpaca / SmolTalk | |||||
| none (vanilla) | 4.213 | 6.593 | 5.373 | 5.404 | 0.269 / 0.278 / 0.293 |
| static learned table (no token input) | 4.176 | 6.529 | 5.243 | 5.279 | - |
| per-layer predictors (unshared) | 4.058 | 6.256 | 5.025 | 5.148 | 0.271 / 0.290 / 0.304 |
| shared predictor only | 4.031 | 6.207 | 4.981 | 5.116 | 0.274 / 0.289 / 0.301 |
| shared + local (DAGFormer) | 4.014 | 6.163 | 4.932 | 5.080 | 0.276 / 0.290 / 0.302 |
| size | model | stage | MC acc. (12) | GSM8K acc. | GSM8K bpb | WikiText bpb |
|---|---|---|---|---|---|---|
| 75M | vanilla | base | 0.304 | 0.010 | 1.840 | 1.393 |
| 75M | vanilla | +Alpaca | 0.309 | 0.010 | 1.801 | 1.459 |
| 75M | vanilla | +SmolTalk | 0.309 | 0.015 | 1.613 | 1.595 |
| 75M | DAGFormer | base | 0.316 | 0.025 | 1.759 | 1.347 |
| 75M | DAGFormer | +Alpaca | 0.319 | 0.015 | 1.733 | 1.417 |
| 75M | DAGFormer | +SmolTalk | 0.336 | 0.010 | 1.502 | 1.550 |
| size | setting | vanilla | DAGFormer | peak post-prune vanilla | peak post-prune DAGFormer |
|---|---|---|---|---|---|
| 75M | unpruned finetune | 2.388 | 2.223 | - | - |
| 75M | 30% heads+channels | 2.478 | 2.298 | 2.749 | 2.578 |
| 75M | 50% heads+channels | 2.590 | 2.391 | 2.841 | 2.604 |
| 75M | 70% heads+channels | 2.829 | 2.614 | 3.199 | 2.913 |
| 75M | 50%, random importance | 3.029 | 2.935 | 4.513 | 4.729 |
| 75M | 33% whole blocks | 2.610 | 2.547 | 4.760 | 4.377 |
| model | set | intact | predictor position mean | predictor global mean | local mean | both mean |
|---|---|---|---|---|---|---|
| 75M (locality arm, both) | wikitext2 | 6.164 | 6.161 | 6.162 | 6.582 | 6.595 |
| 75M (locality arm, both) | mathinstruct | 4.933 | 4.928 | 4.934 | 5.267 | 5.272 |
| 75M (locality arm, both) | gsm8k | 5.080 | 5.075 | 5.076 | 5.353 | 5.353 |
| 75M (locality arm, both) | own | 4.009 | 4.012 | 4.038 | 4.465 | 4.502 |
| 300M | wikitext2 | 3.544 | 3.547 | 3.604 | 4.251 | 4.297 |
| 300M | mathinstruct | 2.565 | 2.556 | 2.600 | 3.065 | 3.065 |
| SFT | comparison | writing | roleplay | reasoning | math | coding | extraction | stem | humanities |
|---|---|---|---|---|---|---|---|---|---|
| Alpaca | 300M vs. 300M | 0.72 | 0.57 | 0.47 | 0.40 | 0.60 | 0.55 | 0.75 | 0.47 |
| Alpaca | 300M mod. vs. 300M | 0.80 | 0.53 | 0.42 | 0.50 | 0.50 | 0.72 | 0.55 | 0.68 |
| Alpaca | 1B@5B vs. 1B@5B | 0.55 | 0.60 | 0.42 | 0.45 | 0.42 | 0.62 | 0.75 | 0.85 |
| Alpaca | 1B@5B vs. 1B@10B | 0.42 | 0.82 | 0.50 | 0.28 | 0.53 | 0.65 | 0.53 | 0.75 |
| Alpaca | 1B@10B vs. 1B@10B | 0.40 | 0.75 | 0.42 | 0.33 | 0.65 | 0.65 | 0.53 | 0.75 |
| SmolTalk | 300M vs. 300M | 0.82 | 0.82 | 0.53 | 0.80 | 0.65 | 0.57 | 0.60 | 0.72 |
| model | mean score (1–10) | answer tokens | ended on end-of-turn |
|---|---|---|---|
| 300M vanilla / Alpaca | 1.91 | 109 | 0.74 |
| 300M DAGFormer / Alpaca | 2.15 | 109 | 0.72 |
| 300M modular / Alpaca | 1.95 | 114 | 0.71 |
| 1B vanilla 5B / Alpaca | 2.06 | 103 | 0.74 |
| 1B DAGFormer 5B / Alpaca | 2.14 | 122 | 0.75 |
| 1B vanilla 10B / Alpaca | 2.19 | 111 | 0.71 |
| held-out NLL at sparsity | NLL at 50%, routers frozen | ||||||
|---|---|---|---|---|---|---|---|
| size | model | 0% | 30% | 50% | 70% | all routers | predictor only |
| 75M | vanilla | 2.387 | 2.475 | 2.602 | 2.815 | – | – |
| DenseFormer | 2.383 | 2.482 | 2.610 | 2.829 | 2.640 | – | |
| hyper-conn. | 2.306 | 2.400 | 2.526 | 2.756 | 2.517 | – | |
| mHC | 2.328 | 2.408 | 2.537 | 2.796 | 2.549 | – | |
| MUDDFormer | 2.362 | 2.461 | 2.612 | 2.889 | 2.618 | – | |
| held-out NLL | damage (%) | frozen | ||||||
|---|---|---|---|---|---|---|---|---|
| size | model | 0% | 30% | 50% | 70% | at 50% | at 70% | NLL at 50% |
| 75M | vanilla | 2.388 | 2.478 | 2.590 | 2.829 | 8.4 | 18.5 | – |
| DAGFormer | 2.223 | 2.298 | 2.391 | 2.614 | 7.5 | 17.6 | 2.388 | |
| 150M | vanilla | 1.883 | 1.957 | 2.071 | 2.278 | 10.0 | 21.0 | – |
| DAGFormer | 1.743 | 1.807 | 1.899 | 2.091 | 8.9 | 20.0 | 1.899 | |
| 300M | vanilla | 1.608 | 1.665 | 1.762 | 1.967 | 9.6 | 22.3 | – |
Transformer
Transformers are neural architectures that use attention to model relationships among sequence elements in language, vision, and scientific data.
See all 536 papers