vllm.model_executor.layers.quantization.utils.fp8_utils ¶
Functions:
-
create_fp8_input_scale–Create input scale parameter for static activation quantization.
-
create_fp8_scale_parameter–Create scale parameter based on quantization strategy.
-
create_fp8_weight_parameter–Create FP8 weight parameter.
-
get_w8a8_block_fp8_configs–Return optimized configurations for the w8a8 block fp8 kernel.
-
input_to_float8–This function quantizes input values to float8 values "
-
per_token_group_quant_fp8–Function to perform per-token-group quantization on an input tensor
x. -
per_token_group_quant_fp8_packed_for_deepgemm–FP8 per-token-group quantization for DeepGEMM.
-
process_fp8_input_tensor_strategy_moe–Process moe input scales for tensor-wise quantization strategy.
-
process_fp8_weight_block_strategy–Process weights for block-wise quantization strategy.
-
process_fp8_weight_channel_strategy–Process weights for channel-wise quantization strategy.
-
process_fp8_weight_tensor_strategy–Process weights for tensor-wise quantization strategy.
-
process_fp8_weight_tensor_strategy_moe–Process moe weights for tensor-wise quantization strategy.
-
requant_weight_ue8m0_inplace–Re-quantise weight so that its per-block scaling factors are in the
-
silu_mul_per_token_group_quant_fp8_colmajor–Gated activation + block-fp8 quant.
alpha/betaselect the gate -
validate_fp8_block_shape–Validate block quantization shapes for tensor parallelism.
-
w8a8_triton_block_scaled_mm–This function performs matrix multiplication with block-wise
_maybe_pad_fp8_weight(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(y_ptr, y_q_ptr, y_s_ptr, group_size, y_num_columns, y_row_stride, eps, fp8_min, fp8_max, use_ue8m0, BLOCK) ¶
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(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, BLOCK) ¶
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(y_ptr, y_q_ptr, y_s_ptr, M, N, y_s_col_stride, eps, clamp_limit, alpha, beta, fp8_min, fp8_max, use_ue8m0, HAS_CLAMP, GROUP_SIZE, BLOCK_M, BLOCK_N) ¶
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
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 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 | |
_upcast_e8m0_to_fp32(scale) ¶
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(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, BLOCK_SIZE_N, BLOCK_SIZE_K, GROUP_SIZE_M) ¶
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
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 811 812 813 814 815 816 817 818 819 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 | |
create_fp8_input_scale(output_partition_sizes, weight_loader) ¶
Create input scale parameter for static activation quantization.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
create_fp8_scale_parameter(parameter_type, output_partition_sizes, input_size_per_partition, block_size, weight_loader, scale_dtype=None) ¶
Create scale parameter based on quantization strategy.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
create_fp8_weight_parameter(output_size_per_partition, input_size_per_partition, weight_loader) ¶
Create FP8 weight parameter.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
get_w8a8_block_fp8_configs(N, K, block_n, block_k) 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(x, dtype=None) ¶
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(x, group_size, eps=1e-10, dtype=None, column_major_scales=False, tma_aligned_scales=False, out_q=None, use_ue8m0=None) ¶
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
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 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 687 688 689 690 691 692 | |
per_token_group_quant_fp8_packed_for_deepgemm(x, group_size, eps=1e-10, use_ue8m0=None, out_q=None) ¶
FP8 per-token-group quantization for DeepGEMM.
Returns:
-
tuple[Tensor, Tensor]–(x_q, x_s_packed) x_q: FP8 activations, same shape as
x. x_s_packed: Int32 tensor with logical shape [mn, ceil(num_groups_per_row / 4)], laid out with TMA-aligned stride along the packed-K dimension
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
process_fp8_input_tensor_strategy_moe(w13_input_scale, w2_input_scale) ¶
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(weight, weight_scale) ¶
Process weights for block-wise quantization strategy.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
process_fp8_weight_channel_strategy(weight, weight_scale, input_scale=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(weight, weight_scale, logical_widths, input_scale=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(weight, weight_scales, shard_size, num_experts, is_act_and_mul=True) ¶
Process moe weights for tensor-wise quantization strategy.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
requant_weight_ue8m0_inplace(weight, weight_scale, block_size=(128, 128)) ¶
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:
-
(weight¶Tensor) –Block-quantised weight tensor stored in
torch.float8_e4m3fn. Expected shape(..., M, K). -
(weight_scale¶Tensor) –Corresponding per-block scale tensor (
torch.float32) with shape(..., M // block_size[0], K // block_size[1]). -
(block_size¶Sequence[int], default:(128, 128)) –2-element iterable
[block_m, block_k]describing the block quantisation granularity.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
silu_mul_per_token_group_quant_fp8_colmajor(input, output=None, use_ue8m0=None, eps=1e-10, clamp_limit=None, group_size=128, alpha=1.0, beta=0.0) ¶
Gated activation + block-fp8 quant. alpha/beta select the gate (silu: alpha=1, beta=0; swigluoai: alpha, beta from config).
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
validate_fp8_block_shape(layer, input_size, output_size, input_size_per_partition, output_partition_sizes, block_size) ¶
Validate block quantization shapes for tensor parallelism.
Source code in vllm/model_executor/layers/quantization/utils/fp8_utils.py
w8a8_triton_block_scaled_mm(A, B, As, Bs, block_size, output_dtype=torch.float16) ¶
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
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 | |