vllm.model_executor.determinism.batch_invariant
¶
Functions:
-
all_reduce_batch_invariant–Sum all-reduce whose result does not depend on the message size.
-
bmm_kernel–Batched GEMM: (B, M, K) x (B, K, N) -> (B, M, N).
-
log_softmax–Compute log_softmax using Triton kernel.
-
matmul_descriptor_persistent–Persistent matmul using tensor descriptors (Intel XPU fast path).
-
matmul_kernel_descriptor_persistent–Persistent matmul using tensor descriptors for 2D block I/O.
-
mean_dim–Triton implementation of torch.mean with single dimension reduction.
-
mean_kernel–Kernel for computing mean along a single dimension.
-
reduce_scatter_batch_invariant–Sum reduce-scatter over dim 0 whose result does not depend on the size.
-
rms_norm_batch_invariant–Compute RMS normalization using Triton kernel.
-
softmax–Compute softmax along the last dimension using a Triton kernel.
_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.
Source code in vllm/model_executor/determinism/batch_invariant.py
_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.
Source code in vllm/model_executor/determinism/batch_invariant.py
_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.
Source code in vllm/model_executor/determinism/batch_invariant.py
_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.
Source code in vllm/model_executor/determinism/batch_invariant.py
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.
Source code in vllm/model_executor/determinism/batch_invariant.py
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.
Source code in vllm/model_executor/determinism/batch_invariant.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
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
Source code in vllm/model_executor/determinism/batch_invariant.py
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.
Source code in vllm/model_executor/determinism/batch_invariant.py
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).
Source code in vllm/model_executor/determinism/batch_invariant.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
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
Source code in vllm/model_executor/determinism/batch_invariant.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
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.
Source code in vllm/model_executor/determinism/batch_invariant.py
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.
Source code in vllm/model_executor/determinism/batch_invariant.py
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 | |
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:
-
Tensor | tuple[Tensor, Tensor]–RMS normalized tensor, or
(output, residual_out)whenresidual -
Tensor | tuple[Tensor, Tensor]–is provided
Source code in vllm/model_executor/determinism/batch_invariant.py
softmax(input, dim=-1)
¶
Compute softmax along the last dimension using a Triton kernel.