vllm.model_executor.layers.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
_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
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 | |
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
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
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 |