Skip to content

vllm.v1.attention.ops.common

Functions:

  • pack_seq_triton –

    Pack sequences of different lengths into a batched tensor.

  • pack_ue8m0_x4 –

    Encode a power-of-two fp32 scale as four equal packed UE8M0 bytes, the

  • unpack_seq_triton –

    Unpack a packed decode query tensor back to the original format.

pack_seq_triton(x, lengths, pad_value=-float('inf'), block_t=64, block_d=64)

Pack sequences of different lengths into a batched tensor.

Supports float dtypes (any, via fp32 pad) and torch.uint8 (exact-byte pad — e.g. MXFP4 packed nibbles or ue8m0 scale bytes). For uint8 inputs pad_value must be an integer in [0, 255].

Parameters:

  • x

    (Tensor) –

    [N, ...] — input tensor where N is total number of tokens.

  • lengths

    (Tensor) –

    [B] — sequence lengths for each batch.

  • pad_value

    (float | int, default: -float('inf') ) –

    value to use for padding. Defaults to -inf which is only sensible for float dtypes; pass 0 (or any byte) for uint8 inputs.

  • block_t

    (int, default: 64 ) –

    block size for time dimension.

  • block_d

    (int, default: 64 ) –

    block size for feature dimension.

Returns:

  • packed ( Tensor ) –

    [B, Lmax, ...] — packed tensor.

pack_ue8m0_x4(scale)

Encode a power-of-two fp32 scale as four equal packed UE8M0 bytes, the MX scales of a 128-wide row (see mqa_logits_use_mx_scales).

unpack_seq_triton(packed_tensor, lengths, block_t=64, block_d=64)

Unpack a packed decode query tensor back to the original format. Efficient Triton implementation.

Parameters:

  • packed_tensor

    (Tensor) –

    [B, Lmax, ...] - packed tensor from pack_seq_triton

  • lengths

    (Tensor) –

    [B] - sequence lengths for each batch

  • block_t

    (int, default: 64 ) –

    block size for time dimension

  • block_d

    (int, default: 64 ) –

    block size for feature dimension

Returns:

  • unpacked_tensor ( Tensor ) –

    [N, ...] where N = sum(lengths)