vllm.model_executor.layers.quantization.utils.fp8_utils ¶
W8A8BlockFp8LinearOp ¶
This class executes a Blocked FP8 linear layer using cutlass if supported and torch.scaled_mm otherwise.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
213 214 215 216 217 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 349 | |
deepgemm_input_quant_op instance-attribute ¶
deepgemm_input_quant_op = (
QuantFP8(
False,
act_quant_group_shape,
column_major_scales=True,
use_ue8m0=use_deep_gemm_e8m0,
)
if is_deep_gemm_supported
else None
)
__init__ ¶
__init__(
weight_group_shape: GroupShape,
act_quant_group_shape: GroupShape,
cutlass_block_fp8_supported: bool = CUTLASS_BLOCK_FP8_SUPPORTED,
use_aiter_and_is_supported: bool = False,
)
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_dispatch_w8a8_blockscale_op ¶
_dispatch_w8a8_blockscale_op(
use_cutlass: bool, use_aiter_and_is_supported: bool
) -> tuple[
Callable[[Tensor, Tensor, Tensor], Tensor],
Optional[QuantFP8],
]
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_run_aiter ¶
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_run_cutlass ¶
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_run_deepgemm ¶
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_run_triton ¶
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
apply ¶
apply(
input: Tensor,
weight: Tensor,
weight_scale: Tensor,
input_scale: Optional[Tensor] = None,
bias: Optional[Tensor] = None,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_fp8_gemm_nt_op ¶
_fp8_gemm_nt_op(
q_input: Tensor,
input_scale: Tensor,
weight: Tensor,
weight_scale: Tensor,
output: Tensor,
use_deep_gemm_e8m0: bool,
) -> None
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_fp8_gemm_nt_op_fake ¶
_maybe_pad_fp8_weight ¶
Pad the weight tensor. This is an optimization on ROCm platform, which can benefit from tensors located far enough from one another in memory
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_padded_cutlass ¶
_padded_cutlass(
qx: Tensor,
weight: Tensor,
x_scale: Tensor,
weight_scale: Tensor,
block_size: list[int],
output_dtype: dtype,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_padded_cutlass_fake ¶
_padded_cutlass_fake(
qx: Tensor,
weight: Tensor,
x_scale: Tensor,
weight_scale: Tensor,
block_size: list[int],
output_dtype: dtype,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_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_triton_block_scaled_mm ¶
_w8a8_triton_block_scaled_mm(
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
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 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
_w8a8_triton_block_scaled_mm_fake ¶
_w8a8_triton_block_scaled_mm_fake(
qx: Tensor,
weight: Tensor,
x_scale: Tensor,
weight_scale: Tensor,
block_size: list[int],
output_dtype: dtype,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_w8a8_triton_block_scaled_mm_func ¶
_w8a8_triton_block_scaled_mm_func(
qx: Tensor,
weight: Tensor,
x_scale: Tensor,
weight_scale: Tensor,
block_size: list[int],
output_dtype: dtype,
) -> 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
check_aiter_fp8_linear_support ¶
check_aiter_fp8_linear_support() -> bool
AITER is only supported on ROCm and only for FP8_FNUZ and at the moment are MI300 series
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
create_fp8_input_scale ¶
create_fp8_input_scale(
output_partition_sizes: list[int],
weight_loader: Optional[Callable],
) -> Parameter
Create input scale parameter for static activation quantization.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
create_fp8_scale_parameter ¶
create_fp8_scale_parameter(
parameter_type: Parameter,
output_partition_sizes: list[int],
input_size_per_partition: int,
block_size: Optional[list[int]],
weight_loader: Optional[Callable],
) -> Parameter
Create scale parameter based on quantization strategy.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
create_fp8_weight_parameter ¶
create_fp8_weight_parameter(
output_size_per_partition: int,
input_size_per_partition: int,
weight_loader: Optional[Callable],
) -> Parameter
Create FP8 weight parameter.
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,
is_hopper: Optional[bool] = None,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
expert_weight_is_col_major ¶
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 ¶
maybe_post_process_fp8_weight_block ¶
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
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
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 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 596 597 | |
process_fp8_weight_block_strategy ¶
Process weights for block-wise quantization strategy.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
process_fp8_weight_channel_strategy ¶
process_fp8_weight_channel_strategy(
weight: Tensor,
weight_scale: Tensor,
input_scale: Optional[Tensor] = None,
) -> tuple[Tensor, Tensor, Optional[Tensor]]
Process weights for channel-wise quantization strategy.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
process_fp8_weight_tensor_strategy ¶
process_fp8_weight_tensor_strategy(
weight: Tensor,
weight_scale: Tensor,
logical_widths: list[int],
input_scale: Optional[Tensor] = None,
) -> tuple[Tensor, Tensor, Optional[Tensor]]
Process weights for tensor-wise quantization strategy.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
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
validate_fp8_block_shape ¶
validate_fp8_block_shape(
layer: Module,
input_size: int,
output_size: int,
input_size_per_partition: int,
output_partition_sizes: list[int],
block_size: list[int],
) -> None
Validate block quantization shapes for tensor parallelism.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
w8a8_triton_block_scaled_mm ¶
w8a8_triton_block_scaled_mm(
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
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 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | |