Skip to content

vllm.model_executor.determinism.batch_invariant

Functions:

_fixed_order_sum_kernel(src_ptr, out_ptr, numel, stride_rank, WORLD_SIZE, BLOCK_SIZE, LARGE)

Sum WORLD_SIZE contributions in ascending rank order, fp32 accumulator.

An output element sums exactly WORLD_SIZE values in a compile-time constant order and rounds once, so the result depends only on the rank ordering and never on how many elements are being reduced.

_resolve_block_sizes()

Size the tiles to the shared memory, to avoid triton OutOfResources.

Runs when the mode is enabled, or on first use by a caller that never enables it, such as a kernel unit test.

_rms_norm_kernel(input_ptr, weight_ptr, output_ptr, input_row_stride, output_row_stride, n_cols, eps, BLOCK_SIZE, HAS_WEIGHT)

Compute RMS normalization along the last dimension of a 2D tensor. RMS Norm: y = x / sqrt(mean(x^2) + eps) * weight Each block handles one row of the input tensor.

_softmax_kernel(input_ptr, output_ptr, input_row_stride, input_col_stride, output_row_stride, n_cols, BLOCK_SIZE, LOG=False)

Compute softmax, or log_softmax when LOG, along the last dimension of a 2D tensor. Each block handles one row of the input tensor, in a fixed block order, so the result never depends on the row count.

all_reduce_batch_invariant(input_, group=None)

Sum all-reduce whose result does not depend on the message size.

Library all-reduces (NCCL/RCCL) pick their algorithm, channel count and chunk boundaries from the message size, so the order in which a given element's contributions are summed changes with the number of tokens in the batch.

Instead, all-gather the contributions -- pure data movement, so bitwise reproducible at any size -- and reduce them with _fixed_order_sum_kernel.

bmm_kernel(a_ptr, b_ptr, c_ptr, B, M, N, K, stride_ab, stride_am, stride_ak, stride_bb, stride_bk, stride_bn, stride_cb, stride_cm, stride_cn, BLOCK_SIZE_M, BLOCK_SIZE_N, BLOCK_SIZE_K, A_LARGE, B_LARGE, C_LARGE)

Batched GEMM: (B, M, K) x (B, K, N) -> (B, M, N).

Each program computes one (batch_idx, tile_m, tile_n) tile, accumulating along K in a fixed order to preserve batch invariance.

dequantize_gptq_weight(qweight, scales, *, num_bits, group_size, zero_bias)

Unpack a symmetric GPTQ weight (no act-order) to scales.dtype.

qweight is in the checkpoint layout: [K // pack_factor, N] int32 with pack_factor consecutive input rows packed into each element, lowest bits first. Returns (q - zero_bias) * scale of shape [K, N].

gptq_linear_batch_invariant(x, qweight, scales, *, num_bits, group_size, zero_bias, bias=None)

GPTQ linear without Marlin: the Marlin GEMM picks its tiling and K-split from the number of tokens, so dequantize the checkpoint weight and use the batch-invariant matmul instead.

log_softmax(input, dim=-1)

Compute log_softmax using Triton kernel.

Parameters:

  • input

    (Tensor) –

    Input tensor

  • dim

    (int, default: -1 ) –

    Dimension along which to compute log_softmax (only -1 or last dim supported)

Returns:

  • Tensor –

    Tensor with log_softmax applied along the specified dimension

matmul_descriptor_persistent(a, b, bias=None)

Persistent matmul using tensor descriptors (Intel XPU fast path).

Parameters:

  • a

    (Tensor) –

    Input matrix [M, K], must be contiguous.

  • b

    (Tensor) –

    Weight matrix [K, N] (standard layout — transposed internally).

  • bias

    (Tensor | None, default: None ) –

    Optional 1D bias vector [N].

Returns:

  • Tensor –

    Output matrix [M, N] with dtype matching the inputs.

matmul_kernel_descriptor_persistent(a_ptr, b_ptr, c_ptr, bias_ptr, M, N, K, BLOCK_SIZE_M, BLOCK_SIZE_N, BLOCK_SIZE_K, GROUP_SIZE_M, NUM_SMS, HAS_BIAS)

Persistent matmul using tensor descriptors for 2D block I/O.

Expects b_ptr to point to a transposed B matrix of shape [N, K] with row-major (K-contiguous) layout. The dot product transposes each loaded B-tile back: dot(A_tile, B_tile.T).

~3x faster than the pointer-based persistent kernel on Intel XPU because tensor descriptors leverage hardware 2D block load/store with automatic bounds checking (no explicit masks needed).

mean_dim(input, dim, keepdim=False, dtype=None)

Triton implementation of torch.mean with single dimension reduction.

Parameters:

  • input

    (Tensor) –

    Input tensor

  • dim

    (int) –

    Single dimension along which to compute mean

  • keepdim

    (bool, default: False ) –

    Whether to keep the reduced dimension

  • dtype

    (dtype | None, default: None ) –

    Output dtype. If None, uses input dtype (or float32 for integer inputs)

Returns:

  • Tensor –

    Tensor with mean values along specified dimension

mean_kernel(input_ptr, output_ptr, input_stride0, input_stride1, input_stride2, output_stride0, output_stride1, M, N, K, BLOCK_SIZE)

Kernel for computing mean along a single dimension. Input is viewed as (M, N, K) where N is the dimension being reduced.

reduce_scatter_batch_invariant(input_, group=None, sizes=None)

Sum reduce-scatter over dim 0 whose result does not depend on the size.

ncclReduceScatter picks its chunking from the message size just as ncclAllReduce does. Route around it the same way all_reduce_batch_invariant does: an all-to-all sends rank d exactly the rows it owns from every rank -- pure data movement, so bitwise reproducible however the library chunks it -- and lands them rank-major, which is the layout _fixed_order_sum_kernel already consumes.

sizes (the reduce-scatterv case) changes only which rows a rank receives, never how the received contributions are summed, so variable shard sizes are invariant for the same reason.

Parameters:

  • input_

    (Tensor) –

    Contiguous full-size input; dim 0 is the scattered axis.

  • group

    (ProcessGroup | None, default: None ) –

    Process group, defaults to the world group.

  • sizes

    (list[int] | None, default: None ) –

    Per-rank row counts. Uniform split when None.

Returns:

  • Tensor –

    This rank's shard of the sum.

rms_norm_batch_invariant(input, weight, eps=1e-06, residual=None)

Compute RMS normalization using Triton kernel.

Parameters:

  • input

    (Tensor) –

    Input tensor of shape (..., hidden_size)

  • weight

    (Tensor | None) –

    Weight tensor of shape (hidden_size,), or None to skip the per-channel multiply (RMSNorm(has_weight=False))

  • eps

    (float, default: 1e-06 ) –

    Small constant for numerical stability

  • residual

    (Tensor | None, default: None ) –

    Optional residual tensor fused into the normalization path

Returns:

softmax(input, dim=-1)

Compute softmax along the last dimension using a Triton kernel.