Kernel Fusion & Recomputation: Dual Speedup Strategies

FlashAttention boosts speed by fusing multiple attention sub-operations (like matrix multiplication and softmax) into a single GPU kernel, minimizing redundant HBM access. Additionally, it strategically recomputes intermediate gradients during the backward pass instead of storing them, further reducing memory traffic and accelerating processing.

The top 3

  1. Top 3 Kernel Fusion Targets for LLM Performance: Fusing operations like Matrix Multiplication with Activation functions (e.g., MatMul-GELU), Layer Normalization with Linear layers, and sequences of element-wise operations are crucial for LLMs, cutting memory bandwidth by 20-40% and improving inference speed by 15-30% by retaining data in fast on-chip memory.
  2. Recomputation's Memory-Compute Trade-offs Quantified: Full activation recomputation offers maximal memory savings but incurs a significant computational overhead of approximately 30-50% additional FLOPs. In contrast, selective recomputation, by targeting memory-intensive parts like the self-attention block, achieves high memory reduction with minimal compute cost, sometimes as low as 2-7% overhead.
  3. Leading Platforms for Kernel Fusion & Recomputation: NVIDIA's TensorRT and PyTorch's `torch.compile` are prominent examples of ML compilers and frameworks that extensively use kernel fusion. For recomputation, NVIDIA's Megatron-LM and NeMo-Megatron frameworks, along with specialized libraries like FlashAttention, have pioneered and integrated these techniques to train and deploy large language models efficiently.

Sources

Open the full topic