DeCo-Attention: Decompose to Compensate for Low-Precision Attention
Organizations: NVIDIA
Abstract
Self-attention over tens of thousands of tokens dominates the generation time of video diffusion transformers, because its cost grows quadratically with sequence length. The FP4 matrix products of modern GPUs can speed up attention, but the 4-bit rounding of the queries Q and the keys K introduces large errors. We show that the exponential in softmax amplifies the error of their product QK, which therefore dominates the attention error. We propose DeCo-Attention, a co-design of algorithm and system for low-precision attention. DeCo-Attention is training-free and compensates the rounding error of Q and K along a few principal directions found by a per-head eigendecomposition. The lightweight compensation terms are appended to Q and K as extra channels, so the FP4 matrix product corrects its own rounding error while it computes the attention scores. Once the products run in FP4, the softmax bounds the kernel, and we optimize the softmax so that the gain of FP4 computation translates into realized speedup. With QK in FP4, we implement DeCo-Attention with the rest of attention in FP8 on GB300 and VR200 and in FP4 on RTX PRO 6000. On Wan2.2, these kernels run 2.13x, 2.49x, and 2.82x faster than BF16 attention, and the whole generation runs 1.55x, 1.68x, and 1.80x faster. On four video generation models, the FP8 configuration achieves LPIPS comparable to prior 8-bit QK methods, and the fully FP4 configuration lower LPIPS than prior fully 4-bit kernels.
Figures & tables
| P | Codes from | Instr. | ||||||
| Hard | All | Hard | All | Hard | All | |||
| E4M3 | exp2 and rounding | 8 | 0.28 | 0.40 | 0.43 | 0.88 | 1.07 | 2.72 |
| ExpCast | 7 | 0.44 | 1.02 | 1.41 | 3.26 | 4.37 | 8.88 | |
| I-ExpCast | 6 | 0.50 | 0.68 | 0.54 | 0.93 | 1.11 | 2.72 | |
| E2M1 | exp2 and rounding | 8 | 1.56 | 2.01 | 1.59 | 2.09 | 1.69 | 2.64 |
| Direct-P | 4 | 4.11 | 5.06 | 4.11 | 5.06 | 4.11 | 5.06 | |
| Method | QK/PV | Wan2.2 | LongCat-Video | HunyuanVideo-1.5 | MiniMax-H3 | ||||||||
| PSNR | SSIM | LPIPS | PSNR | SSIM | LPIPS | PSNR | SSIM | LPIPS | PSNR | SSIM | LPIPS | ||
| BF16 | 16/16 | 24.54 | 0.850 | 0.112 | 30.09 | 0.929 | 0.038 | 18.98 | 0.709 | 0.241 | 21.40 | 0.752 | 0.186 |
| QK16PV8 | 16/8 | 20.66 | 0.748 | 0.197 | 23.50 | 0.817 | 0.107 | 16.04 | 0.601 | 0.352 | 20.19 | 0.717 | 0.217 |
| Per-tensor FP8 | 8/8 | 17.95 | 0.658 | 0.283 | 20.52 | 0.728 | 0.164 | 14.89 | 0.548 | 0.410 | 17.13 | 0.601 | 0.356 |
| MXFP8 | 18.01 | 0.662 | 0.278 | 20.50 | 0.732 | 0.163 | 14.06 | 0.521 | 0.451 | 16.85 | 0.590 | 0.365 | |
| SageAttention2 † | 20.3 | 0.730 | 0.206 | 23.1 | 0.793 | 0.122 | 15.6 | 0.581 | 0.382 | 19.9 | 0.723 | 0.252 | |
| Method | QK/PV | Wan2.2 | MiniMax-H3 | ||
| Hard | All | Hard | All | ||
| BF16 | 16/16 | 0.15 | 0.17 | 0.17 | 0.17 |
| SageAttention2, FP8 QK | 8/8 | 13.03 | 4.10 | 21.23 | 4.55 |
| VC-Attention, FP8 QK | 3.67 | 2.64 | 6.65 | 2.85 | |
| NVFP4 QK, FP8 PV | 4/8 | 30.56 | 10.57 | 28.92 | 10.69 |
| Attn-QAT | 30.19 | 10.60 | 28.25 | 11.10 | |
| Q-side term | K-side term | Wan2.2 | MiniMax-H3 | ||
| Hard | All | Hard | All | ||
| ✓ | ✓ | 2.80 | 3.73 | 6.31 | 4.40 |
| ✓ | 3.97 | 4.96 | 7.30 | 5.71 | |
| ✓ | 18.35 | 7.27 | 29.11 | 9.22 | |
| 18.70 | 8.10 | 29.40 | 10.00 | ||
| Kernel | Time (ms) | Speedup | SM clock (MHz) | Error (%) |
| BF16 attention | 124.3 | 1.00 | 1537 | 0.15 |
| NVFP4 QK, FP8 PV | 83.8 | 1.48 | 2070 | 30.56 |
| Our kernel, compensation only | 79.0 | 1.57 | 2017 | 2.92 |
| + I-ExpCast | 62.2 | 2.00 | 1777 | 2.94 |
| + Row sum in the PV MMA | 57.3 | 2.17 | 1612 | 2.94 |
| + Lazy rescale, | 55.8 | 2.23 | 1537 | 2.95 |
Appendix figures & tables30 assets
Supplementary material from the paper’s appendix.
Appendix
| Compensation | Wan2.2 | MiniMax-H3 | |||
| Hard | All | Hard | All | ||
| Keys with (%) | 7.4 | 1.3 | 17 | 4.8 | |
| ✓ | 2.1 | 0.19 | 5.0 | 0.32 | |
| Attention weight of these keys (%) | 0.67 | 0.095 | 7.1 | 1.4 | |
| ✓ | 0.017 | 0.0012 | 0.23 | 0.015 | |
| Error of Eq. 17 , median head (%) | 5.9 | 10.5 | 28.5 | 18.8 | |
| Rotation | Wan2.2 | MiniMax-H3 | |||
| Hard | All | Hard | All | ||
| Direction factor | 1.63 | 1.20 | 1.62 | 1.33 | |
| ✓ | 1.02 | 1.01 | 1.13 | 1.03 | |
| First-order error energy | 1.00 | 1.00 | 1.00 | 1.00 | |
| ✓ | 0.64 | 0.85 | 0.80 | 0.83 | |
| Basis | Tokens | -side term, | -side term, | ||||
| 16 | 32 | 64 | 16 | 32 | 64 | ||
| separate | all | 42.1 | 25.6 | 10.7 | 43.0 | 26.4 | 11.3 |
| shared | all | 44.6 | 27.8 | 11.9 | 45.7 | 28.7 | 12.6 |
| shared (Ours) | 1/256 | 46.9 | 30.8 | 14.3 | 47.8 | 31.3 | 14.9 |
| random | none | 87.4 | 74.8 | 49.6 | 87.4 | 74.8 | 49.6 |
| Rotation | Wan2.2 | MiniMax-H3 | |||
| Hard | All | Hard | All | ||
| Uncompensated | 30.12 | 10.29 | 28.14 | 10.82 | |
| ✓ | 18.57 | 8.00 | 30.14 | 9.98 | |
| Compensated | 3.56 | 3.57 | 5.45 | 4.19 | |
| ✓ | 2.10 | 3.45 | 5.90 | 4.19 | |
| Whole kernel | 3.94 | 3.83 | 5.82 | 4.40 | |
| Rotation | Wan2.2 | MiniMax-H3 | |||
| Hard | All | Hard | All | ||
| First order, compensated | 30.03 | 9.75 | 27.77 | 10.06 | |
| ✓ | 18.47 | 7.27 | 29.74 | 9.13 | |
| First order, dropped | 1.62 | 3.20 | 4.35 | 3.91 | |
| ✓ | 1.69 | 3.29 | 4.64 | 3.97 | |
| Second-order term | 1.60 | 0.74 | 1.36 | 0.78 | |
| Channels | MMAs | Wan2.2 | MiniMax-H3 | ||||
| GB300 | VR200 | Hard | All | Hard | All | ||
| 0 | 128 | 2 | 1 | 18.70 | 8.10 | 29.40 | 10.00 |
| 16 | 160 | 2 | 2 | 3.97 | 4.77 | 10.08 | 5.89 |
| 32 (Ours) | 192 | 2 | 2 | 2.80 | 3.73 | 6.31 | 4.40 |
| 64 | 256 | 3 | 2 | 2.42 | 2.81 | 4.92 | 3.18 |
| Basis | Tokens | Wan2.2 | MiniMax-H3 | |||
| Hard | All | Hard | All | |||
| separate | all | 86.0 | 73.7 | 93.8 | 83.2 | |
| 87.4 | 74.3 | 96.3 | 85.1 | |||
| shared | all | 83.8 | 71.1 | 92.5 | 80.8 | |
| 85.4 | 71.9 | 95.1 | 82.7 | |||
| shared (Ours) | 1/256 | 82.6 | 68.5 | 88.9 | 75.8 | |
| Basis | Rotation | Wan2.2 | MiniMax-H3 | ||
| Hard | All | Hard | All | ||
| shared (Ours) | ✓ | 2.80 | 3.73 | 6.31 | 4.40 |
| separate | ✓ | 2.91 | 3.77 | 5.97 | 4.35 |
| channels | ✓ | 15.16 | 6.78 | 24.99 | 8.22 |
| channels | 4.48 | 4.56 | 7.75 | 5.84 | |
| random | ✓ | 14.56 | 6.80 | 25.74 | 8.49 |
| Tokens | Wan2.2 | MiniMax-H3 | ||
| Hard | All | Hard | All | |
| 1/256 (Ours) | 2.80 | 3.73 | 6.31 | 4.40 |
| 1/64 | 2.77 | 3.65 | 6.07 | 4.26 |
| all | 2.77 | 3.62 | 5.78 | 3.99 |
| PV | Block | Wan2.2 | MiniMax-H3 | ||
| Hard | All | Hard | All | ||
| FP8 | none | 2.95 | 3.75 | 6.37 | 4.44 |
| 16 | 2.66 | 3.70 | 6.29 | 4.38 | |
| 32 | 2.73 | 3.71 | 6.31 | 4.39 | |
| 128 (Ours) | 2.80 | 3.73 | 6.31 | 4.40 | |
| NVFP4 | none | 7.50 | 5.81 | 9.16 | 6.55 |
| x = ffma2(s, a, c) h = cvt.f16x2(x) p = ex2.approx.f16x2(h) q = cvt.e4m3x2.f16x2(p) | b = ffma2(s, 8a, c) h = cvt.relu.f16x2(b) y = fma.f16x2(h, 1, 1024) q = prmt(y01, y23) | t = ffma2(s, a, c) w = cvt.pack.sat.u16(t) q = cvt.e4m3x2.f16x2(w) | u = ffma2(s, a, c) q = cvt.relu.e2m1x2.f32(u) |
| 8 instructions | 7 instructions | 6 instructions | 4 instructions |
| (a) exp2 on the SFU | (b) ExpCast | (c) I-ExpCast | (d) Direct-P |
| PV | Exponential | Time (ms) | Wan2.2 | MiniMax-H3 | ||
| Hard | All | Hard | All | |||
| FP8 | I-ExpCast (Ours) | 57.83 | 2.80 | 3.73 | 6.32 | 4.40 |
| ExpCast | 60.05 (+3.6%) | 3.13 | 4.82 | 6.87 | 5.08 | |
| SFU | 70.24 (+21.5%) | 2.78 | 3.69 | 6.27 | 4.37 | |
| SFU and polynomial | 72.67 (+25.7%) | 2.78 | 3.69 | 6.27 | 4.37 | |
| NVFP4 | I-ExpCast (Ours) | 54.17 | 5.68 | 5.09 | 8.24 | 5.67 |
| Row sum of P | Time (ms) | Wan2.2 | MiniMax-H3 | ||
| Hard | All | Hard | All | ||
| MMA (Ours) | 54.93 | 2.95 | 3.75 | 6.37 | 4.44 |
| ALU, E4M3 values | 58.89 (+7.2%) | 2.95 | 3.75 | 6.37 | 4.44 |
| ALU, FP16 values | 57.91 (+5.4%) | 3.02 | 3.79 | 6.44 | 4.48 |
| PV | Time (ms) | Wan2.2 | MiniMax-H3 | |||
| Hard | All | Hard | All | |||
| FP8 | 0 | 59.09 (+2.5%) | 2.79 | 3.70 | 6.27 | 4.36 |
| 4 (Ours) | 57.63 | 2.80 | 3.73 | 6.32 | 4.40 | |
| 8 | 57.36 (-0.5%) | 2.99 | 4.50 | 6.85 | 5.05 | |
| NVFP4 | 0 | 56.63 (+4.5%) | 5.67 | 5.07 | 8.24 | 5.65 |
| 4 (Ours) | 54.19 | 5.68 | 5.09 | 8.24 | 5.67 | |
| Wan2.2 | MiniMax-H3 | |
| Resolution | 720p | |
| Frames | 81 | 243, with audio |
| Tokens per call | 75,600 | 73,512 |
| Heads | 40 | 56 |
| Hard layers | 33, 34, 38 | 49, 45, 1 |
| Hard calls | 18 | 9 |
| Method | QK/PV | Source |
| BF16, FlashAttention-4 | 16/16 | public release |
| BF16, cuDNN | 16/16 | TensorRT-LLM |
| QK16PV8 | 16/8 | TensorRT-LLM |
| Per-tensor FP8 | 8/8 | TensorRT-LLM |
| MXFP8 | 8/8 | TensorRT-LLM |
| SageAttention2, INT8 or FP8 QK | 8/8 | TensorRT-LLM |
| Method | QK/PV | Wan2.2 | LongCat-Video | HunyuanVideo-1.5 | MiniMax-H3 | ||||||||
| S.C. | I.Q. | A.Q. | S.C. | I.Q. | A.Q. | S.C. | I.Q. | A.Q. | S.C. | I.Q. | A.Q. | ||
| BF16, FlashAttention-4 | 16/16 | 0.930 | 0.700 | 0.669 | 0.938 | 0.683 | 0.678 | 0.922 | 0.672 | 0.659 | 0.905 | 0.686 | 0.647 |
| BF16 † | 16/16 | 0.932 | 0.703 | – | 0.941 | 0.694 | – | 0.933 | 0.680 | – | 0.899 | 0.668 | – |
| BF16, cuDNN | 16/16 | 0.931 | 0.700 | 0.668 | 0.938 | 0.684 | 0.679 | 0.924 | 0.670 | 0.658 | 0.904 | 0.686 | 0.647 |
| QK16PV8 | 16/8 | 0.931 | 0.700 | 0.672 | 0.937 | 0.682 | 0.680 | 0.923 | 0.668 | 0.656 | 0.906 | 0.686 | 0.647 |
| Per-tensor FP8 | 8/8 | 0.927 | 0.695 | 0.671 | 0.938 | 0.681 | 0.677 | 0.915 | 0.671 | 0.653 | 0.902 | 0.677 | 0.644 |
| Method | QK/PV | Wan2.2 | LongCat-Video | HunyuanVideo-1.5 | MiniMax-H3 | ||||||||
| M.S. | D.D. | O.C. | M.S. | D.D. | O.C. | M.S. | D.D. | O.C. | M.S. | D.D. | O.C. | ||
| BF16, FlashAttention-4 | 16/16 | 0.9766 | 0.61 | 0.268 | 0.9834 | 0.80 | 0.262 | 0.9893 | 0.74 | 0.266 | 0.9887 | 0.80 | 0.272 |
| BF16, cuDNN | 16/16 | 0.9765 | 0.62 | 0.268 | 0.9834 | 0.80 | 0.263 | 0.9894 | 0.75 | 0.265 | 0.9887 | 0.81 | 0.272 |
| QK16PV8 | 16/8 | 0.9765 | 0.62 | 0.266 | 0.9832 | 0.81 | 0.263 | 0.9889 | 0.75 | 0.263 | 0.9888 | 0.78 | 0.273 |
| Per-tensor FP8 | 8/8 | 0.9763 | 0.61 | 0.268 | 0.9831 | 0.80 | 0.262 | 0.9866 | 0.73 | 0.267 | 0.9884 | 0.76 | 0.270 |
| MXFP8 | 0.9764 | 0.60 | 0.269 | 0.9830 | 0.81 | 0.262 | 0.9872 | 0.75 | 0.267 | 0.9881 | 0.77 | 0.269 | |
| Model | SageAttention2 | VC-Attention | ||
| reported | ours | reported | ours | |
| Wan2.2 | 20.30 | 20.08 | 20.50 | 19.78 |
| LongCat-Video | 23.10 | 22.93 | 23.80 | 25.21 |
| HunyuanVideo-1.5 | 15.60 | 15.88 | 17.50 | 17.41 |
| MiniMax-H3 | 19.90 | 19.36 | 20.20 | 19.39 |
| Method | QK/PV | Wan2.2 | LongCat-Video | HunyuanVideo-1.5 | MiniMax-H3 | ||||
| PSNR | LPIPS | PSNR | LPIPS | PSNR | LPIPS | PSNR | LPIPS | ||
| QK16PV8 | 16/8 | +1.24 0.58 | -0.019 0.017 | +0.97 0.64 | -0.008 0.013 | +0.07 0.40 | -0.003 0.018 | +2.97 0.47 | -0.112 0.017 |
| Per-tensor FP8 | 8/8 | -1.47 0.47 | +0.067 0.017 | -2.02 0.65 | +0.049 0.015 | -1.08 0.37 | +0.054 0.017 | -0.09 0.37 | +0.027 0.015 |
| MXFP8 | -1.41 0.47 | +0.061 0.017 | -2.03 0.55 | +0.047 0.014 | -1.91 0.38 | +0.096 0.019 | -0.37 0.35 | +0.035 0.015 | |
| SageAttention2, FP8 QK | -1.97 0.50 | +0.077 0.019 | -1.72 0.58 | +0.043 0.015 | -1.23 0.35 | +0.055 0.017 | -0.24 0.36 | +0.026 0.015 | |
| VC-Attention, FP8 QK | -0.90 0.48 | +0.034 0.017 | -0.30 0.60 | +0.013 0.017 | +0.14 0.40 | -0.013 0.017 | +0.48 0.38 | -0.020 0.017 | |
| Method | QK/PV | Wan2.2 | LongCat-Video | HunyuanVideo-1.5 | MiniMax-H3 | ||||
| PSNR | LPIPS | PSNR | LPIPS | PSNR | LPIPS | PSNR | LPIPS | ||
| SageAttention2, FP8 QK | 8/8 | +0.09 0.43 | +0.001 0.017 | -0.35 0.40 | +0.013 0.014 | -0.21 0.38 | +0.012 0.018 | +0.26 0.29 | +0.003 0.013 |
| VC-Attention, FP8 QK | +1.17 0.51 | -0.042 0.020 | +1.07 0.60 | -0.017 0.017 | +1.16 0.39 | -0.056 0.018 | +0.97 0.41 | -0.042 0.017 | |
| NVFP4 | 4/4 | -4.95 0.61 | +0.253 0.023 | -8.05 0.61 | +0.301 0.020 | -6.90 0.52 | +0.378 0.022 | -2.88 0.37 | +0.148 0.017 |
| SageAttention3 | -3.77 2.44 | +0.119 0.037 | -6.15 2.00 | +0.180 0.048 | -5.62 1.71 | +0.310 0.089 | -1.95 1.27 | +0.093 0.060 | |
| VC-Attention, 4-bit | -1.21 1.78 | +0.053 0.069 | -3.67 1.50 | +0.105 0.046 | -0.57 1.12 | +0.029 0.058 | -1.22 1.14 | +0.079 0.062 | |
| Method | QK/PV | Wan2.2 | MiniMax-H3 | ||
| Hard | All | Hard | All | ||
| BF16 | 16/16 | 0.15 / 0.17 | 0.17 / 0.19 | 0.17 / 0.20 | 0.17 / 0.19 |
| QK16PV8 | 16/8 | 1.90 / 2.28 | 1.20 / 2.27 | 1.76 / 2.17 | 1.27 / 2.03 |
| Per-tensor FP8 | 8/8 | 20.29 / 35.18 | 5.29 / 29.69 | 21.42 / 56.52 | 5.14 / 46.44 |
| MXFP8 | 18.21 / 33.28 | 4.81 / 33.16 | 21.87 / 57.12 | 4.95 / 48.17 | |
| SageAttention2 | 2.18 / 2.79 | 1.37 / 2.43 | 3.32 / 5.42 | 1.52 / 4.68 | |
| Method | QK/PV | Backend | GB300 | VR200 | ||||||
| Wan2.2 | MiniMax-H3 | Wan2.2 | MiniMax-H3 | |||||||
| attention | prep. | attention | prep. | attention | prep. | attention | prep. | |||
| BF16 | 16/16 | FA4, cuDNN / FA4 | 122.5 (1.00 ) | 0.00 | 83.5 (1.00 ) | 0.00 | 72.6 (1.00 ) | 0.00 | 50.5 (1.00 ) | 0.00 |
| QK16PV8 | 16/8 | TRT-LLM / FlashInfer | 102.8 (1.19 ) | 0.65 | 69.8 (1.20 ) | 0.46 | 59.8 (1.22 ) | 0.59 | 41.9 (1.21 ) | 0.43 |
| Per-tensor FP8 | 8/8 | FlashInfer / cuDNN | 79.2 (1.55 ) | 1.95 | 52.7 (1.58 ) | 1.40 | 43.7 (1.66 ) | 1.78 | 29.0 (1.74 ) | 1.30 |
| MXFP8 | cuDNN | 82.7 (1.50 ) | 3.37 | 54.5 (1.53 ) | 2.32 | 44.2 (1.64 ) | 3.51 | 29.5 (1.72 ) | 2.41 | |
| Kernel | Time (ms) | Speedup of the optimizations |
| Our kernel, compensation only | 101.1 | – |
| + All four optimizations | 60.5 | 1.67 |
| FP8-QK reference | 98.9 | – |
| + All four optimizations | 69.4 | 1.43 |
| Method | QK/PV | Wan2.2 | MiniMax-H3 |
| BF16 | 16/16 | 660.3 (1.00 ) | 444.0 (1.00 ) |
| SageAttention3 | 4/4 | 253.0 (2.61 ) | 165.3 (2.69 ) |
| VC-Attention, 4-bit | 262.1 (2.52 ) | 170.1 (2.61 ) | |
| DeCo-Attention (Ours) | 234.0 (2.82 ) | 155.1 (2.86 ) |
| Method | Wan2.2 | MiniMax-H3 |
| GB300 | ||
| BF16 | 302.7 (1.00 ) | 51.9 (1.00 ) |
| VC-Attention, FP8 QK | 237.8 (1.27 ) | 41.3 (1.26 ) |
| SageAttention2, FP8 QK | 270.4 (1.12 ) | 46.2 (1.12 ) |
| DeCo-Attention, FP8 PV (Ours) | 194.7 (1.55 ) | 33.6 (1.54 ) |
| VR200 | ||
Attention Quantization
Attention quantization reduces the precision and memory cost of attention computations while preserving model quality.
See all 48 papers