Skip to content

vllm.models.hy_v4.weight_utils

Functions:

remap_block_fp8_scale(name, weight, quant_config)

Map a block-FP8 checkpoint .scale onto the weight_scale_inv param.

Source code in vllm/models/hy_v4/weight_utils.py
def remap_block_fp8_scale(
    name: str, weight: torch.Tensor, quant_config: QuantizationConfig | None
) -> tuple[str, torch.Tensor]:
    """Map a block-FP8 checkpoint `.scale` onto the `weight_scale_inv` param."""
    if (
        isinstance(quant_config, Fp8Config)
        and quant_config.weight_block_size is not None
        and name.endswith(".scale")
    ):
        name = name.removesuffix(".scale") + ".weight_scale_inv"
        if weight.dtype == torch.uint8:
            # UINT8 stores UE8M0 exponents, not numeric scales.
            weight = weight.view(torch.float8_e8m0fnu)
    return name, weight