Skip to content

vllm.v1.attention.ops.triton_per_tensor_fp8_quant

Fused dynamic per-tensor FP8 quantization of up to three attention inputs.

Each [tokens, heads, dim] input (possibly strided, e.g. V as a view of the kv_b_proj output) gets its own amax and FP32 descale. A partial-amax pass and a reduce-and-quantize pass cover all inputs in two launches; the kernel boundary is the only global barrier, so no atomics or zero-initialization are needed and the ops are CUDA-graph safe. Compile-time specialization does not depend on the token counts (only the grid size does), so varying batch shapes do not recompile.

One grid covers all the inputs in each launch, so a program can land past the end of a smaller input. Such programs do no work and compute no address, and every load and store is masked regardless, so no out-of-range pointer is formed or dereferenced.

Adapted from the fused QKV quantizer in ROCm/ATOM (atom/model_ops/ triton_fused_qkv_quant.py, MIT license).

Functions:

fused_per_tensor_fp8_quant(*tensors, fp8_dtype=torch.float8_e4m3fn)

Quantize each input to FP8 with its own dynamic per-tensor scale.

Parameters:

  • tensors

    (Tensor, default: () ) –

    One to three BF16/FP16 [tokens, heads, dim] tensors on the same device. Arbitrary strides are supported; token counts may differ and may be zero.

  • fp8_dtype

    (dtype, default: float8_e4m3fn ) –

    The FP8 output dtype.

Returns:

  • tuple[Tensor, ...] –

    (outputs, descales): contiguous FP8 tensors with the input shapes

  • tuple[Tensor, ...] –

    and FP32 shape-[1] descales (amax / fp8_max, or 1e-6 for

  • tuple[tuple[Tensor, ...], tuple[Tensor, ...]] –

    all-zero or empty inputs).