Meta has introduced a rewritten Jagged Flash Attention (JFA) kernel for NVIDIA Blackwell (B200) GPUs, implemented using Triton Low-level Extensions (TLX). The work targets the attention mechanism inside Meta's Generative Ads Model (GEM), where sequence lengths vary across users and traditional padding can waste up to 50% of compute cycles. According to PyTorch's engineering blog, the high-level TLX implementation achieves state-of-the-art efficiency while keeping the codebase significantly smaller than low-level CUDA or CuteDSL kernels.
Addressing Hardware and Maintainability Trade-Offs
Reaching maximum throughput on NVIDIA's Blackwell architecture typically requires hand-written CuteDSL or CUDA code. While fast, these specialized kernels often exceed 10,000 lines of complex code, making them difficult for modeling engineers to modify, extend, or fuse with other operations. Standard Triton compilers automate hardware scheduling, but they lack the granular control required to avoid tensor-core stalls during attention operations.
TLX introduces hardware-aware primitives directly into Triton's tile-based programming interface. This allows developers to explicitly manage shared and tensor memory allocations, sequence asynchronous warp tasks, and configure barriers without dropping down to C++ or CUDA. Meta's TLX-based JFA kernel comprises approximately 3,200 lines of readable Python-level code, roughly one-third the size of comparative CuteDSL implementations.
Architectural Changes and Memory Optimizations
To prevent tensor-core idling, Meta restructured the kernel into specialized asynchronous tasks. Dedicated warps handle TMA data loading, matrix multiplications, softmax calculations, and memory stores concurrently. Shared memory buffers for key and value tensors are triple-buffered, allowing input loads to run ahead of execution. Dynamic memory buffers for intermediate scores and statistics are assigned overlapping lifetimes to maximize available memory space.
The team introduced several specific targeted optimizations to reduce runtime bottlenecks:
– **Jagged Tile Load Balancing:** To resolve work imbalances caused by variable sequence lengths, host-side sorting schedules non-uniform workloads across streaming multiprocessors (SMs) using a boustrophedon pattern. Dynamic distribution is further managed at runtime using NVIDIA's Cluster Launch Control (CLC).
– **Multi-Stage Staging and Early Release:** Epilogue stores for broadcasted query gradients employ a double-buffered staging pipeline to hide reduction latency. Tensor-memory buffers are freed early—before final stores complete—allowing matrix multiplication warps to begin subsequent operations immediately.
– **Loop Peeling:** By isolating mask conditions into a separate tail loop, the compiler statically removes masking overhead from the primary attention loop. This reduces register pressure and eliminates local-memory spilling in register-heavy warps.
– **Collaborative Matmuls:** The backward pass adapts a 2-CTA paired strategy, where two cooperative thread blocks across a cluster share workload over distributed shared memory, increasing tensor-core utilization.
Benchmark Results and Performance Metrics
Benchmarking conducted in bfloat16 on NVIDIA B200 hardware shows significant performance gains for production workload shapes. Against a May 2026 version of FlashAttention-4 (FA4), the TLX implementation improved average speeds on jagged sequence shapes by approximately 13% during the forward pass and around 50% during the backward pass. On standard dense inputs, the implementation delivered competitive performance, reaching roughly 87% of FA4's forward throughput while outperforming FA4's backward pass by approximately 17%.
The underlying code has been made available via Meta's public code repository.
AI-generated editorial illustration; not a documentary photograph.
Source: Optimizing Jagged Flash Attention with TLX: The Road Toward SOTA FA4 on Blackwell

Leave a Reply