vllm.v1.attention.ops.common ¶
Functions:
-
pack_seq_triton–Pack sequences of different lengths into a batched tensor.
-
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
-infwhich is only sensible for float dtypes; pass0(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.
Source code in vllm/v1/attention/ops/common.py
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)