What problem does it solve?
Transformer attention becomes prohibitively slow and memory-hungry for long sequences, causing training and inference to be limited by GPU memory (OOM) or poor throughput. This Skill explains how to enable Flash Attention and related FP8 optimizations to reduce attention memory from O(N²) to near O(N) and achieve multi-fold speedups.
Core Features & Use Cases
- Native PyTorch SDPA integration: Replace standard attention with torch.nn.functional.scaled_dot_product_attention for automatic Flash-backed execution on supported PyTorch versions.
- flash-attn library features: Use flash-attn for sliding-window/local attention, multi-query attention, and H100 FP8 kernels for maximal performance.
- H100 FP8 and production tuning: Steps to verify H100 availability, convert tensors to FP8 formats, and benchmark performance for long-context training and inference.
- Use Case: Train or serve large autoregressive models (e.g., Llama, Mistral) with 4K–32K contexts where standard attention would OOM or be too slow.
Quick Start
Enable Flash Attention in your PyTorch model to accelerate attention and reduce GPU memory usage for long-context training or inference.