Skip to content

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

Modal 18 min read Deep dive hardMaster

We reverse-engineered Flash Attention 4

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.

Assumes: Transformer attentionCUDA programming modelGPU memory hierarchyasynchronous programming

Related posts

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

    Together AI hardMaster

    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.

  • 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.

  • Profiling in PyTorch (Part 2): From nn.Linear to a Fused MLP

    Hugging Face hardMaster

    Profiling an nn.Linear on an A100 shows a single cuBLAS/CUTLASS GEMM kernel with the bias folded in as an epilogue via aten::addmm, while aten::t only rewrites strides on the CPU and launches nothing. As a result, torch.compile has little to fuse for a lone Linear; it mainly removes CPU dispatch overhead by hard-coding strides, and the kernel's layout suffix (e.g. tn) shows how the transpose is absorbed. Stacking three Linears into a GeGLU MLP yields five kernels per forward pass: three GEMMs, each preceded by an occupancy query, plus separate GELU and multiply pointwise kernels. Reading kernel names and the profiler table shows which ops actually reach the GPU and where fusion could help.

The quest for software engineering knowledge.

Look:
Layout: