[UT][XPU] fix b12x UT (#52265)

Signed-off-by: mayuyuace <qiming1.zhang@intel.com>
Signed-off-by: Andreas Karatzas <Andreas.Karatzas@amd.com>
Co-authored-by: Andreas Karatzas <Andreas.Karatzas@amd.com>
This commit is contained in:
Qiming Zhang
2026-08-14 09:49:47 -04:00
committed by GitHub
co-authored by Andreas Karatzas
parent 57bd0ed441
commit 1f7427bc0a
2 changed files with 24 additions and 3 deletions
@@ -46,7 +46,7 @@ from vllm.model_executor.layers.quantization.utils.quant_utils import (
kFp8Static128BlockSym,
kFp8StaticTensorSym,
)
from vllm.platforms import PlatformEnum
from vllm.platforms import PlatformEnum, current_platform
from vllm.utils.b12x import b12x_warmup_token_counts
@@ -100,6 +100,7 @@ def test_b12x_backend_does_not_intercept_unquantized_bf16(
dist_init,
) -> None:
default_vllm_config.kernel_config.linear_backend = "b12x"
device = current_platform.device_type
layer = ReplicatedLinear(
128,
64,
@@ -107,9 +108,9 @@ def test_b12x_backend_does_not_intercept_unquantized_bf16(
params_dtype=torch.bfloat16,
quant_config=None,
prefix="bf16_linear",
).cuda()
).to(device)
layer.weight.data.normal_()
x = torch.randn(8, 128, device="cuda", dtype=torch.bfloat16)
x = torch.randn(8, 128, device=device, dtype=torch.bfloat16)
output, output_bias = layer(x)
expected = torch.nn.functional.linear(x, layer.weight)
@@ -767,6 +768,24 @@ def test_b12x_mxfp8_reload_reuses_packed_tensor_addresses(monkeypatch) -> None:
assert layer.weight_scale.numel() == 0
@pytest.fixture
def _mock_b12x_cuda_fp8_platform(monkeypatch: pytest.MonkeyPatch) -> None:
import vllm.model_executor.layers.quantization.utils.fp8_utils as fp8_utils
monkeypatch.setattr(
fp8_utils,
"current_platform",
types.SimpleNamespace(
is_fp8_fnuz=lambda: False,
is_rocm=lambda: False,
fp8_dtype=lambda: torch.float8_e4m3fn,
is_xpu=lambda: False,
is_cuda_alike=lambda: True,
),
)
@pytest.mark.usefixtures("_mock_b12x_cuda_fp8_platform")
def test_b12x_block_fp8_process_weights_keeps_native_block_layout() -> None:
layer = torch.nn.Module()
layer.weight = torch.nn.Parameter(
@@ -796,6 +815,7 @@ def test_b12x_block_fp8_process_weights_keeps_native_block_layout() -> None:
@pytest.mark.parametrize("scale_dtype", [torch.float8_e8m0fnu, torch.uint8])
@pytest.mark.usefixtures("_mock_b12x_cuda_fp8_platform")
def test_b12x_block_fp8_upcasts_e8m0_weight_scales(scale_dtype) -> None:
layer = torch.nn.Module()
layer.weight = torch.nn.Parameter(