Making FlashAttention-4 faster for inference
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.
Related posts
- FlashAttention-4: Algorithm and Kernel Pipelining Co-Design for Asymmetric Hardware Scaling
Together AI hardMasterFlashAttention-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.
- 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.
- Optimizing your LLM in production
Hugging Face mediumAdeptServing billion-parameter LLMs efficiently comes down to three levers: lower precision, Flash Attention, and inference-friendly architectures such as ALiBi, rotary embeddings, Multi-Query Attention and Grouped-Query Attention. Weights need roughly 2 GB of VRAM per billion parameters in bfloat16, and measurements on OctoCoder (~15B parameters) show peak memory dropping from about 29 GB in bfloat16 to 15 GB with 8-bit and 9.5 GB with 4-bit bitsandbytes quantization, with little output change but slightly slower inference. Flash Attention addresses self-attention's quadratic memory growth with sequence length by restructuring the computation to make better use of GPU memory. Code examples in Hugging Face Transformers accompany each technique.
- Key research and product announcements at the AI Native Conf
Together AI hardMasterTogether 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 mediumAdeptProfiling 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.