TLX kernel outperforms FlashAttention-4 on jagged attention for Blackwell

News PyTorch Blog · Source account, not independently verified by us.

A Jagged Flash Attention kernel built with Triton Low-level Extensions (TLX) outperforms FlashAttention-4 on NVIDIA’s B200 for the variable-length shapes used by Meta’s Generative Ads Model (GEM), according to the PyTorch Blog. The reported gains are about 13% in the forward pass and 50% in the backward pass. The approach aims to make Blackwell performance more accessible without requiring a hard-to-extend CUDA or CuteDSL kernel.

Jagged attention processes sequences of different lengths in packed form instead of padding them to a fixed size. The post says padding can waste up to 50% of compute. The kernel therefore operates directly on packed Q, K and V tensors, alongside an offsets tensor that records sequence boundaries. Attention is GEM’s slowest individual kernel; in the production configuration described, a dense Q is shared across a batch, so its gradient must also be accumulated across the batch.

TLX extends Triton’s higher-level programming model with explicit control over memory, barriers and asynchronous work. The team assigns tasks to specialized warps and overlaps operations including data loading, matrix multiplication and softmax. The resulting kernel is about 3,200 lines of Triton code, compared with roughly 10,000 lines for the FA4 implementation in CuteDSL, according to the post. Other techniques distribute uneven sequence workloads across processing units and double-buffer gradient stores.

The comparison used bfloat16 on B200 and the FA4 version identified in the post as the May 2026 release. Kernel code is available in Meta’s GitHub repository; the original post also explains the individual optimizations and measurement methods. Original source: PyTorch Blog

🇬🇧 https://pytorch.org/blog/optimizing-jagged-flash-attention-with-tlx-the-road-toward-sota-fa4-on-blackwell

Leave a Comment

The weekly brief: selected developments, projects and videos