MetaExplainer
GEM Training: How Meta Doubled the Efficiency of Its LLM-Scale Ads Foundation Model
Summary
Meta’s Generative Ads Recommendation Model (GEM), a hybrid foundation model for ads recommendations on Instagram and Facebook, trains across several thousand latest-generation GPUs and combines trillions of sparse embedding parameters with billions of dense parameters. The post frames its engineering problem around recommendation-specific jagged and asymmetric sequences, memory-bound operations, numerical sensitivity, communication overhead, activation pressure, and load skew that make conventional LLM training techniques insufficient. Its co-design approach combines custom kernels such as Jagged Flash Attention (JFA), BlockAttention, and Generalized Dot-Product Attention (GDPA), mixed ultra-low-precision training including MXFP8 attention and MLP, topology-aware 5D parallelism, SM-free collectives, and memory and load-balancing techniques. The reported result is a doubling of end-to-end training efficiency to 20–25% Model FLOPs Utilization (MFU) while total training FLOPs increased fourfold over 12 months; Base Batch Shuffling (BBS) alone delivered a reported 4% efficiency gain, with 4% QPS improvement and 4% peak memory reduction.
Context
GEM combines trillions of sparse embedding parameters with billions of dense parameters and processes sequence and non-sequence recommendation features. Its jagged sequence lengths, asymmetric attention patterns, memory-bound operations, numerical sensitivity, communication demands, activation pressure, and iteration-to-iteration load skew create training challenges that standard LLM-oriented infrastructure does not directly address.
Approach / What changed
The work separates end-to-end MFU into local compute efficiency and scaling efficiency, then co-designs kernels, precision, parallelism, networking, memory management, and load balancing. Techniques include JFA, BlockAttention, GDPA, mixed ultra-low-precision training, topology-aware 5D parallelism with SM-free collectives, activation quantization, and Base Batch Shuffling for balancing jagged workloads without cross-rank communication.
Takeaways
Jagged Flash Attention eliminates compute waste from padding variable-length inputs, while BlockAttention reduces long user-history self-attention cost from O(L²) to O(L) while preserving model quality and efficiency.
Base Batch Shuffling sorts 128-sample sub-batches by total sequence length and interleaves heavy and light groups into 1K+ sample batches, delivering a reported 4% efficiency gain without cross-rank communication.
GEM reached 20–25% end-to-end MFU after a twofold efficiency improvement, while its total training FLOPs scaled fourfold over 12 months.
Source and freshness
- Source
- engineering.fb.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.