What if inside every Transformer, there was a smaller, faster, and better one?
With Model Carving, we let gradient descent find it during training: up to 34% smaller, 1.6× faster decoding, and better than models trained with up to 1.7× the compute! 🧵
📝 Blog: https://t.co/9VAQRgk2SJ
📄 Paper: https://t.co/UYeJAUfC0F
💻 Code: https://t.co/xVIS32Vf02
w/ Pratyusha Sharma @pratyusha_PS!
Yes, it might be one of the rare cases of being a free lunch!! Matching models trained w/ up to 1.7x the compute with also faster decoding. We think this better Pareto comes from the co-optimization pressure to find the topology most worth its compute while adapting the weights for it. Def more interp work to be done :)
What if inside every Transformer, there was a smaller, faster, and better one?
With Model Carving, we let gradient descent find it during training: up to 34% smaller, 1.6× faster decoding, and better than models trained with up to 1.7× the compute! 🧵
📝 Blog: https://t.co/9VAQRgk2SJ
📄 Paper: https://t.co/UYeJAUfC0F
💻 Code: https://t.co/xVIS32Vf02
w/ Pratyusha Sharma @pratyusha_PS!
Nope! You only set the training FLOP budget (we assume you have that :) like any run, but no target size or sparsity. Part of the method is measuring each component's contribution to the loss w.r.t. this FLOP budget, so the final shape/size is dynamic and comes out of training! This was a major goal-- to keep the same fixed settings at every scale.
@sebuzdugan@pratyusha_PS Yes :) On one H100, the carved 2.7B is faster at every batch size we tested, ~1.4x at batch 1, ~1.45x at the largest batch both models fit, and 1.61x at each model's max batch-- its smaller KV cache fits ~1.3-1.4x bigger batches. We have the full table in Table 10!
@MixtTensi8198@pratyusha_PS Thank you!! We haven't tried MoE yet, but everything in the paper is dense (standard + looped) so it's definitely complementary. The method should carry over to anything w/ a gate and a FLOP share, so you may have guessed our next experiments lol
Yes, good q! OFA trains one weight-sharing supernet across many widths/depths/kernel sizes, then runs a separate search to pick a subnet for each hardware target. Carving doesn't use a supernet and has no search, instead it's a single pretraining run that learns which sublayer/connection topology is most worth their compute. So you still get one static dense model, but the architecture is learned by + during training itself!
Good q! Unstructured pruning zeroes individual weights (needs sparse kernels) vs. structured pruning removes whole heads/layers from an already-trained model w/ a fixed target sparsity.
Carving is similar to structured, at the attn/MLP sublayer level, but done during pretraining and runs on any standard kernel. One major motivation was also no target sparsity so the model smoothly adjusts pressure as it needs to maintain the optimal quality-compute Pareto!
@antonships@pratyusha_PS Good question-- it mostly settles early! Most of the sublayers get carved in the first ~25% of training, but we allow carving to continue (which it does, gradually) until the cooldown starts at 80%. We freeze the topology for the final 20%.
Yes, that's right! Given the same training compute, carved models use ~34% fewer inference FLOPs and still reach lower loss than the standard baseline.
And, against a dense-connection baseline without any removal, carving matches or beats its performance with ~23% fewer inference FLOPs. So there's no net cost-- we get the overparameterized model's quality at a smaller model's inference cost!
@Advikar24@pratyusha_PS Thanks! Edge models are def a big motivation as usually you train a big model, then prune or distill it, but carved models beat both and decode 1.4× faster. :)
Carving gets better with scale. From 140M to 1.3B, carved looped models go from matching dense looped models trained with 1.33x to 1.71x the compute. Carved standard models also get leaner as they grow, from 13% to 34% fewer inference FLOPs per token.
The gains even hold when overtraining to ~130 tokens per parameter! 3/8
@pratyusha_PS Model Carving is inspired by synaptic pruning in the brain. Each sublayer and connection gets a learned gate and pays a compute price, set by how much it's still learning versus what it costs. When a gate hits zero, we simply remove it. No sparsity sweep required. 4/8
@dr_hb_ai@pratyusha_PS One per pass, so carving actually gives looped models a different depth profile per loop + lets each loop specialize more, while still keeping the weight-tying!
@therealjfsm425@pratyusha_PS Thanks so much! Yes, we pretrain w/ carving, then instruction tune the carved model as usual.
We found the lead holds after SFT, i.e. the carved 1.3B and 2.7B models stay ahead CORE and chat pass@k on GSM8K, TriviaQA and SQuAD. Same for quantization down to 3 bits!
@Advikar24@pratyusha_PS That was one of my favorite results!! One way I think about it is that a fixed Transformer hardcodes its inductive bias but Carving lets training find the right one-- for modular addition, just attn is needed!
Def agree, check out some of Ida Momennejad's work on the right primitives/grammar for intelligence! Self-supervised learning is also a powerful way to learn the robust representations you mention (Thomas Fel's work has both great visuals and excellent geometric theory on DINO-- see https://t.co/surCmal3du).
I'm very excited about this line of work, lead by the amazing @kadenzheng. We all know not every parameter is meaningfully useful at all times, even at fully dense cases. So why don't we get the benefits back? It's also a nice interp tool as well.
nice looking AND saves flops.
Thanks! The gains come from Carving removing whole attn and MLP sublayers, not just narrowing/fewer heads. So fewer sublayers = fewer weights to read, and also less KV cache per attention sublayer dropped!
At long context the cache dominates, so the gain should track how many attention sublayers were carved. For ref, our carved 2.7B keeps 22/32 attn sublayers, a 0.69× KV cache -> ~1.45× speedup. In the paper, we show the speedup grows from 1.34× at 1k to 1.42× at 8k, and I just measured ~1.51× at the same batch size at 32k. Will add long-context numbers to the revision!
Thanks, great catch! Nemotron Elastic should be in there, and we’ll add it in the next arXiv revision. :)
Just to highlight the different settings, Nemotron Elastic compresses the trained 12B model into nested smaller models via router + distillation, and those smaller models don’t surpass the parent on average. However, a big motivation of Model Carving was for the model to learn its own shape during pretraining without a target size, and this co-optimization pressure lets the carved models beat the parent models!
Yes! The 34% is inference FLOPs per token-- Carved sublayers are removed from the execution graph entirely and removed attn layers need no KV cache. In practice, we measured up to 1.45x faster decoding at equal batch on an H100, up to 1.6x at max batch, and ~1.4x on single workstation GPUs.