Harvard and NYU carve Transformers in training, cutting up to 34% of inference FLOPs

Model Carving: Training Transformers That Optimize Their Own Topology

Kaden Zheng, Pratyusha Sharma

ICLR 2027

cs.LG, cs.AI

2026-11-21

Gates drop sublayers that do not earn their FLOPs. Matched-compute carved models beat dense runs needing up to 1.7× FLOPs, using up to 34% fewer inference FLOPs.

What problem this solves

A standard Transformer locks its layout before the first gradient step: attention, then MLP, same order, same width, every layer. That regularity is a convention. Reordering sublayers already changes perplexity, whole layers of a trained model can be dropped with modest damage, and models such as Gemma 3 and Jamba already break the pattern by hand.

Neural architecture search treats layout as a second optimization, a controller or a set of architecture weights trained apart from the model, often followed by a fresh run. Edge models are usually a large network that is later pruned or distilled. Model Carving folds both choices into one pretraining run. It starts oversized, lets the loss turn off sublayers that do not pay for themselves, and spends the freed FLOPs on extra tokens.

Method

Each sublayer is RMS-scaled against the residual stream and multiplied by a learned gate g ≥ 0 before it writes back. A gate at zero contributes nothing. Learned connections let a layer read earlier outputs, with the L1 norm of those coefficients capped at 1. Gates start at 0.1. At 0.2 or higher, almost nothing is removed.

The training FLOP budget is fixed. Removing a sublayer makes every later token cheaper, so the same budget buys more tokens. The pressure on a sublayer is the loss reduction those extra tokens are estimated to buy near the end of the run. The trainer reads the learning rate by scoring one batch on the live weights and on an earlier snapshot, then extrapolates that rate to the end of the budget with a power law. If the sublayer's contribution sits below the pressure, its gate is driven down.

The penalty is logarithmic. An L1 penalty weakens as the gate shrinks, so it is hard to compare with the sublayer's effect on the loss. The log penalty pushes with a constant force, and a gate falls only when its quality cost is about a third of the pressure (the factor is ln 20, a deliberate margin). A gate that hits zero is clipped there. Every 300 steps the trainer compiles a graph without the closed sublayers and switches over about 400 steps later. Pressure is set to zero during learning-rate cooldown.

Looped Transformers use the same rule. The stack is weight-tied and repeated for four loops, but each loop has its own gates, so one set of weights can run in one loop and be skipped in another.

Results

Training uses a shuffled sample of FineWeb-Edu. Standard Transformers run from 140M to 2.7B, looped models from 140M to 1.3B. The budget matches a full-depth run at 50 tokens per parameter. Matrix parameters use Muon; the rest use AdamW. Baselines share the data, the recipe, and the training FLOPs: the full-depth model, a shallower model sized to the carved inference cost, and a student distilled from the full-depth teacher into that shallower shape.

Starting pointVal. bpb (carved / full)Inference FLOPsCompute multiplier kCORE-22
Looped 1.3B0.683 / 0.7040.77×1.7136.0 / 35.2
Looped 370M0.788 / 0.8080.78×1.5528.5 / 25.7
Standard 2.7B0.675 / 0.6760.66×1.0337.0 / 36.0
Standard 1.3B0.727 / 0.7290.72×1.0531.2 / 29.8

k is how many times more training FLOPs a power-law fit to full-depth loss needs before it matches the carved validation loss. In the looped family it rises from 1.33 at 140M to 1.71 at 1.3B. In the standard family it stays between 1.03 and 1.07. On the compute-optimal frontier the gap is 1.16× to 1.32× for looped models and 1.10× to 1.25× for standard models, and it widens as the budget grows. Shallower models lose on both loss and CORE-22 at every scale. Looped carving barely changes parameter count, because the weights are tied; it skips sublayer applications. The standard 2.7B carved model keeps 66% of the parameters and 0.66× the inference FLOPs, a 34% cut.

On generative tasks at standard 2.7B, 16 samples each is roughly a tie: GSM8K pass@16 moves from 0.284 to 0.300, TriviaQA from 0.413 to 0.391. At 0.66× FLOPs per token the carved model can draw about 24 samples for the same inference budget, and then all five tasks beat the full-depth model. MATH-500 moves from 0.142 to 0.194. Decode is up to 1.45× faster at equal batch size and up to 1.61× at each model's largest batch. KV cache per token drops by 5% to 31%.

On the standard 1.3B model, Sheared-LLaMA, Minitron, and ShortGPT pruning, each retrained to the same total FLOPs, finish with higher loss and lower CORE-22. Distilled students do too, at every finished size. The main text does not report the numeric gaps for those three pruning runs. On modular addition the carved loop keeps 2 of 24 sublayer applications, both attention, at 99.8% test accuracy.

Why it matters

An edge model can shrink during pretraining and ship as a static graph, with no router at decode time. The lead survives 4-bit weight quantization, except at standard 2.7B, and survives 3-bit in the looped family. It also survives one epoch of instruction tuning. Under the gentler tuning recipe, pass@k on GSM8K, TriviaQA, and SQuAD is 2.0 to 9.5 points higher.

The topology runs opposite to what post-hoc pruning usually finds. Standard models drop sublayers in roughly the first third of depth. The 2.7B model removes attention in layers 2 through 11 and the MLP in layers 1 through 12. Predicting held-out removals from other scales gives an AUC of at least 0.97 for standard models. Knocking out the median sublayer the 2.7B carved model kept raises validation loss by more than 5× the damage of knocking out the median sublayer of the full-depth model. That ratio grows from about 2.4× at 140M to 5.5× at 2.7B.

On standard Transformers the training-loss win is small. The practical win is inference cost. The looped family is where the training-compute gap opens, and it grows with scale.

Limitations

The largest runs are a standard 2.7B and a looped 1.3B, on a FineWeb-Edu subset. Pressure assumes a constant learning rate and is switched off for cooldown, so across the eight pairs from 140M to 1.3B the carved models gain 10% to 16% less from cooldown than full-depth models. Most removals happen in the first 20% of steps. Gate initialization and the ln 20 margin are shared across every scale, and a closed sublayer never returns. A larger batch at 140M matched the carved loss in 38% fewer updates. That schedule was not tested at larger sizes.

CORE-22 comparisons against public models mix different data, tokenizers, and recipes. They say the carved scores are higher under one harness. They do not show that the training runs are matched. The abstract's 1.7× compute figure is the looped 1.3B multiplier. For standard Transformers, k is about 1.03 to 1.07.

Some of the quality may come from the learned skip connections. A DenseFormer-style control with those connections and no gate-driven removal lands close to the carved model. At looped 370M, carving reaches 0.788 bpb and 28.5 CORE-22, against 0.794 and 27.5, with 23% fewer inference FLOPs. Next to a network that already has dense connections, the extra gain from removal is smaller than the gain against a plain Transformer.

Terms

Source

What people are saying

Related papers

All paper explainers