vllm.model_executor.layers.quantization.utils.fp8_utils ¶
_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
_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: constexpr,
fp8_max: constexpr,
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: constexpr,
fp8_max: constexpr,
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
_silu_mul_per_token_group_quant_fp8_colmajor ¶
_silu_mul_per_token_group_quant_fp8_colmajor(
y_ptr,
y_q_ptr,
y_s_ptr,
M,
N,
y_s_col_stride: int64,
eps,
fp8_min: constexpr,
fp8_max: constexpr,
use_ue8m0: constexpr,
GROUP_SIZE: constexpr,
BLOCK_M: constexpr,
BLOCK_N: constexpr,
)
Each thread block (BLOCK_N) computes [BLOCK_M, GROUP_SIZE] act-mul outputs. Then the thread block quantizes the [BLOCK_M, GROUP_SIZE] block of values and fills the outputs tensors at the right positions.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
_upcast_e8m0_to_fp32 ¶
Upcast E8M0 (exponent-only) scale to float32.
E8M0 stores only the 8-bit biased exponent (bias=127). To convert to float32 we place those 8 bits into the exponent field of an IEEE-754 float32 (bits 23-30) with sign=0 and mantissa=0.
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
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 770 771 772 773 774 775 776 777 778 | |
create_fp8_input_scale ¶
create_fp8_input_scale(
output_partition_sizes: list[int],
weight_loader: Callable | None,
) -> 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: list[int] | None,
weight_loader: Callable | None,
scale_dtype: dtype | None = None,
) -> 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: Callable | None,
) -> Parameter
Create FP8 weight parameter.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
get_w8a8_block_fp8_configs cached ¶
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
per_token_group_quant_fp8 ¶
per_token_group_quant_fp8(
x: Tensor,
group_size: int,
eps: float = 1e-10,
dtype: dtype | None = None,
column_major_scales: bool = False,
tma_aligned_scales: bool = False,
out_q: Tensor | None = None,
use_ue8m0: bool | None = 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 dtype of output tensor. Note that only torch.float8_e4m3fn is supported for now. column_major_scales: Outputs scales in column major. tma_aligned_scales: Outputs scales in TMA-aligned layout. 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
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 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 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
per_token_group_quant_fp8_packed_for_deepgemm ¶
per_token_group_quant_fp8_packed_for_deepgemm(
x: Tensor,
group_size: int,
eps: float = 1e-10,
use_ue8m0: bool | None = None,
out_q: Tensor | None = None,
) -> tuple[Tensor, Tensor]
FP8 per-token-group quantization for DeepGEMM.
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor] | (x_q, x_s_packed) x_q: FP8 activations, same shape as |
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
process_fp8_input_tensor_strategy_moe ¶
process_fp8_input_tensor_strategy_moe(
w13_input_scale: Tensor, w2_input_scale: Tensor
) -> tuple[Tensor, Tensor]
Process moe input scales for tensor-wise quantization strategy.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
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: Tensor | None = None,
) -> tuple[Tensor, Tensor, Tensor | None]
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: Tensor | None = None,
) -> tuple[Tensor, Tensor, Tensor | None]
Process weights for tensor-wise quantization strategy.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
process_fp8_weight_tensor_strategy_moe ¶
process_fp8_weight_tensor_strategy_moe(
weight: Tensor,
weight_scales: Tensor,
shard_size: int,
num_experts: int,
is_act_and_mul: bool = True,
) -> tuple[Tensor, Tensor]
Process moe 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
silu_mul_per_token_group_quant_fp8_colmajor ¶
silu_mul_per_token_group_quant_fp8_colmajor(
input: Tensor,
output: Tensor | None = None,
use_ue8m0: bool | None = None,
eps: float = 1e-10,
)
silu+mul + block-fp8 quant with group size 128.
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
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | |