---
title: "GEM Training: How Meta Doubled the Efficiency of Its LLM-Scale Ads Foundation Model"
description: "Meta doubled end-to-end training efficiency of GEM, its LLM-scale ads recommendation foundation model, to 20–25% MFU while scaling training FLOPs 4x in a year, by co-designing kernels, precision, parallelism, networking and memory."
url: "https://swe.quest/articles/gem-training-how-meta-doubled-the-efficiency-of-its-llm-scale-ads-foundation-1bf8547a323404ba"
canonical: "https://engineering.fb.com/2026/08/03/ml-applications/training-gem-at-llm-scale-meta-ads-recommendation-foundation-model/"
source: "Meta Engineering"
published: "2026-08-03"
difficulty: "hard"
kind: "Case study"
reading_minutes: 21
tags: ["model-training","recommendation-systems","performance","hardware","ads"]
---

# GEM Training: How Meta Doubled the Efficiency of Its LLM-Scale Ads Foundation Model

A post on [Meta Engineering](https://swe.quest/sources/meta.md), published 2026-08-03, 21 min read, Case study. Original: [https://engineering.fb.com/2026/08/03/ml-applications/training-gem-at-llm-scale-meta-ads-recommendation-foundation-model/](https://engineering.fb.com/2026/08/03/ml-applications/training-gem-at-llm-scale-meta-ads-recommendation-foundation-model/)

## Summary

Meta doubled end-to-end training efficiency of GEM, its LLM-scale ads recommendation foundation model, to 20–25% MFU while scaling training FLOPs 4x in a year, by co-designing kernels, precision, parallelism, networking and memory. Compute efficiency came from custom recommendation kernels: Jagged Flash Attention (no padding, subtraction-based masking, split-dQ backward, TLX warp specialization), GDPA unifying non-softmax attention variants (up to 3.5x over FA4 on short K/V), and 64-token BlockAttention with fused RoPE, plus MXFP8 attention and MLP that avoid CTR/CVR quality regressions. Scaling efficiency came from topology-aware 5D parallelism (2D FSDP + expert parallelism for dense, fully sharded 2D model parallelism for sparse embeddings) with SM-free collectives. Framing E2E MFU as local MFU × scaling ratio turned a sprawling co-design effort into separable optimization levers.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Recommendations & ranking](https://swe.quest/tags/recommendation-systems.md) (AI & ML)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Ads](https://swe.quest/tags/ads.md) (Domains)

## Prerequisites

- FlashAttention
- GPU kernel programming ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))
- distributed training parallelism ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- recommendation models

## Keywords

GEM, Jagged Flash Attention, GDPA, BlockAttention, MXFP8, Triton TLX, FSDP, FlashAttention 4

## Related posts

- [Meta’s Generative Ads Model (GEM): Scaling the Central Model and Compute Engine for Frontier Ads AI](https://swe.quest/articles/meta-s-generative-ads-model-gem-scaling-the-central-model-and-compute-engine-588a45420da8f0cd.md): Meta Engineering · 2026-10-13 · Hard · 14 min read · Recommendations & ranking, Ads, Model training, Inference & serving, Scaling
  Meta's 2026 GEM replaces per-surface ads ranking models with a single central recommendation foundation model trained across Facebook, Instagram, Reels and deep-funnel conversion objectives, reporting 18.9% conversion and 12% CTR gains.
- [Meta’s Generative Ads Model (GEM): The Central Brain Accelerating Ads Recommendation AI Innovation](https://swe.quest/articles/meta-s-generative-ads-model-gem-the-central-brain-accelerating-ads-5d5a24731a15c0eb.md): Meta Engineering · 2025-11-10 · Hard · 10 min read · Recommendations & ranking, Ads, Model training, ML platforms
  GEM is Meta's LLM-scale foundation model for ads recommendation, trained on thousands of GPUs and used as a teacher to improve hundreds of downstream vertical ranking models; it lifted ad conversions 5% on Instagram and 3% on Facebook Feed.
- [Meta Adaptive Ranking Model: Bending the Inference Scaling Curve to Serve LLM-Scale Models for Ads](https://swe.quest/articles/meta-adaptive-ranking-model-bending-the-inference-scaling-curve-to-serve-llm-b02b370caa05f2c4.md): Meta Engineering · 2026-03-31 · Hard · 9 min read · Recommendations & ranking, Inference & serving, Ads, Performance engineering, Hardware
  Meta Adaptive Ranking Model serves LLM-scale ads ranking models (O(10 GFLOPs) per token, O(1T) parameters) at O(100 ms) latency by routing each request to an appropriately complex model and computing user signals once per request instead of once per ad candidate.
- [From User Sequences to Scaling Laws: A Multi-Stage Architecture for Meta’s Ads Ranking](https://swe.quest/articles/from-user-sequences-to-scaling-laws-a-multi-stage-architecture-for-meta-s-ads-3c689db90be36667.md): Meta Engineering · 2026-08-05 · Hard · 6 min read · Recommendations & ranking, Ads, Model training, Machine learning, Scaling
  Meta scales sequence learning for ads ranking by splitting it into two stages: an offline transformer user model processes thousands of user events asynchronously and caches user-level embeddings, and a lightweight online ranking model combines those embeddings with fresh signals and ad candidates under strict latency budgets.
- [Beyond Prompting: How Algorithmic Evolution Doubled our Training Speed](https://swe.quest/articles/beyond-prompting-how-algorithmic-evolution-doubled-our-training-speed-3669307c6d5f1431.md): Klarna Engineering · 2026-03-30 · Medium · 7 min read · Model training, Performance engineering, AI for coding, Payments & fintech
  Klarna used Google DeepMind's AlphaEvolve to evolve nearly 6,000 candidate versions of the PyTorch training pipeline for a large transformer trained on payment events.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
