arXiv:2611.07496cs.DCNov 2026

Manuscript Offprint

arXiv:2611.07496

ZYFA: Speed and Accuracy of FP8 FlashAttention on AMD CDNA4

Quentin Anthony, Ganesh Bikshandi, Praneeth Medepalli, Stephen Ebert

Quentin Anthony ∗^{*} Ganesh Bikshandi Praneeth Medepalli Stephen Ebert

Zyphra

San Francisco, CA

Abstract—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, so a GPU kernel's total speedup from FP8 shrinks as other operations take a larger share of the overall kernel time. For example in attention, the softmax between the two matrix multiplications is on vector units which FP8 does not accelerate. On the AMD Instinct MI355X, the vendor's AITER kernels (AMD's library of inference kernels) reach 39% of peak FP8 matrix throughput at 32K tokens, compared with 49% in BF16. Unlike NVIDIA's Hopper and Blackwell GPUs, the MI355X also does not track the completion of matrix instructions in hardware, so fine-grained instruction order must be carried out via more manual methods like assembly instruction ordering, which is vital for attention kernels such as overlapping the softmax with the matrix multiplications. Finally, attention is more numerically sensitive to quantization than feed-forward layers, so considerable numerical analysis must be done to ensure fidelity. To overcome these challenges, 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, since an FP8 bit pattern approximates a scaled base-2 logarithm of its raw value; (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, so that far fewer small probabilities round to zero, and normalizing by the sum of the rounded probabilities, so that the attention weights still sum to one. On attention inputs captured from three representative models and timed at sustained clock speeds (the lower, steady clock that the GPU settles at after a few seconds of back-to-back launches), ZYFA achieves 1.16–1.76× the throughput of AITER. On the random Gaussian inputs of kernel benchmarks at 32K tokens, ZYFA achieves 1.26–1.37× the throughput of AITER at head dimension 128 and 1.99× 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, where ZYFA takes fewer clock cycles than AITER's kernel but runs at a lower per-cycle clock speed. At head dimension 128, ZYFA's numerical error is within a few percent of that of AMD's Composable Kernel and Triton kernels and 62–78% lower than that of AITER's. The source code is available at https://github.com/Zyphra/zyfa.

I. INTRODUCTION

The attention operation remains both widespread and computationally expensive. The longer the input context to a model, the larger the share of prefill time that attention takes, and long contexts are becoming increasingly common: coding agents work across large repositories [Jimenez et al., 2024], and genomic models read long DNA sequences [Nguyen et al., 2024]. At these lengths attention often dominates the prefill phase of autoregressive inference. IO-aware algorithms like FlashAttention perform the same arithmetic as standard attention, but stream blocks of keys and values through on-chip memory and keep a running softmax for each query, so that the score matrix never reaches the comparatively slow high-bandwidth memory (HBM) of the GPU [Dao et al., 2022, Dao, 2024]. The speed of attention then depends on how well its GPU kernel can keep the arithmetic units of the GPU busy, and because the throughput of matrix or tensor cores has increased significantly faster in subsequent GPU generations than all other hardware elements, the kernel engineer's primary focus has shifted to keeping them fed. FlashAttention-3 hides the softmax behind asynchronous matrix instructions on Hopper GPUs [Shah et al., 2024], and FlashAttention-4 approximates portions of the exponentials with polynomials on Blackwell GPUs, whose matrix hardware units grew faster than their exponential units [Zadouri et al., 2026]. Low precision worsens this hardware gap further. Recent GPUs execute 8-bit floating-point (FP8) matrix instructions at twice the theoretical BF16 rate [Micikevicius et al., 2022, Advanced Micro Devices, 2025b], so FP8 attention could, in principle, take half the time of BF16 attention if it were purely bound by its matrix multiplications.

However, on the AMD Instinct MI355X, FP8 attention gains much less than this in practice. At 32K tokens on random Gaussian inputs, the FP8 attention kernel of AITER, AMD's library of inference kernels [AMD, 2025a], reaches 39% of the FP8 datasheet peak, while its BF16 kernel reaches 49% of the BF16 peak. Accuracy is a second concern. DeepSeek-V3, for example, trains its linear layers, including the experts, in FP8 but keeps attention in higher precision because attention is more numerically sensitive [DeepSeek-AI, 2024b]. This paper asks what limits the FP8 attention operation on the MI355X GPU, how to work around these limits, and how the error of FP8 attention can be sourced and mitigated.

The first limit is the softmax. FP8 doubles the speed of the matrix products but not of the softmax operation. Each score still needs an exponential, and an FP8 kernel must also convert each probability to 8 bits before the second matrix product, and both of these operations are performed on vector

∗^{*}Corresponding author: quentin@zyphra.com units whose speed is the same in both FP8 and BF16. For 32 queries against a block of 128 keys at head dimension 128, the two matrix products take 2048 matrix-unit cycles in BF16 and 1024 in FP8, while the softmax takes 896 vector-unit cycles in FP8, even more than the 768 it takes in BF16, because converting a probability to FP8 costs more than converting it to BF16 (see Section III-B). Having nearly the same clock cycles spent in vector units and matrix units is troubling for the programmer, since one must overlap the softmax with matrix products in order to keep the matrix cores busy. FP8 therefore requires almost perfect overlap (1024 matrix cycles against 896 vector cycles), but BF16 has considerable slack (2048 against 768) that makes implementation easier. In our thread traces of AITER's FP8 kernel (cycle-by-cycle records of every instruction that a wave issues), we see the matrix unit idle for 31.7% of cycles while the softmax runs. NVIDIA's Hopper and Blackwell GPUs provide asynchronous matrix instructions whose completion events are tracked by hardware [Shah et al., 2024, Zadouri et al., 2026], so the hardware tells a kernel when a matrix product is ready and overlap is much easier to organize by the kernel programmer. On the MI355X, however, matrix instructions keep running while the wave that issued them (a group of 64 threads that issue instructions together) issues other instructions, and the hardware does not track their completion, so the overlap depends entirely on the order in which the kernel issues its instructions, whose order must also ensure that each matrix instruction has finished before its result is read (Section II-A). We find this often necessitates raw GPU assembly kernels, whose development can be eased by generator functions written in higher-level languages like Python.

The clock speed is the second limit one encounters when implementing attention. Under sustained load, the MI355X lowers its clock, and since each bit flip draws current, the clock rate falls as more operand bits change from one instruction to the next. This clock behavior is an important factor for attention, since as we remove softmax as a bottleneck, the matrix cores can do more arithmetic per cycle, which is more bit flips and therefore a lower clock. This effect is further complicated by the fact that real-world inputs have very different distributions from classical synthetic kernel inputs, such as random Gaussian values, which one uses for development or kernel comparison. Speed and numerics are therefore closely intertwined. For example, we found that AITER lets more probabilities underflow to zero on some real model inputs, and zeros switch fewer bits in subsequent arithmetic, so AITER will have a higher clock rate but worse numerics. Achieving both high performance and low numerical error is therefore the primary goal of our work.

We measure the low-level instruction costs and the clock behavior of the MI355X and use them to design ZYFA, causal forward kernels in BF16 and FP8. They support head dimension 128 and the head shape of multi-head latent attention (MLA) in DeepSeek-V2 [DeepSeek-AI, 2024a], with query-key dimension 192 and value dimension 128, the per-head form of

MLA that prefill uses. 1^{1} Our FP8 kernels attempt to shrink the number of cycles spent in softmax by exploiting the FP8 format to perform a similar numerical operation to the exponential, specifically by using the fact that the exponent bits of an FP8 number already encode an exponential. Read as an integer, the 8-bit bit pattern (or code) of a positive e4m3 number, the FP8 format with 4 exponent and 3 mantissa bits, grows by 8 each time the value doubles, so it is close in effect to a scaled and shifted base-2 logarithm of the value being represented. The code of a probability p=2xp = 2^x, where xx is the score minus the row maximum in base-2 units, is therefore close to 8x8x plus a constant, the same relation that Schraudolph's fast exponential uses for IEEE floating-point numbers [Schraudolph, 1999]. At head dimension 128 the FP8 kernel computes this code with one multiply-add and one integer conversion, which we call lean P. Lean P replaces both the exponential and the floating-point conversion, and lowers the vector cycles per block from 896 to 384. It is an approximation that raises the output error of one attention call to 1.22−1.36×1.22-1.36\times that of exact P, which evaluates the exponential, but the kernel's error stays below that of AITER's kernel, at 0.26×0.26\times in geometric mean (Section VI-B). Essentially, lean P trades a small amount of numerical accuracy for speed. Lean P is optional, and ZYFA uses it by default at head dimension 128. The kernel at the MLA shape keeps exact P only because there lean P falls just below the signal-to-noise threshold of our correctness test in 1 of 24 configurations, although it matches exact P end to end (Section VI-B).

Two further changes keep the FP8 probabilities as accurate as possible. In a long row of the attention matrix most probabilities lie far below the largest one, often below 2−62^{-6}, where e4m3 values lose precision, or below 2−102^{-10}, where they underflow to zero and we lose information. The kernels therefore multiply each block of 64 probabilities by a power of two so that its largest value is close to 1, and the scaled FP8 matrix instruction of CDNA4 undoes the factor at no cost. The kernels also keep each output as a weighted average whose weights sum to one. The output divides ∑jpjvj\sum_j p_j v_j by ∑jpj\sum_j p_j, and the numerator uses the probabilities after rounding to FP8. If the denominator sums the unrounded probabilities, as in AITER's kernel, probabilities that underflow to zero still count in the denominator, so every output row shrinks slightly, which accounts for much of the larger error of AITER's FP8 kernel (Section VI-B). ZYFA divides by the sum of the rounded probabilities instead, and it computes this sum with one extra matrix instruction that multiplies the FP8 probabilities by a vector of ones. The extra instruction adds 6% to the matrix work and removes vector additions from the vector unit, which is the principal bottleneck in FP8.

Finally, our assembly schedule pairs two waves, AMD's

1^{1}MLA caches one compressed latent vector per token instead of per-head keys and values. Prefill expands the latent vectors into per-head keys and values and runs standard attention with these dimensions. Decoding instead folds the expansion of the keys into the query and attends over the latent vectors directly, with a query-key dimension of 576 and a value dimension of 512 that all heads share.

counterpart of warps, on each SIMD unit and runs the softmax of one wave during the matrix instructions of the other. With lean P the wave that computes the softmax finishes its work before the wave that issues the matrix instructions does, so the matrix instructions determine the speed of the loop over blocks of keys.

The contributions of this work are as follows.

  1. A characterization of the MI355X hardware in the context of attention (Section III), covering the vector cost of each class of instruction, the overlap capability of vector and matrix work on a single SIMD, and clock dependencies on operand values, expanding on the detail provided by the official instruction set architecture (ISA) documentation.

  2. ZYFA, whose FP8 kernels achieve 1.16–1.76× the throughput of AITER's default kernels on activations captured from real models at sustained clocks and 1.26–1.99× on Gaussian inputs at 32K tokens (Sections IV and VI-A).

  3. A measurement of the error of single attention calls (Section VI-B), which shows that at head dimension 128 ZYFA's FP8 error is within a few percent of that of Composable Kernel and Triton and 62–78% lower than that of AITER's assembly kernel.

  4. An account of FP8 attention error in three full models (Section VI-C). Most of it comes from quantizing the inputs rather than the probabilities and is spread over most heads, so keeping the most sensitive heads in BF16 is not a useful middle ground. On Mistral-7B and Qwen3-8B, even 90% of heads in BF16 does not sufficiently match BF16 accuracy, and by then attention takes as long as all-BF16. A Hadamard rotation of Q and K instead roughly halves the error from quantizing the inputs at almost no cost.

Table II defines the terms that the rest of the paper uses. The source code is available at https://github.com/Zyphra/zyfa.

References (31)