Skip to content

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

Together AI 11 min read Research hardMaster

FlashAttention-4: Algorithm and Kernel Pipelining Co-Design for Asymmetric Hardware Scaling

FlashAttention-4 is an attention kernel co-designed for Blackwell GPUs, where tensor core throughput grew much faster than the exponential (SFU) units and shared memory bandwidth. A feeds-and-speeds analysis shows the forward pass is bottlenecked by softmax exponentials and the backward pass by shared memory traffic, not by MMA speed. The forward pass addresses this with ping-pong Q tiles, a dedicated correction warpgroup, conditional online-softmax rescaling, and exp2 computed partly in software through Cody-Waite range reduction and a cubic polynomial on FMA units. The backward pass keeps intermediates in tensor memory, uses 2-CTA MMA with a DSMEM exchange of dS to cut shared memory traffic and halve dQ atomics, and adds an LPT tile scheduler and a deterministic mode. On B200 with BF16 it reaches up to 1605 TFLOPs/s (71% utilization), up to 1.3× faster than cuDNN 9.13 and 2.7× faster than Triton, and is written in CuTe-DSL.

Assumes: GPU kernel programmingFlashAttention online softmaxtensor cores and GEMM tilingCUDA memory hierarchy

Related posts

  • We reverse-engineered Flash Attention 4

    Modal hardMaster

    Flash Attention 4, Tri Dao's attention kernel for Nvidia Blackwell GPUs, reportedly runs about 20% faster than cuDNN's closed-source attention kernels. Its main change is a far more complex warp-specialized asynchronous pipeline: Load, MMA, Softmax, Correction and Epilogue warps hand tiles through shared and Tensor Memory, synchronized by producer/consumer barriers. Two math tricks add to the gain. A cubic polynomial exponential runs on CUDA Cores to avoid queueing on the scarce Special Function Units, and a smarter online softmax rescales only when the running max changes enough to matter, reportedly cutting rescaling work by 10x. The authors read the released source and argue that programmer-managed asynchrony is pushing GPU programming toward tile-based DSLs such as CuTe, CUTLASS, Gluon and CuTile.

  • Making FlashAttention-4 faster for inference

    Modal hardMaster

    Modal engineers extended the FlashAttention-4 kernel for decode-heavy LLM inference on Blackwell GPUs through two kinds of change: new parallelism strategies, such as split-KV parallelism across the key/value dimension, and support for irregular memory access via cp.async in place of TMA bulk loads. FP8 inputs gave up to 1.16x throughput over bf16, likely limited by the softmax, which still runs at higher precision. Arbitrary KV page sizes help prefix sharing, reduce fragmentation and suit speculative decoding, and a transposed warp-level address-generation scheme made them up to 2.4x faster. Split-KV raised small-query memory throughput by up to 4.37x, keeping SMs busy that the original query-parallel design left idle.

  • Key research and product announcements at the AI Native Conf

    Together AI hardMaster

    Together AI announced seven research and product releases spanning GPU kernels, reinforcement learning infrastructure and inference optimization. FlashAttention-4 targets NVIDIA Blackwell and is reported 2.7x faster than Triton and 1.3x faster than cuDNN 9.13. A single-kernel Megakernel cut a voice agent's time-to-first-64-tokens from 281ms to 77ms, and together.compile beats torch.compile by 41% on a Flux Kontext benchmark. ThunderAgent schedules whole agentic workflows to avoid KV cache thrashing and leaked tool sandboxes, ATLAS-2 retrains speculative decoders online from live traffic, and cache-aware prefill-decode disaggregation sends warm and cold requests to separate tiers over an RDMA KV cache for 35-40% higher QPS.

  • Profiling in PyTorch (Part 3): Attention is all you profile

    Hugging Face mediumAdept

    Profiling attention variants in PyTorch on an A100 shows how each implementation appears in profiler traces. Naive attention launches matmul, mul, masking, softmax and matmul kernels plus a hidden Memcpy from out-of-place masked_fill; switching to in-place masked_fill_ removes that kernel under no_grad. SDPA's math backend turns out 3.7x slower than the naive version: it launches 20 kernels, upcasts to FP32 sgemm on CUDA cores instead of bf16 Tensor Cores, rebuilds the causal mask every call, and uses a NaN-safe softmax. Fused backends such as the efficient (CUTLASS fmha) backend collapse attention into a single kernel, and kernel names can be read to tell which hardware path each backend takes.

  • Learn the Hugging Face Kernel Hub in 5 Minutes

    Hugging Face mediumAdept

    Hugging Face's Kernel Hub and `kernels` library let PyTorch code download pre-compiled, optimized GPU kernels such as FlashAttention, activations, RMSNorm and quantization kernels with a single `get_kernel` call. The library matches the binary to the installed Python, PyTorch and CUDA versions, which avoids source builds that for FlashAttention can need about 96 GB of RAM and hours of compilation. The walkthrough checks a fast GELU kernel against PyTorch and swaps a Triton LlamaRMSNorm into a simple model with the `use_kernel_forward_from_hub` decorator. It then benchmarks the kernel against a plain PyTorch RMSNorm using CUDA events.

The quest for software engineering knowledge.

Look:
Layout: