vllm.model_executor.layers.quantization.utils.fp8_utils
_per_token_group_quant_fp8 ¶
_per_token_group_quant_fp8(
y_ptr,
y_q_ptr,
y_s_ptr,
group_size,
y_num_columns,
y_row_stride,
eps,
fp8_min,
fp8_max,
use_ue8m0: constexpr,
BLOCK: constexpr,
)
A Triton-accelerated function to perform per-token-group quantization on a tensor. This function converts the tensor values into float8 values.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_per_token_group_quant_fp8_colmajor ¶
_per_token_group_quant_fp8_colmajor(
y_ptr,
y_q_ptr,
y_s_ptr,
group_size,
y_num_columns,
y_row_stride,
y_s_col_stride,
eps,
fp8_min,
fp8_max,
use_ue8m0: constexpr,
BLOCK: constexpr,
)
A Triton-accelerated function to perform per-token-group quantization on a tensor. This function converts the tensor values into float8 values.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_w8a8_block_fp8_matmul ¶
_w8a8_block_fp8_matmul(
A,
B,
C,
As,
Bs,
M,
N,
K,
group_n,
group_k,
stride_am,
stride_ak,
stride_bk,
stride_bn,
stride_cm,
stride_cn,
stride_As_m,
stride_As_k,
stride_Bs_k,
stride_Bs_n,
BLOCK_SIZE_M: constexpr,
BLOCK_SIZE_N: constexpr,
BLOCK_SIZE_K: constexpr,
GROUP_SIZE_M: constexpr,
)
Triton-accelerated function used to perform linear operations (dot product) on input tensors A
and B
with block-wise quantization, and store the result in output tensor C
.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
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 494 495 496 497 498 499 500 501 502 503 504 505 506 507 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 |
|
apply_w8a8_block_fp8_linear ¶
apply_w8a8_block_fp8_linear(
input: Tensor,
weight: Tensor,
block_size: list[int],
weight_scale: Tensor,
input_scale: Optional[Tensor] = None,
bias: Optional[Tensor] = None,
cutlass_block_fp8_supported: bool = CUTLASS_BLOCK_FP8_SUPPORTED,
use_aiter_and_is_supported: bool = False,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
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 139 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 |
|
apply_w8a8_block_fp8_linear_fake ¶
apply_w8a8_block_fp8_linear_fake(
input: Tensor,
weight: Tensor,
block_size: list[int],
weight_scale: Tensor,
input_scale: Optional[Tensor] = None,
bias: Optional[Tensor] = None,
cutlass_block_fp8_supported: bool = CUTLASS_BLOCK_FP8_SUPPORTED,
use_aiter_and_is_supported: bool = False,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
block_quant_to_tensor_quant ¶
This function converts block-wise quantization to tensor-wise quantization. The inputs are block-wise quantization tensor x_q_block
, block-wise quantization scale and the block size. The outputs are tensor-wise quantization tensor and tensor-wise quantization scale. Note only float8 is supported for now.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
cutlass_scaled_mm ¶
cutlass_scaled_mm(
A: Tensor,
B: Tensor,
As: Tensor,
Bs: Tensor,
block_size: list[int],
output_dtype: dtype = float16,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
dispatch_w8a8_blockscale_func ¶
dispatch_w8a8_blockscale_func(
use_cutlass: bool, use_aiter_and_is_supported: bool
) -> Callable[
[Tensor, Tensor, Tensor, Tensor, list[int], dtype],
Tensor,
]
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
get_col_major_tma_aligned_tensor ¶
Returns TMA-aligned transposed format of the input tensor. torch.transpose
will be called if necessary. If the input tensor is already column-major layout and 16-byte aligned along the M axis (thus meets the requirement of LHS scaling tensor in DeepGEMM), this function will do nothing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Tensor | usually the LHS scaling tensor in GEMM. | required |
Returns:
Type | Description |
---|---|
Tensor | The LHS scaling tensor of TMA-aligned transposed format. |
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
get_tma_aligned_size ¶
Global memory address of TMA must be 16-byte aligned. Since we use column-major layout for the LHS scaling tensor, the M-axis of the LHS scaling tensor needs to be padded to a multiple of 16 bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | int | original M-axis shape of the LHS scaling tensor. | required |
element_size | int | element size of the LHS scaling tensor. | required |
Returns:
Type | Description |
---|---|
int | M-axis shape of the LHS scaling tensor after padding. |
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
get_w8a8_block_fp8_configs cached
¶
get_w8a8_block_fp8_configs(
N: int, K: int, block_n: int, block_k: int
) -> Optional[dict[int, Any]]
Return optimized configurations for the w8a8 block fp8 kernel. The return value will be a dictionary that maps an irregular grid of batch sizes to configurations of the w8a8 block fp8 kernel. To evaluate the kernel on a given batch size bs, the closest batch size in the grid should be picked and the associated configuration chosen to invoke the kernel.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
input_to_float8 ¶
This function quantizes input values to float8 values " "with tensor-wise quantization.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
is_fp8 ¶
per_token_group_quant_fp8 ¶
per_token_group_quant_fp8(
x: Tensor,
group_size: int,
eps: float = 1e-10,
dtype: Optional[dtype] = None,
column_major_scales: bool = False,
out_q: Optional[Tensor] = None,
use_ue8m0: Optional[bool] = None,
) -> tuple[Tensor, Tensor]
Function to perform per-token-group quantization on an input tensor x
. It converts the tensor values into signed float8 values and returns the quantized tensor along with the scaling factor used for quantization. Args: x: The input tensor with ndim >= 2. group_size: The group size used for quantization. eps: The minimum to avoid dividing zero. dtype: The dype of output tensor. Note that only torch.float8_e4m3fn
is supported for now. column_major_scales: Outputs scales in column major. out_q: Optional output tensor. If not provided, function will create. Returns: tuple[torch.Tensor, torch.Tensor]: The quantized tensor and the scaling factor.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.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 |
|
requant_weight_ue8m0_inplace ¶
requant_weight_ue8m0_inplace(
weight: Tensor,
weight_scale: Tensor,
block_size: Sequence[int] = (128, 128),
) -> None
Re-quantise weight so that its per-block scaling factors are in the UE8M0 (power-of-two) format expected by the new DeepGEMM kernels inplace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
weight | Tensor | Block-quantised weight tensor stored in | required |
weight_scale | Tensor | Corresponding per-block scale tensor ( | required |
block_size | Sequence[int] | 2-element iterable | (128, 128) |
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
rocm_aiter_gemm_w8a8_blockscale_fake ¶
rocm_aiter_gemm_w8a8_blockscale_fake(
A: Tensor,
B: Tensor,
As: Tensor,
Bs: Tensor,
block_size: list[int],
output_dtype: dtype = float16,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
rocm_aiter_gemm_w8a8_blockscale_impl ¶
rocm_aiter_gemm_w8a8_blockscale_impl(
A: Tensor,
B: Tensor,
As: Tensor,
Bs: Tensor,
block_size: list[int],
output_dtype: dtype = float16,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
w8a8_block_fp8_matmul ¶
w8a8_block_fp8_matmul(
A: Tensor,
B: Tensor,
As: Tensor,
Bs: Tensor,
block_size: list[int],
output_dtype: dtype = float16,
) -> Tensor
This function performs matrix multiplication with block-wise quantization. It takes two input tensors A
and B
with scales As
and Bs
. The output is returned in the specified output_dtype
. Args: A: The input tensor, e.g., activation. B: The input tensor, e.g., weight. As: The per-token-group quantization scale for A
. Bs: The per-block quantization scale for B
. block_size: The block size for per-block quantization. It should be 2-dim, e.g., [128, 128]. output_dytpe: The dtype of the returned tensor. Returns: torch.Tensor: The result of matmul.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
|