🔥 BLACK FRIDAY: 40% OFF every guide & bundle · auto-applied at checkout · LAST DAY  Shop the bundles →Not sure? 60-sec quiz →

SageAttention3 FP4 Attention 2026: Faster Inference on RTX 50

SageAttention3 FP4 Attention 2026: Faster Inference on RTX 50 - ailearningguides.com

FP4 attention went from a research curiosity to something we can actually ship on a desktop GPU. A technical deep-dive published this week showed how register-recycling tricks let FP4 attention kernels on RTX 50-series Blackwell cards hold more work in flight and stall less. That brings Tsinghua’s open-source SageAttention3 back into the conversation for anyone running video diffusion or LLM inference locally. If you own an RTX 5090 and still run stock FlashAttention, you are probably leaving a lot of speed unused. Before you flip the switch, know what it costs in quality.

Want the complete, hands-on version of this guide?Browse the Eguides →

What’s actually new with FP4 attention

The new work is about how the kernels are built, not a new model or a new number format. Blackwell’s consumer GPUs (sm_120: the RTX 5090, 5080 and siblings) have hardware FP4 tensor core instructions, but getting near their peak inside an attention kernel is hard. Attention is not a single large matrix multiply. It chains a QKT matmul, an online softmax, a quantize step and a PV matmul, and every intermediate fights for the same limited register file. This week’s analysis showed that freeing and reusing registers across those stages lets the kernel keep more tiles resident and hide more memory latency, so the FP4 tensor cores stay busy. That is the difference between a kernel that is fast on paper and one that is fast in practice.

SageAttention3 is the most mature open-source project built around this hardware path. The Tsinghua team (thu-ml) introduced it in the paper “SageAttention3: Microscaling FP4 Attention for Inference and An Exploration of 8-bit Training.” It quantizes Q, K and V into microscaling FP4, the same block-scaled format NVIDIA markets as NVFP4: blocks of 16 values share an FP8 scale factor. That fine-grained scaling is what makes 4-bit attention usable at all, because plain per-tensor FP4 would destroy the outliers attention relies on. The authors report about 1,038 TOPS of attention throughput on an RTX 5090, roughly 5x faster than the fastest FlashAttention kernel on the same card.

The other key piece is how SageAttention3 handles the softmax output P. Its values sit between 0 and 1, and a naive FP4 scale wastes most of the format’s range there. The paper uses two-level quantization: P is first rescaled per row, then quantized with the normal block scales. That preserves far more precision in exactly the matrix FP4 handles worst. Combine that with this week’s register-level tuning ideas and the remaining performance gap on consumer Blackwell shrinks considerably.

Why FP4 attention matters

  • Video generation is attention-bound. Long-sequence video diffusion models (HunyuanVideo, Wan, CogVideoX-class) spend most of their runtime in attention, so a multi-fold faster attention kernel translates directly into faster end-to-end generation. The SageAttention team reports roughly 3x end-to-end speedups on video models.
  • RTX 5090 inference speed finally matches the hardware. Most local stacks still run FP16/BF16 attention and never touch Blackwell’s FP4 tensor cores. FP4 attention lets a $2,000 consumer card behave like a much more expensive one for this workload.
  • It is plug-and-play, not a retrain. SageAttention is a drop-in replacement for scaled_dot_product_attention. You don’t fine-tune, calibrate or convert checkpoints, so trying it costs almost nothing.
  • Quality is not free. 4-bit attention is lossy. On most image and video models the drop is hard to see, but sensitive layers, early diffusion timesteps and long-context LLM decoding can degrade. Measure on your own workloads.
  • It stacks with weight quantization. NVFP4 weight quantization (via TensorRT-LLM, ModelOpt or similar) cuts memory and speeds up the matmuls. FP4 attention speeds up the part weight quantization doesn’t touch. Together they make local LLM inference practical on hardware that couldn’t handle it a year ago.
  • The format is the industry’s 4-bit standard. Microscaling FP4 now spans NVIDIA’s data-center and consumer lineups, so the skills and tooling you build now will carry forward.

How to use FP4 attention today

This walkthrough assumes Linux or WSL2, an RTX 50-series GPU, and a recent PyTorch build with CUDA 12.8 or newer. Older toolkits won’t compile sm_120 kernels.

1. Confirm your GPU and toolkit

You need compute capability 12.0 and a CUDA 12.8+ PyTorch build.

nvidia-smi
nvcc --version
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.get_device_capability())"
# Expect something like: 2.x.x 12.8 (12, 0)

2. Create a clean environment and install PyTorch for CUDA 12.8

python -m venv ~/venvs/sage3
source ~/venvs/sage3/bin/activate
pip install --upgrade pip wheel setuptools ninja packaging
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu128

3. Build SageAttention from source

The Blackwell FP4 kernels live in their own subdirectory of the thu-ml repository. The build takes a while, so limit parallel jobs if RAM is tight.

git clone https://github.com/thu-ml/SageAttention.git
cd SageAttention

# SageAttention2/2++ (INT8/FP8 path, works on Ada, Hopper and Blackwell)
export MAX_JOBS=8
pip install . --no-build-isolation

# SageAttention3 FP4 kernels for Blackwell (sm_120)
cd sageattention3_blackwell
pip install . --no-build-isolation

The repo moves fast. If the directory or package name has changed, check the README before you debug your compiler.

4. Run a microbenchmark against PyTorch SDPA

Do this before wiring the kernel into a model. It tells you whether it actually beats your current baseline on your card, at your sequence lengths. The import name below matches the project’s README at the time of writing; adjust it if upstream renames it.

import torch, time
import torch.nn.functional as F
from sageattn3 import sageattn3_blackwell  # see repo README if renamed

B, H, N, D = 1, 24, 32768, 128   # video-length sequence
q, k, v = (torch.randn(B, H, N, D, device="cuda", dtype=torch.bfloat16) for _ in range(3))

def bench(fn, iters=20):
    for _ in range(3): fn()
    torch.cuda.synchronize(); t = time.perf_counter()
    for _ in range(iters): fn()
    torch.cuda.synchronize()
    return (time.perf_counter() - t) / iters * 1000

ref = F.scaled_dot_product_attention(q, k, v)
out = sageattn3_blackwell(q, k, v)

print(f"SDPA:  {bench(lambda: F.scaled_dot_product_attention(q, k, v)):.2f} ms")
print(f"Sage3: {bench(lambda: sageattn3_blackwell(q, k, v)):.2f} ms")
cos = F.cosine_similarity(ref.flatten().float(), out.flatten().float(), dim=0)
print(f"cosine similarity vs SDPA: {cos.item():.5f}")

Track both numbers. Speed without an accuracy check is how bad outputs reach production.

5. Patch it into a diffusers pipeline

Monkey-patching SDPA is the quickest test, but it replaces attention everywhere. Keep a fallback for shapes the kernel doesn’t support, such as masks, odd head dims and cross-attention with short keys.

import torch.nn.functional as F
from sageattn3 import sageattn3_blackwell

_orig_sdpa = F.scaled_dot_product_attention

def sdpa_fp4(q, k, v, attn_mask=None, dropout_p=0.0, is_causal=False, **kw):
    if attn_mask is None and dropout_p == 0.0 and q.shape[-1] in (64, 128) and k.shape[-2] >= 1024:
        return sageattn3_blackwell(q, k, v, is_causal=is_causal)
    return _orig_sdpa(q, k, v, attn_mask=attn_mask, dropout_p=dropout_p, is_causal=is_causal, **kw)

F.scaled_dot_product_attention = sdpa_fp4
# now load and run your diffusers video pipeline as usual

6. Use a hybrid schedule to protect quality

The safest production setup keeps the first and last diffusion steps, or the most sensitive layers, on 8-bit SageAttention2++ or full-precision attention and runs FP4 everywhere else. You keep most of the speedup and remove most of the visible artifacts.

from sageattention import sageattn  # SageAttention2/2++ (8-bit path)

def make_attn(step, total_steps):
    use_fp4 = 2 <= step < total_steps - 2
    return sageattn3_blackwell if use_fp4 else sageattn

7. ComfyUI setup

Many recent ComfyUI builds expose a SageAttention launch flag. Install the package into ComfyUI’s Python environment, start it with the flag, and compare render times and outputs on a fixed seed.

python main.py --use-sage-attention

8. For LLMs, test prefill and decode separately

FP4 attention helps most on long-context prefill, where attention is compute-bound. Single-token decode is usually memory-bound on the KV cache, so expect smaller gains there. Validate quality with a perplexity run or your own eval set before trusting it for local LLM inference.

How it compares: FlashAttention vs SageAttention

Kernel Precision (QK / PV) Best hardware Relative speed on RTX 5090 Quality risk Retraining needed
PyTorch SDPA / FlashAttention2 FP16/BF16 Ampere and newer Baseline None (reference) No
FlashAttention3 FP16/BF16, FP8 option Hopper (H100) focused Limited consumer Blackwell support Low No
SageAttention2 / 2++ INT8 (QK) / FP8 (PV) Ada, Hopper, Blackwell Roughly 2-4x over FlashAttention2 (per authors) Very low on most models No
SageAttention3 Microscaling FP4 (NVFP4-style) / FP4 Blackwell (sm_120) About 5x over fastest FlashAttention (per paper) Low to moderate, model dependent No (8-bit training is a separate research track)

Our take: on Ada or Hopper, SageAttention2++ is the sensible default and costs almost nothing in quality. On an RTX 5090, benchmark SageAttention3 today, but run it in a hybrid setup rather than an all-in swap until you’ve validated it on your own prompts.

What’s next

The register-recycling work shows where the remaining gains are: FP4 attention on consumer Blackwell is limited by kernel engineering, not by the format. Expect these ideas to land in SageAttention, in the attention backends of inference engines like vLLM, SGLang and TensorRT-LLM, and in community forks. Watch for support for more head dimensions, attention masks and variable-length batches. Those gaps currently force fallbacks that eat into end-to-end speedups.

Second, watch how this fits with whole-model NVFP4 quantization. Most local stacks today pair quantized weights with higher-precision attention, or FP4 attention with BF16 weights. Running everything in FP4 with clear accuracy guarantees is the obvious next step, and the tooling (ModelOpt, TensorRT-LLM, diffusers integrations) is heading there. The SageAttention team’s exploration of 8-bit attention for training is also worth tracking. If it holds up, low-precision attention stops being only an inference trick.

Finally, expect better quality controls. Per-layer and per-timestep precision schedules are tuned by hand today. Automated sensitivity analysis that picks FP4, FP8 or BF16 for each layer would make FP4 attention a safe default rather than a power-user tweak.

Frequently Asked Questions

What is FP4 attention?

FP4 attention runs the attention matmuls (QKT and PV) in 4-bit floating point instead of 16-bit. To preserve accuracy, it uses microscaling: small blocks of values share a higher-precision scale factor. On GPUs with native FP4 tensor cores, such as Blackwell, this sharply increases attention throughput.

Does SageAttention3 work on RTX 40-series or older GPUs?

No. SageAttention3’s FP4 kernels require Blackwell’s FP4 tensor core instructions (sm_120 on consumer cards). On Ada (RTX 40-series) and Hopper, use SageAttention2 or 2++, which use INT8 and FP8 and still deliver large speedups over FlashAttention2.

How much faster is RTX 5090 inference speed with SageAttention3?

The authors report about 1,038 TOPS for the attention kernel, around 5x the fastest FlashAttention on the same card. End-to-end video generation speedups are smaller, roughly 3x in their reports, because attention isn’t the only cost. LLM decode gains are smaller still. Benchmark your own model and sequence lengths.

Will FP4 attention hurt output quality?

It can. On most image and video diffusion models the difference is hard to notice, but you may see texture loss, temporal flicker or slight prompt-adherence drift, especially if FP4 runs in the first and last denoising steps. For LLMs, check perplexity and task evals. A hybrid setup that keeps sensitive steps on 8-bit attention recovers most of the quality.

Is SageAttention3 the same as NVFP4 quantization?

No, though they’re related. NVFP4 is NVIDIA’s block-scaled 4-bit format, typically used to quantize model weights and activations. SageAttention3 applies a similar microscaling FP4 format inside the attention computation. You can combine them: quantize weights with NVFP4 and run attention with SageAttention3.

Do I need to retrain or fine-tune my model?

No. SageAttention is a plug-and-play replacement for standard attention at inference time. Swap the kernel, benchmark speed and quality, and keep it if the numbers hold up.

Go deeper than this article

This article covers the essentials. Our Technical & Coding eguide collection gives you the full step-by-step playbooks — prompts, workflows, and copy-paste recipes built for exactly this work.

Browse Technical & Coding Eguides →

SSL SecurePrivacy Protectedvisamastercardamericanexpressdiscovergooglepay
Scroll to Top