[ROCm][Quark][6/N] Use MXFP4 linear kernel abstraction for aiter backend (#49348)
Signed-off-by: Felix Marty <Felix.Marty@amd.com> Co-authored-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
co-authored by
Andreas Karatzas
parent
73af7a362a
commit
7aea73d83d
@@ -17,6 +17,7 @@ import pytest
|
||||
import torch
|
||||
from packaging import version
|
||||
|
||||
from vllm._aiter_ops import is_aiter_found_and_supported
|
||||
from vllm.model_executor.layers.quantization.quark.quark import ( # noqa: E501
|
||||
QuarkLinearMethod,
|
||||
QuarkW8A8Fp8,
|
||||
@@ -26,6 +27,9 @@ from vllm.model_executor.layers.quantization.quark.quark_moe import ( # noqa: E
|
||||
QuarkW4A8Fp8MoEMethod,
|
||||
QuarkW8A8Int8MoEMethod,
|
||||
)
|
||||
from vllm.model_executor.layers.quantization.utils.mxfp4_utils import (
|
||||
quant_dequant_mxfp4,
|
||||
)
|
||||
from vllm.model_executor.layers.quantization.utils.quant_utils import (
|
||||
is_layer_skipped,
|
||||
)
|
||||
@@ -52,6 +56,8 @@ QUARK_MXFP4_AVAILABLE = find_spec("quark") is not None and version.parse(
|
||||
importlib.metadata.version("amd-quark")
|
||||
) >= version.parse(QUARK_MXFP4_MIN_VERSION)
|
||||
|
||||
AITER_AVAILABLE = is_aiter_found_and_supported()
|
||||
|
||||
DEVICE_TYPE = current_platform.device_type
|
||||
|
||||
if QUARK_MXFP4_AVAILABLE:
|
||||
@@ -487,6 +493,42 @@ def test_mxfp4_dequant_kernel_match_quark(
|
||||
assert torch.equal(out_hip, out_torch)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not QUARK_MXFP4_AVAILABLE,
|
||||
reason=f"amd-quark>={QUARK_MXFP4_MIN_VERSION} is not available",
|
||||
)
|
||||
@pytest.mark.skipif(
|
||||
not AITER_AVAILABLE,
|
||||
reason="AITER is not found or not supported on the current platform",
|
||||
)
|
||||
@pytest.mark.parametrize("float_dtype", [torch.bfloat16, torch.float16])
|
||||
@pytest.mark.parametrize("scalings", [[2.3, 0.03, 7.3, 0.1, 0.004, 17.3, 1e4, 1e-4]])
|
||||
def test_mxfp4_dynamic_quant_match_quark(
|
||||
float_dtype: torch.dtype, scalings: list[float]
|
||||
):
|
||||
"""`AiterMxfp4LinearKernel` quantizes weights dynamically through AITER's
|
||||
`dynamic_mxfp4_quant`, while the emulation path quantizes/dequantizes
|
||||
through Quark's `qdq_mxfp4`. Check that both agree on the same input.
|
||||
"""
|
||||
from aiter.ops.triton.quant import dynamic_mxfp4_quant
|
||||
|
||||
torch.manual_seed(0)
|
||||
|
||||
hidden_size = 32 * 64
|
||||
inp = (torch.rand(48, hidden_size, dtype=float_dtype, device=DEVICE_TYPE) - 0.5) * 2
|
||||
for i in range(hidden_size // 32):
|
||||
inp[:, i * 32 : (i + 1) * 32] = (
|
||||
inp[:, i * 32 : (i + 1) * 32] * scalings[i % len(scalings)]
|
||||
)
|
||||
|
||||
x_q, x_s = dynamic_mxfp4_quant(inp)
|
||||
out_dynamic_quant = dq_mxfp4_torch(x_q, x_s, float_dtype)
|
||||
|
||||
out_quark_qdq = quant_dequant_mxfp4(inp)
|
||||
|
||||
assert torch.equal(out_dynamic_quant, out_quark_qdq)
|
||||
|
||||
|
||||
# Unit tests for ``is_layer_skipped`` fused-name handling.
|
||||
|
||||
FUSED_MAPPING = {
|
||||
|
||||
Reference in New Issue
Block a user