Zyphra 发布 ZYFA:提升 AMD MI355X 上 FP8 FlashAttention 速度与精度
ZYFA: Speed and Accuracy of FP8 FlashAttention on AMD CDNA4
AMD MI355X 跑 FP8 attention 一直打不满峰值,Zyphra 的 ZYFA 内核比官方 AITER 快 1.16-1.76 倍还更准,代码开源可以直接试。
Attention 在长上下文 prefill 中是计算瓶颈,AMD Instinct MI355X 的 AITER 内核在 32K tokens 下只达到 FP8 峰值矩阵吞吐的 39%,低于 BF16 的 49%。Zyphra 的 ZYFA 用直接乘加代替指数运算、ping-pong 调度让 softmax 与矩阵乘重叠、2 的幂缩放后再舍入三项技术优化 FP8 FlashAttention。在三个模型的真实注意力输入上,ZYFA 达到 AITER 的 1.16-1.76 倍吞吐;在 head dimension 128 时数值误差比 AITER 低 62-78%,与 Composable Kernel 和 Triton 相近。源代码已在 GitHub 开源。
ZYFA: Speed and Accuracy of FP8 FlashAttention on AMD CDNA4
Attention is a core building block of frontier models and often dominates compute-bound prefill at long context. FP8 matrix instructions offer twice the peak throughput of BF16, but they accelerate only matrix multiplication, and the softmax between the two matrix multiplications of attention runs on vector units that FP8 does not accelerate. On the AMD Instinct MI355X, the vendor's AITER kernels reach 39% of peak FP8 matrix throughput at 32K tokens, compared with 49% in BF16. Attention is also more numerically sensitive to quantization than feed-forward layers, and unlike NVIDIA's Hopper and Blackwell GPUs, the MI355X does not track the completion of matrix instructions in hardware, so overlapping the softmax with the matrix multiplications depends on instruction order. We present ZYFA, prefill kernels for the MI355X built on three techniques: (1) computing each FP8 probability directly from its score with a multiply-add and an integer conversion instead of an exponential; (2) a ping-pong schedule in which one group of threads computes its softmax while another executes its matrix multiplications; and (3) scaling each block of probabilities up by a power of two before rounding, and normalizing by the sum of the rounded probabilities. On attention inputs captured from three models and timed at sustained clock speeds, ZYFA achieves 1.16-1.76x the throughput of AITER. On the Gaussian inputs of kernel benchmarks at 32K tokens, it achieves 1.26-1.37x at head dimension 128 and 1.99x for DeepSeek-style multi-head latent attention. The sustained clock of the MI355X depends on operand values, so throughput on random inputs does not reliably predict throughput on real model activations. At head dimension 128, ZYFA's numerical error is within a few percent of that of Composable Kernel and Triton and 62-78% lower than that of AITER's. The source code is available at https://github.com/Zyphra/zyfa.
- Tri Dao (FlashAttention)11-05 19:01原文