vllm.model_executor.layers.quantization.utils.marlin_utils_fp4 ¶
Functions:
-
nvfp4_marlin_process_scales–Process NVFP4 weight scales into the special S0E5M3 format for Marlin.
-
prepare_moe_mxfp4_layer_for_marlin–Pure-function version of prepare_moe_fp4_layer_for_marlin for MXFP4.
_nvfp4_compute_scale_factor(marlin_scales, a_dtype=None) ¶
Compute the power-of-2 scale_factor needed so that all non-zero values in marlin_scales * 2^7 are >= 2 after rescaling. Returns a Python float (power of 2, >= 1.0).
Source code in vllm/model_executor/layers/quantization/utils/marlin_utils_fp4.py
nvfp4_marlin_process_scales(marlin_scales, scale_factor=None, a_dtype=None) ¶
Process NVFP4 weight scales into the special S0E5M3 format for Marlin.
Parameters:
-
(marlin_scales¶Tensor) –Weight scales tensor in half precision, already permuted for the Marlin kernel layout.
-
(scale_factor¶float | None, default:None) –Optional power-of-2 rescaling factor. If None, the factor is computed automatically so that every non-zero scale satisfies
scale * 2^7 >= 2(i.e., the MSB of the S0E5M3 representation is always 1). When provided (e.g., for MoE layers where all experts must share the same factor), the given value is used directly. The caller is responsible for dividingglobal_scaleby the returnedscale_factorto preserve numerical correctness.
Returns:
Source code in vllm/model_executor/layers/quantization/utils/marlin_utils_fp4.py
prepare_moe_mxfp4_layer_for_marlin(layer, w13, w2, w13_scale, w2_scale, w13_bias, w2_bias) ¶
Pure-function version of prepare_moe_fp4_layer_for_marlin for MXFP4.
Takes weight tensors as inputs and returns transformed tensors. Does NOT modify the layer in-place.
Source code in vllm/model_executor/layers/quantization/utils/marlin_utils_fp4.py
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 | |