Meta AI Research ★ 85 4 min

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

AI ResearchData InfrastructureML Applications

🔗 https://engineering.fb.com/2026/08/03/ml-applications/training-gem-at-llm-scale-meta-ads-recommendation-foundation-model/

📌 【Meta AI 研究】訓練效率翻倍:揭秘 Meta 廣告推薦基礎模型 GEM 的大規模訓練技術

TL;DR:透過自研 JFA 與 GDPA Kernel,Meta 將廣告推薦模型 GEM 的訓練吞吐量提升了 30% 以上。

在廣告推薦系統中,處理數兆級別的稀疏嵌入(sparse embedding)與數十億級別的密集參數(dense parameters)是一項極大的挑戰。Meta 推出的 GEM 是其廣告系統的核心推薦基礎模型,採用混合架構來處理序列特徵(如使用者活動歷史)與非序列特徵(如使用者位置)。然而,現有的 GPU 軟體棧多針對 LLM 任務優化,面對推薦系統中「長度不一(jagged)的序列」與「複雜的特徵交互」,難以達成高 GPU 運算利用率。

🧩 將訓練效率拆解為兩個核心維度

Meta 發現,單純增加 GPU 數量並不能帶來成比例的加速。為了提升效能,他們將端到端(E2E)的 MFU(Model Flops Utilization)拆解為兩個獨立的優化問題:

  • Local MFU (運算效率):衡量單顆 GPU 的運算單元利用率,取決於 Kernel 設計、數值精度以及工作負載與 GPU 架構(如 Tensor cores)的匹配程度。
  • Scaling Ratio (擴展效率):衡量將模型分散至數千顆 GPU 進行訓練時,能保留多少單卡效能。這會受到通訊開銷、負載不平衡與記憶體壓力導致的重算(recomputation)影響。

📊 針對推薦系統特性開發的自研 Kernel

為了突破現有 FlashAttention 在處理推薦任務時的限制,Meta 研發了多種專用技術:

  • JFA (Jagged FlashAttention): 傳統 FlashAttention 針對 LLM 的固定長度序列設計,但在推薦系統中,使用者序列長度差異極大(從數百到數萬個 token 不等)。若進行補齊(padding)會浪弱 50% 的運算量。JFA 直接作用於變長(variable-length)的 jagged tensors,消除了 padding 開銷。其最新版本 JFA v4 在性能上較 v2 提升了 40-140%,並帶來 18.5% 的 Local MFU 增益。
  • GDPA Kernel: GEM 使用多種類似 Attention 的交互模式(如 self-attention、PMA、cross-attention),但會將 softmax 替換為 GELU 或 SiLU 等激活函數。Meta 開發了 GDPA Kernel 來統一這些模組,在處理短 K/V 序列的生產環境中,其前向傳播速度比 Flash Attention 4 快上 3.5 倍。
  • TLX Block Attention: 針對 Self-attention 的長序列問題,Meta 結合了滑動窗口(Sliding Window Attention)與 Block-aligned attention 技術。透過將 Attention 轉換為獨立的 64x64 問題,並將 RoPE 反向傳播融合進 Attention epilogue,使 Self-attention 層的 MFU 比 Triton 的 Block Attention 提升了 30.6%。

💡 利用低精度訓練實現效能躍升

在最新的 GPU 硬體上,使用 FP8 精度可獲得 2 倍於 FP16 的峰值 TFLOPS,而 FP4 則可達 4 倍。為了在不損失模型品質(避免數值不穩定與量化開銷)的前提下利用此特性,Meta 開發了具備數值穩定增強功能的 MXFP8 Attention 與 MLP,並擴展了 FA4 kernel 以支援端到端的 MXFP8 block-scaled MMA。

🎯 實務啟示

對於處理大規模推薦系統的工程師而言,GEM 的經驗指出:針對特定資料分佈(如 Jagged sequences)開發專用 Kernel,以及利用低精度(Low-precision)訓練來逼近硬體理論極限,是提升大規模基礎模型訓練效率的關鍵路徑。

🔗 來源

#MetaAI #MachineLearning #LLM #RecommendationSystem #GPU #DeepLearning #TrainingEfficiency #FlashAttention #ComputerVision #AIInfrastructure

原始資料 Meta AI Research · 收集於 2026-08-04
來源原標題
GEM Training: How Meta Doubled the Efficiency of Its LLM-Scale Ads Foundation Model
作者
原始標籤
AI Research · Data Infrastructure · ML Applications
原始連結
https://engineering.fb.com/2026/08/03/ml-applications/training-gem-at-llm-scale-meta-ads-recommendation-foundation-model/

摘要原文

GEM is the central recommendations foundation model behind Meta’s ads system. It has a hybrid architecture with trillions of sparse embedding parameters and billions of dense parameters. GEM is trained on ad content and user engagement data with two categories of features: sequence features (e.g., user activity history) and non-sequence features (e.g., user location, ad creative representation). Customized attention mechanisms are applied to each group independently, while also enabling cross-feature learning. The interplay between this hybrid architecture and rec-domain data properties is what makes GEM’s training uniquely challenging. Today’s data center GPUs and their software stacks are mostly optimized for LLM workloads, whereas recommendation workloads have a fundamentally different profile due to unique data characteristics and rich user & ads signal interaction patterns that make it extremely difficult to achieve high GPU compute utilization for training a foundational recommendation model of GEM’s size. Training GEM across thousands of GPUs with trillions of sparse embedding parameters and billions of dense parameters requires scaling efficiently, not just scaling up. Simply adding more GPUs does not translate to proportional speedup. In distributed training, E2E latency per training step is determined by: E2E Latency = Max across GPU Rank (Max(Local Compute Time, Communication Time)) Near-linear scaling requires four conditions: GEM’s workload threatens every one of these: Given the challenges outlined above, we needed a framework that turned a sprawling co-design effort into a small number of technical levers. We measure training efficiency through E2E MFU, which decomposes into two factors: E2E MFU = Local MFU (compute efficiency) × Scaling Ratio (scaling efficiency) These factors describe two related but distinct optimization problems. Local MFU (compute efficiency) measures how well a single GPU’s compute units are utilized — how close the workload runs to the hardware roofline. It is determined by kernel design, numerical precision, and how well the workload’s compute patterns (data dimensions, sequence lengths) map onto GPU architecture (Tensor cores, memory hierarchy, streaming multiprocessor scheduling). Scaling Ratio (scaling efficiency) measures how much single-GPU performance is retained when distributing across thousands of GPUs. A scaling ratio of 1.0 means perfect linear scaling; in practice, communication overhead, load imbalance, straggler effects, and activation recomputation from memory pressure all erode it. To isolate local MFU, we run model layers individually on a single GPU and compute a weighted average MFU without activation recomputation or communication exposure. The scaling ratio is derived as the ratio between local and E2E MFU. This decomposition matters because it lets us treat compute efficiency and scaling efficiency as related but distinct optimization problems, each with its own dedicated set of techniques: Both must be addressed to maximize end-to-end MFU. To address the recommendations-system-specific challenges mentioned above and push up GPU FLOPS utilization, we built a custom kernel library and an ultra-low-precision training recipe custom-built and optimized for recommendation workloads on the latest GPU hardware. FlashAttention is designed for dense, fixed-length sequences common in LLMs. In recommendation models, user sequences are inherently jagged — varying from hundreds to tens of thousands of tokens per sample — and padding to max length could waste up to 50% of compute. Standard FlashAttention implementations assume uniform sequence lengths for efficient tiling and parallelization; with jagged inputs, naive approaches either pad (wasting compute) or leave SMs idle when short sequences finish early. We developed JFA, a custom FlashAttention implementation that operates directly on variable-length jagged tensors, eliminating padding overhead while supporting rec-specific features such as custom attention biases, asymmetric query/key-value lengths, and efficient backward passes. We evolved JFA through four generations, progressively closing the gap from being slower than padded SDPA (scaled dot-product attention) to matching SOTA CUDA/Cutlass performance on latest-generation GPUs: JFA v4 (TLX) achieves 40-140% TFLOPS improvement over JFA v2, which delivers consistent gains under production jagged distributions (sparsity 0.5), contributing to 18.5% relative local MFU gain and 12% QPS gain. GEM uses diverse attention-like interaction patterns — self-attention, PMA, and cross-attention — that share a common structure: two matrix multiplications with an element-wise activation in between, but replace softmax with activations like GELU or SiLU. We unify these modules under a single GDPA kernel optimized for production RecSys training workloads on latest generation GPUs. Existing FlashAttention kernels are designed for LLM-style dense, long-sequence inputs and perform poorly under real production traffic. We observed a 2.6x forward performance gap and up to 4x worst-case gap between real-world workloads and synthetic benchmarks driven by short/asymmetric K/V sequences, jagged inputs, and large batch sizes that break pipeline occupancy assumptions. We redesigned the kernel pipeline, scheduling, and math to close the performance gap between real-world traffic and hardware roofline. With these optimizations, the optimized GDPA kernel achieves 2x forward speedup (1,145 BF16 TFLOPs, ~97% Tensor Core utilization) and 1.6x backward speedup over baseline. Under short K/V production settings, it achieves up to 3.5x forward speedup over Flash Attention 4 (FA4). Applied across the full model, these kernels deliver over 30% end-to-end training throughput improvement. For GEM self-attention, the core efficiency challenge was scaling long user sequences without paying the quadratic cost of full attention. We first moved the layer from full self-attention to sliding-window attention, limiting each token to nearby events and reducing complexity from O(L 2 ) to O(L * window). This made longer sequences practical. The Sliding Window Attention (SWA) kernel skipped off-window tiles in JFA and reduced long-sequence self-attention latency by up to 68% with neutral NE (normalized entropy, a model-quality metric) . We then pushed the structure further with block-aligned attention. Since GEM could safely use fixed 64-token blocks, each Q block only attends to its corresponding K/V block, turning attention into independent 64×64 problems. This removes the partial-window masking and multi-tile iteration still present in SWA, and lets a dedicated TLX kernel eliminate FlashAttention overheads such as online softmax correction, logsumexp HBM traffic, and separate Di preprocessing. Fusing RoPE backward into the attention epilogue removes another memory-bound kernel and keeps gradients in FP32 registers. Together, TLX block attention + fused rotary improves self-attention layer MFU by +30.6% over Triton block attention, or roughly +44% over the SWA baseline. On a GPU, lower precision directly translates to higher Tensor core throughput. For the latest generation GPU, FP8 delivers 2x peak FLOPS over FP16, and FP4 delivers 4x. We expect the peak FLOPS of low precision to increase faster in next-generation GPUs. This makes low-precision training increasingly attractive as hardware vendors scale low-precision FLOPS faster than FP16. However, making low-precision training work without quality regression — addressing both numerical stability and quantization overhead — remains an industry-wide challenge. We developed MXFP8 Attention and MLP with numerical stability enhancement, which addressed both training stability and quantization overhead. We extended the FA4 kernel with end-to-end MXFP8 blockscaled MMA for both forward and backward passes leveraging latest generation GPUs’ native support for low precision.

tencent/hy3:free 自動生成