Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Meta Engineering 8 min read Case study hardMaster

How Meta animates AI-generated images at scale

Meta made its Meta AI image-animation feature fast enough for billions of users by stacking model optimizations. These include bfloat16 precision, expanding temporal-attention context after the cross-attention projections, DPM-Solver sampling down to 15 steps, and combined guidance and step distillation that turned 32 multi-pass teacher steps into 8 single-pass student steps. TorchScript freezing came first, followed by a move to PyTorch 2.0 compile with context and sequence parallelism. In serving, a load-aware routing table keeps requests in-region and offloads to progressively farther regions as load nears capacity. Because each GPU accepts only one request at a time, retry-based probing for free GPUs started to cascade until execution delay and exponential backoff were added.

Assumes: diffusion modelsclassifier-free guidancePyTorchretries and backoff

Related posts

  • Meta Andromeda: Powering the Next Generation of Ads Retrieval Through Model-System Co-Design

    Meta Engineering hardMaster

    Meta's next-generation Andromeda ads retrieval engine co-designs model, system and GPU hardware to score every eligible ad with near ranking-level quality at over one billion ads per second per GPU server, a 100x lift over the 2024 system. A retrieval mixture-of-experts architecture (ensemble of user-tower experts plus an ad-aware attention gating router) cuts inference FLOPs ~300x. A single fused kernel keeps per user-ad intermediates in registers and shared memory to avoid HBM traffic, reaching over 10B ads/sec on one GH200. Co-locating index matching, scoring and top-K on the same GPU cuts network traffic ~100x. NVIDIA-optimized kernels hit ~85% of peak HBM bandwidth, and INT8 adds up to 2x throughput at FP16-equivalent accuracy.

  • Meta Adaptive Ranking Model: Bending the Inference Scaling Curve to Serve LLM-Scale Models for Ads

    Meta Engineering hardMaster

    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. Key techniques include in-kernel broadcast of request-level embeddings, the Wukong Turbo architecture refinements, GPU-offloaded feature preprocessing, selective FP8 post-training quantization, operator fusion with grouped GEMM, and multi-GPU embedding sharding, reaching 35% MFU across heterogeneous hardware. Launched on Instagram in Q4 2025, it delivered +3% ad conversions and +5% CTR for targeted users.

  • Run FLUX.1-dev three times faster

    Modal mediumAdept

    FLUX.1-dev image generation on Modal drops from ~6.75s to under three seconds per 1024x1024 image. About 1.5x comes from standard optimizations: torch.compile with max-autotune, fused QKV projections and channels-last memory layout. Another 2x comes from First Block Caching (via ParaAttention, based on TEACache), which skips denoising steps whose early-block residual change falls below a threshold. A threshold of 0.12 gave a good quality/speed tradeoff. The tens of minutes of compile time added to cold starts were cut roughly 30x by persisting Inductor, Triton and CUDA caches on a volume and using Modal memory snapshots.

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

    Meta Engineering hardMaster

    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.

  • Meta’s Generative Ads Model (GEM): Scaling the Central Model and Compute Engine for Frontier Ads AI

    Meta Engineering hardMaster

    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. Its new Kunlun architecture uses block-sparse attention, a GDPA kernel that unifies attention-like ops, MoE-style cross interaction with expert parallelism, component skipping (43% fewer FLOPs) and unified user sequences. Together these support 2.5x model complexity and an LLM-like scaling law, with prediction quality following a power law in sequence length. Intelligence reaches latency-bound vertical models through LoopFM precomputed structured representations, which double transfer effectiveness over plain distillation, and through Solaris speculative precomputation of user-ad embeddings with hierarchical fallback. Custom low-precision kernels and 5D parallelism reach 20-25% MFU at 4x the training FLOPs.

The quest for software engineering knowledge.

Look:
Layout: