Skip to main content
Back

Harvard's Model Carving Cuts AI Inference Costs by 34% During Pretraining

Model Carving trains Transformers with learnable gates on every sublayer, letting the loss itself delete components and leave a smaller, faster network behind.

Pro

  • Model Carving adds learnable gates to each Transformer sublayer and removes them during training when they underperform.
  • Carved models cut inference FLOPs per token by up to 34% with no quality loss.
  • Dense looped Transformers need up to 1.71x more compute to match carved loss.
  • Decoding runs up to 1.6x faster on H100 with smaller KV cache footprint.
  • Carved small models beat pruned or distilled size-matched baselines, challenging compress-after-training pipelines.
  • Code and project page are public; evaluated up to 2.7B parameters.

Most Transformer training fixes the architecture before optimization begins: choose the depth, alternate attention and MLP sublayers, then update only their weights. Researchers from Harvard and NYU propose Model Carving, which learns weights and topology in one pretraining run. Across standard and looped Transformers, the method cuts inference compute by up to 34%, reduces KV-cache use, and matches or improves model quality.

The loss chooses what survives

Each attention and MLP sublayer writes to the residual stream through a learned scalar gate. Learned skip connections also allow later blocks to reuse outputs from earlier layers. Model Carving applies RMS normalization before each gated write, making the gate the primary control over that sublayer’s contribution. When optimization drives a gate to zero, zero becomes an absorbing state and the associated sublayer leaves the computation graph permanently.

Each gate faces a pressure term based on opportunity cost. The method estimates how much the loss could improve if the sublayer’s FLOPs were spent processing additional training tokens. It fits a power law to the run’s recent learning curve, forecasts the marginal value of more tokens near the end of training, and compares that value with the sublayer’s contribution. A sublayer remains active when its loss reduction exceeds the estimated benefit of reallocating its compute. This calibration removes the need for a manual penalty sweep.

Validation loss plotted against training FLOPs for carved and dense Transformer models
Carved and dense models compared by validation loss and training compute.

A 34% FLOP cut at 2.7B

The authors pretrained standard Transformers from 140 million to 2.7 billion parameters and looped Transformers from 140 million to 1.3 billion. Looped models repeatedly apply a weight-tied block, allowing the same parameters to perform several computational steps. Experiments used matched datasets and training budgets. Validation loss is reported in bits per byte, or bpb, where lower values indicate better prediction. CORE-22 aggregates performance across 22 downstream tasks, where higher scores are better. GFLOPs per token measures billions of floating-point operations required for each generated token.

Selected dense and carved model comparisons
Metric Dense baseline Carved model Reported change
Inference GFLOPs per token, 2.7B standard 5.62 3.74 34% lower
Validation bpb, 2.7B standard 0.676 0.675 0.001 lower
CORE-22, 2.7B standard 36.0 37.0 1.0 point higher
Validation bpb, 1.3B looped 0.704 0.683 0.021 lower

Matching the carved 1.3B looped model’s validation loss required a dense looped baseline to use 1.71 times as much compute. The full paper also reports up to 1.6 times faster decoding on an Nvidia H100. KV-cache storage fell by 5% to 31% per token, reducing the memory used to retain attention keys and values during autoregressive generation.

Decode throughput, inference FLOPs, and KV-cache use for carved and dense models
Measured inference costs and decoding throughput for carved and dense architectures.

One run replaces a compression stage

Carved networks outperform size-matched models produced through pruning or teacher-student distillation in the paper’s experiments. A gated pretraining run can therefore produce the deployed topology directly, removing a separate compression stage and the need to train a larger teacher first. At matched inference cost, the authors report that their carved 1.3B standard model exceeds OPT-1.3B and Pythia-1.4B on CORE-22 while using less reported training compute.

Different depths produce different circuits

The retained architectures vary across depth rather than collapsing into uniformly shallower networks. Attention and MLP sublayers survive or disappear independently, and looped Transformers can select different sublayers on each repeated application. This flexibility allows training to allocate compute according to the role of each depth and loop.

Symbolic tasks produce especially sparse circuits. For modular addition modulo 113, Model Carving retains only 2 of 24 sublayer applications. Both surviving applications use attention, while every MLP application is removed.

Sparse architectures learned by Model Carving on symbolic reasoning tasks
Minimal attention and MLP circuits selected for symbolic tasks.

Where the method fits

  • Inference-heavy services: A one-time architecture search during pretraining can reduce recurring generation costs.
  • Edge and on-device deployment: Lower FLOPs and smaller KV caches address compute and memory limits without a separate compression run.
  • Looped Transformers: The largest reported quality gains occur in weight-tied models, and the advantage grows with scale in the tested range.
  • Architecture research: Permanently removed sublayers expose compact circuits that can be inspected after training.

Limits before adoption

  • Scale: Experiments stop at 2.7 billion parameters, well below the largest production training runs.
  • Evaluation: Results come from the authors’ pretraining setup and evaluation harness rather than standard public leaderboards. Comparisons with independently trained model families also involve different datasets and recipes.
  • Standard-decoder gains: The reported compute-equivalent improvement for standard Transformers is 1.05 to 1.07 times. Their main benefit is cheaper inference at similar quality, while looped models show larger loss reductions.
  • Irreversible removal: A gate cannot recover after reaching zero, so noisy early estimates can permanently eliminate a useful sublayer.
  • Hardware dependence: Reduced FLOPs do not guarantee proportional latency gains. Actual speed depends on kernels, memory traffic, batch size, and the resulting topology.

The authors publish source code for reproducing the experiments and testing the method in other training stacks.