vllm.model_executor.layers.batch_invariant ¶
_compute_pid ¶
Source code in vllm/model_executor/layers/batch_invariant.py
_log_softmax_batch_invariant ¶
_log_softmax_kernel ¶
_log_softmax_kernel(
input_ptr,
output_ptr,
input_row_stride,
output_row_stride,
n_cols,
BLOCK_SIZE: constexpr,
)
Compute log_softmax along the last dimension of a 2D tensor. Each block handles one row of the input tensor.
Source code in vllm/model_executor/layers/batch_invariant.py
_matmul_launch_metadata ¶
_matmul_launch_metadata(
grid: Callable[..., Any],
kernel: Any,
args: dict[str, Any],
) -> dict[str, Any]
Source code in vllm/model_executor/layers/batch_invariant.py
_rms_norm_kernel ¶
_rms_norm_kernel(
input_ptr,
weight_ptr,
output_ptr,
input_row_stride,
output_row_stride,
n_cols,
eps,
BLOCK_SIZE: constexpr,
)
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/layers/batch_invariant.py
addmm_batch_invariant ¶
bmm_batch_invariant ¶
Source code in vllm/model_executor/layers/batch_invariant.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 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 | |
bmm_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: constexpr,
BLOCK_SIZE_N: constexpr,
BLOCK_SIZE_K: constexpr,
A_LARGE: constexpr,
B_LARGE: constexpr,
C_LARGE: constexpr,
)
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/layers/batch_invariant.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
enable_batch_invariant_mode ¶
Source code in vllm/model_executor/layers/batch_invariant.py
init_batch_invariance ¶
Source code in vllm/model_executor/layers/batch_invariant.py
linear_batch_invariant ¶
log_softmax ¶
Compute log_softmax using Triton kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input | Tensor | Input tensor | required |
dim | int | Dimension along which to compute log_softmax (only -1 or last dim supported) | -1 |
Stashed changes Returns: Tensor with log_softmax applied along the specified dimension
Source code in vllm/model_executor/layers/batch_invariant.py
matmul_batch_invariant ¶
Source code in vllm/model_executor/layers/batch_invariant.py
matmul_kernel_persistent ¶
matmul_kernel_persistent(
a_ptr,
b_ptr,
c_ptr,
bias_ptr,
M,
N,
K,
stride_am,
stride_ak,
stride_bk,
stride_bn,
stride_cm,
stride_cn,
BLOCK_SIZE_M: constexpr,
BLOCK_SIZE_N: constexpr,
BLOCK_SIZE_K: constexpr,
GROUP_SIZE_M: constexpr,
NUM_SMS: constexpr,
A_LARGE: constexpr,
B_LARGE: constexpr,
C_LARGE: constexpr,
HAS_BIAS: constexpr,
)
Source code in vllm/model_executor/layers/batch_invariant.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
matmul_persistent ¶
Source code in vllm/model_executor/layers/batch_invariant.py
mean_batch_invariant ¶
mean_batch_invariant(
input, dim, keepdim=False, dtype: dtype | None = None
)
Source code in vllm/model_executor/layers/batch_invariant.py
mean_dim ¶
Triton implementation of torch.mean with single dimension reduction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input | Tensor | Input tensor | required |
dim | int | Single dimension along which to compute mean | required |
keepdim | bool | Whether to keep the reduced dimension | False |
dtype | dtype | None | Output dtype. If None, uses input dtype (or float32 for integer inputs) | None |
Returns:
| Type | Description |
|---|---|
Tensor | Tensor with mean values along specified dimension |
Source code in vllm/model_executor/layers/batch_invariant.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
mean_kernel ¶
mean_kernel(
input_ptr,
output_ptr,
input_stride0,
input_stride1,
input_stride2,
output_stride0,
output_stride1,
M,
N,
K,
BLOCK_SIZE: constexpr,
)
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/layers/batch_invariant.py
mm_batch_invariant ¶
override_envs_for_invariance ¶
Source code in vllm/model_executor/layers/batch_invariant.py
rms_norm ¶
Compute RMS normalization using Triton kernel.
RMS Norm normalizes the input by the root mean square and scales by weight: output = input / sqrt(mean(input^2) + eps) * weight
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input | Tensor | Input tensor of shape (..., hidden_size) | required |
weight | Tensor | Weight tensor of shape (hidden_size,) | required |
eps | float | Small constant for numerical stability | 1e-06 |
Returns:
| Type | Description |
|---|---|
Tensor | Tensor with RMS normalization applied along the last dimension |
Source code in vllm/model_executor/layers/batch_invariant.py
rms_norm_batch_invariant ¶
Batch-invariant wrapper for RMS normalization.
This function provides a deterministic, batch-invariant implementation of RMS normalization for use with the batch_invariant mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input | Tensor | Input tensor of shape (..., hidden_size) | required |
weight | Tensor | Weight tensor of shape (hidden_size,) | required |
eps | float | Small constant for numerical stability | 1e-06 |
Returns:
| Type | Description |
|---|---|
Tensor | RMS normalized tensor |