Model Carving: Training Transformers That Optimize Their Own Topology
Organizations: Harvard University · New York University
Abstract
Machine learning has largely kept separate the choice of architecture and the process of training. A classic Transformer, for instance, trains a fixed set of attention and MLP sublayers at every layer, in the same order, and optimizes the weights within. This uniformity is a convention rather than a principled design choice, and it is likely suboptimal: the best architecture for a given task may be smaller, more efficient, and far from uniform. We believe that, ideally, training itself should shape the model's topology. To this end, we introduce Model Carving, which learns both a Transformer's weights and its architecture in a single run. By applying learnable, scalar gates to each sublayer, we allow the training loss to remove the model's own components during training -- freeing a smaller heterogeneous network inside. We evaluate Model Carving by pre-training standard Transformers from 140M to 2.7B parameters and looped Transformers from 140M to 1.3B. At equal training compute, carved models reach a lower validation loss than dense models trained with up to 1.7 times more compute. Furthermore, carved models also outperform size-matched models produced by pruning or distillation, suggesting that the best way to obtain small models for edge devices is to carve them during training, not to compress a large one afterwards. This advantage both grows with scale and carries over to downstream tasks such as few-shot evaluation and generation. Because the removed sublayers no longer run, carved models also cost up to 34% fewer FLOPs per token and decode up to 1.6 times faster without cost in quality. Our results show that architecture, like weights, should be learned and not fixed in advance, and that inside every large transformer is a smaller, faster, stronger one waiting to be carved out.
Figures & tables
| Model | Params | Sublayers | Tokens | Training | Inference | Val. | Equal-token | CORE-22 | ||
| (M) | per token | (B) | FLOPs | GFLOPs/token | bpb | bpb | ||||
| Looped Transformer | ||||||||||
| 140M | full-depth | 151 | 128 / 128 | 7.6 | 1.18 | 0.899 | 0.983 | 18.9 | ||
| shallower (15) | 144 | 120 / 128 | 8.0 | 1.11 | 0.900 | 18.9 | ||||
| distilled | 144 | 120 / 128 | 8.0 | 1.11 | 0.915 | 17.9 | ||||
| carved | 151 | 117 / 128 | 7.9 | 1.09 | 0.883 | 0.958 | 19.9 | 1.33 | ||
| Equal samples (16 each) | Nearly equal allowance | ||||
|---|---|---|---|---|---|
| Task | Full-depth | Carving | Difference | Carving (24) | Difference |
| GSM8K | 0.284 | 0.300 | 0.016 [ 0.009, 0.040] | 0.375 | 0.091 [0.064, 0.118] |
| MATH-500 | 0.142 | 0.152 | 0.010 [ 0.021, 0.039] | 0.194 | 0.052 [0.018, 0.086] |
| TriviaQA | 0.413 | 0.391 | 0.022 [ 0.029, 0.016] | 0.429 | 0.016 [0.009, 0.022] |
| SQuAD | 0.624 | 0.623 | 0.001 [ 0.007, 0.005] | 0.649 | 0.025 [0.019, 0.032] |
| LAMBADA | 0.765 | 0.750 | 0.015 [ 0.024, 0.006] | 0.782 | 0.018 [0.008, 0.027] |
| Equal samples (16 each) | Nearly equal allowance | ||||
| Measure | Full-depth | Model Carving | Difference | Model Carving | Difference |
| Standard 1.3B, default recipe | |||||
| CORE-22 (13 stable) | 33.5 | 36.3 | 2.8 [ 1.6, 3.9] | ||
| GSM8K | 0.459 | 0.444 | 0.015 [ 0.041, 0.010] | 0.496 | 0.036 [ 0.008, 0.064] |
| TriviaQA | 0.402 | 0.409 | 0.007 [ 0.002, 0.012] | 0.435 | 0.033 [ 0.027, 0.038] |
| SQuAD | 0.899 | 0.904 | 0.005 [ 0.000, 0.011] | 0.922 | 0.023 [ 0.018, 0.029] |
Appendix figures & tables24 assets
Supplementary material from the paper’s appendix.
Appendix
| Size | Layers | Width | Heads | Parameters (M) | Training tokens (B) | Updates |
|---|---|---|---|---|---|---|
| 140M | 16 | 768 | 12 | 151 | 7.6 | 7,201 |
| 370M | 20 | 1,152 | 18 | 375 | 18.8 | 17,889 |
| 770M | 20 | 1,728 | 27 | 802 | 40.1 | 38,223 |
| 1.3B | 24 | 2,048 | 32 | 1,309 | 65.4 | 62,401 |
| 2.7B | 32 | 2,560 | 32 | 2,642 | 132.1 | 126,001 |
| Standard 140M | Looped 140M | |||||
|---|---|---|---|---|---|---|
| Starting gate value | Removed | FLOPs per token | Lead | Removed | FLOPs per token | Lead |
| 0.05 | 3 | 0.90 | 0.0016 to 0.0034 | 21 | 0.83 | 0.0148 |
| 0.1 | 3 to 5 | 0.84 to 0.90 | 0.0005 to 0.0043 | 11 | 0.91 | 0.0149 |
| 0.2 | 0 to 2 | 0.93 to 1.00 | 0.0070 to 0.0076 | 2 | 0.99 | 0.0161 |
| 0.4 | 0 | 1.00 | 0.0100 to 0.0110 | 3 | 0.98 | 0.0178 |
| Model | Params | Tokens | Inference | Val. | CORE-22 | |
|---|---|---|---|---|---|---|
| (M) | (B) | GFLOPs/token | bpb | |||
| Looped Transformer | ||||||
| 370M | full-depth | 375 | 18.8 | 3.039 | 0.808 | 25.7 |
| DenseFormer-style | 375 | 18.8 | 3.046 | 0.794 | 27.5 | |
| carved | 375 | 22.6 | 2.358 | 0.788 | 28.5 | |
| Standard Transformer | ||||||
| Family | Size | CORE-22 | Stable-13 |
|---|---|---|---|
| Looped | 140M | [ , ] | [ , ] |
| 370M | [ , ] | [ , ] | |
| 770M | [ , ] | [ , ] | |
| 1.3B | [ , ] | [ , ] | |
| Standard | 140M | [ , ] | [ , ] |
| 370M | [ , ] | [ , ] |
| Task | Looped 140M | Looped 370M | Looped 770M | Looped 1.3B |
|---|---|---|---|---|
| Samples (full-depth / carved) | 8 / 8 | 8 / 10 | 8 / 10 | 8 / 10 |
| GSM8K | 0.011 [ 0.003, 0.025] | 0.020 [ 0.004, 0.037] | 0.026 [ 0.009, 0.044] | 0.066 [ 0.047, 0.084] |
| MATH-500 | 0.007 [ 0.007, 0.021] | 0.011 [ 0.005, 0.029] | 0.012 [ 0.031, 0.006] | 0.030 [ 0.009, 0.051] |
| TriviaQA | 0.009 [ 0.006, 0.013] | 0.035 [ 0.031, 0.039] | 0.069 [ 0.065, 0.074] | 0.044 [ 0.040, 0.049] |
| SQuAD | 0.046 [ 0.040, 0.052] | 0.056 [ 0.050, 0.062] | 0.063 [ 0.058, 0.069] | 0.047 [ 0.041, 0.052] |
| LAMBADA | 0.019 [ 0.010, 0.028] | 0.056 [ 0.047, 0.065] | 0.058 [ 0.050, 0.067] | 0.052 [ 0.044, 0.060] |
| Model | Tokens | Training FLOPs | GFLOPs per byte | CORE-22 |
| Looped Transformers | ||||
| Model Carving -140M | 7.9B | 0.241 | 19.9 | |
| Model Carving -370M | 22.6B | 0.522 | 28.5 | |
| Model Carving -770M | 52.1B | 1.05 | 33.5 | |
| Model Carving -1.3B | 82.7B | 1.81 | 36.0 | |
| Parcae-140M ( Prairie et al., 2026 ) | 11.2B | 0.0887 | 13.5 | |
| Equal batch | Largest tested batch | ||||||
|---|---|---|---|---|---|---|---|
| Pair | Context | Batch 1 | Largest common | Full-depth | Model Carving | Per step | Loop |
| Looped 1.3B | 1,024 | 1.21 | 1.22 (71) | 71 | 83 | 1.26 | 1.31 |
| 4,096 | 1.26 | 1.22 (20) | 20 | 24 | 1.29 | 1.28 | |
| 8,192 | 1.27 | 1.21 (10) | 10 | 12 | 1.29 | 1.37 | |
| Standard 1.3B | 1,024 | 1.24 | 1.31 (273) | 273 | 328 | 1.35 | 1.33 |
| 4,096 | 1.26 | 1.33 (80) | 80 | 104 | 1.34 | 1.35 | |
| Family | Size | Attention kept | Full-depth (KiB) | Model Carving (KiB) | Ratio |
|---|---|---|---|---|---|
| Looped | 140M | 61 of 64 | 192.0 | 183.0 | 0.95 |
| 370M | 67 of 80 | 360.0 | 301.5 | 0.84 | |
| 770M | 63 of 80 | 540.0 | 425.2 | 0.79 | |
| 1.3B | 76 of 96 | 768.0 | 608.0 | 0.79 | |
| Standard | 140M | 15 of 16 | 48.0 | 45.0 | 0.94 |
| 370M | 17 of 20 | 90.0 | 76.5 | 0.85 |
| Model | Compute | Val. bpb | CORE-22 | Model Carving model |
|---|---|---|---|---|
| Model Carving | 1.00 | 0.727 | 31.2 | |
| Sheared-LLaMA-style, continued pretraining | 1.00 | 0.742 | 27.6 | [ , ] |
| Minitron-style, distillation and cross-entropy | 1.00 | 0.761 | 28.1 | [ , ] |
| ShortGPT-style, continued pretraining | 1.00 | 0.745 | 27.9 | [ , ] |
| Minitron-style, final full-depth save, distillation only | 1.21 | 0.747 | 29.3 | [ , ] |
| Val. bpb | CORE-22 | ||||
|---|---|---|---|---|---|
| Pair | Student | Model Carving | Student | Model Carving | Student Model Carving |
| Standard 140M | 0.947 | 0.922 | 14.23 | 16.51 | 2.28 [ 3.31, 1.25] |
| Standard 370M | 0.855 | 0.832 | 19.80 | 22.04 | 2.24 [ 3.22, 1.24] |
| Standard 770M | 0.789 | 0.767 | 25.26 | 27.17 | 1.91 [ 2.92, 0.89] |
| Standard 1.3B | 0.749 | 0.727 | 29.73 | 31.23 | 1.50 [ 2.51, 0.48] |
| Looped 140M | 0.915 | 0.883 | 17.92 | 19.92 | 2.00 [ 3.09, 0.87] |
| Full-depth | Model Carving | ||||||
|---|---|---|---|---|---|---|---|
| Family | Budget (FLOPs) | Params (M) | bpb | Params (M) | bpb | Gap (bpb) | |
| Looped | 187 | 0.931 | 169 | 0.922 | 0.009 | 1.16 | |
| 441 | 0.868 | 353 | 0.857 | 0.011 | 1.25 | ||
| 579 | 0.840 | 494 | 0.826 | 0.014 | 1.31 | ||
| 688 | 0.826 | 618 | 0.812 | 0.014 | 1.32 | ||
| 951 | 0.807 | 878 | 0.791 | 0.016 | – | ||
| Pair | Lead, seed 0 | Lead, seed 1 | Closed gates (0 / 1 / shared) | Total | Seed 1 reached |
|---|---|---|---|---|---|
| Standard 140M | 0.0041 [0.0039, 0.0043] | 0.0038 [0.0035, 0.0040] | 5 / 5 / 5 | 32 | the end |
| Standard 370M | 0.0025 [0.0023, 0.0028] | 0.0033 [0.0030, 0.0035] | 9 / 10 / 8 | 40 | the end |
| Standard 1.3B | 0.0026 [0.0022, 0.0030] | 0.0028 [0.0024, 0.0032] | 14 / 13 / 13 | 48 | the end |
| Standard 2.7B | 0.0006 | – | 22 / 22 / 20 | 64 | update 19,600 of 187,311 |
| Looped 140M | 0.0152 [0.0150, 0.0154] | 0.0156 [0.0155, 0.0158] | 11 / 10 / 4 | 128 | the end |
| Looped 370M | 0.0202 | – | 36 / 26 / 20 | 160 | update 15,210 of 21,560 |
| Pair, recipe | Measure | Equal samples (16 each) | Nearly equal allowance |
|---|---|---|---|
| Standard 1.3B, default | CORE-22 (13 stable) | 2.78 [ 1.59, 3.93] | |
| GSM8K | 0.015 [ 0.041, 0.010] | 0.036 [ 0.008, 0.064] | |
| TriviaQA | 0.007 [ 0.002, 0.012] | 0.033 [ 0.027, 0.038] | |
| SQuAD | 0.005 [ 0.000, 0.011] | 0.023 [ 0.018, 0.029] | |
| Standard 1.3B, gentler | CORE-22 (13 stable) | 0.68 [ 0.29, 1.68] | |
| GSM8K | 0.014 [ 0.009, 0.037] | 0.059 [ 0.034, 0.085] | |
| Pair | Recipe | Full-depth | Model Carving | Difference |
|---|---|---|---|---|
| Standard 1.3B | default | 0.227 | 0.224 | [ , ] |
| gentler | 0.031 | 0.029 | ||
| Standard 2.7B | default | 0.211 | 0.166 | [ , ] |
| gentler | 0.022 | 0.022 | ||
| Looped 1.3B | default | 0.263 | 0.253 | [ , ] |
| gentler | 0.034 | 0.034 |
| Family | Size | Full-depth | Shallower | Ratio | Model Carving | Ratio |
|---|---|---|---|---|---|---|
| Looped | 140M | 0.0807 | 0.0811 | 1.00 | 0.0692 | 0.86 |
| 370M | 0.0771 | 0.0782 | 1.02 | 0.0653 | 0.85 | |
| 770M | 0.0739 | 0.0756 | 1.02 | 0.0623 | 0.84 | |
| 1.3B | 0.0704 | – | – | 0.0611 | 0.87 | |
| Standard | 140M | 0.0734 | 0.0743 | 1.01 | 0.0659 | 0.90 |
| 370M | 0.0718 | 0.0719 | 1.00 | 0.0615 | 0.86 |
| Test exact match | |||||
|---|---|---|---|---|---|
| Task | Seed | Kept | Kept applications | Carved | Full-depth |
| Modular addition | 0 | 2 | attention of loop 3 layer 1 and of loop 4 layer 3 | 0.998 | – |
| 1 | 2 | attention of loop 3 layer 1 and of loop 4 layer 2 | 1.000 | – | |
| 2 | 2 | attention of loop 3 layer 1 and of loop 4 layer 2 | 0.764 | – | |
| ListOps | 0 | 6 | attention of loop 3 layers 1 and 2 and of loop 4 layers 2 and 3; MLP of loop 4 layers 2 and 3 | 0.861 | 0.851 |
| 1 | 4 | attention of loop 3 layers 1 and 2 and of loop 4 layer 3; MLP of loop 4 layer 3 | 0.851 | 0.862 | |
Transformer
Transformers are neural architectures that use attention to model relationships among sequence elements in language, vision, and scientific data.
See all 590 papers