Skip to content

vllm.v1.attention.backends.ultraquant_attn

UltraQuant 4-bit KV-cache attention backend.

UltraQuant is a 4-bit KV-cache format (FP4 E2M1 codes + UE8M0 power-of-two per-group-32 scales) with Hadamard-rotated keys. It reuses the TurboQuant attention scaffolding (forward orchestration, metadata, cache-layout addressing, CUDA-graph pre-warm) by subclassing, and overrides only the format-specific seams:

  • store -> ultraquant_store (rotate K, pack FP4 + UE8M0 scales)
  • decode -> FlyDSL D=256 scaled-MFMA kernel, Triton unified fallback
  • continuation -> small chunk: Triton unified; large chunk: dequant + FA

UltraQuantAttentionBackend is a standalone backend with its own identity (ULTRAQUANT) and dtype (ultraquant_4bit); the TurboQuant backend/impl carry no UltraQuant knowledge.

Classes:

UltraQuantAttentionBackend

Bases: TurboQuantAttentionBackend

Standalone backend for the ultraquant_4bit KV-cache dtype.

Subclasses TurboQuantAttentionBackend for the shared metadata and cache-layout plumbing, and overrides identity, spec, impl, block size, and capabilities so no UltraQuant knowledge lives in the TurboQuant backend.

Methods:

  • customize_spec –

    UltraQuant packs K+V into one 4-bit FP4/UE8M0 slot per head.

customize_spec(spec) classmethod

UltraQuant packs K+V into one 4-bit FP4/UE8M0 slot per head.

UltraQuantAttentionImpl

Bases: TurboQuantAttentionImpl

UltraQuant 4-bit KV-cache attention (FP4 E2M1 + UE8M0, rotated K).

Overrides the init, on-device setup, store, decode, and prefill/continuation seams of TurboQuantAttentionImpl; the shared forward / do_kv_cache_update orchestration and metadata handling are inherited.

_ensure_on_device(layer, device)

Build the shared Hadamard rotation and pre-warm FlyDSL buffers.

UltraQuant needs no Lloyd-Max centroids, but the inherited forward reads layer._tq_centroids, so an empty tensor is kept on the layer.

_store_kv(key, value, kv_cache, slot_mapping, layer)

Rotate K by the Hadamard and pack K+V into FP4/UE8M0 slots.

_ultraquant_continuation_prefill(*, layer, query, key_chunk, val_chunk, kv_cache, block_table, cached_len, seq_len, PiT)

Large continuation chunk: dequant the cached prefix, then flash_attn.

The cache stores K already Hadamard-rotated, so only the current chunk's K and the queries need rotating. Hadamard is symmetric orthonormal, so rotating both sides leaves the attention scores unchanged.