[XPU] Unify XPU RMSNorm kernels with vllm_c and drop redundant XPU-specific implementation (#46981)
Signed-off-by: Chaojun Zhang <chaojun.zhang@intel.com> Co-authored-by: Kunshang Ji <kunshang.ji@intel.com>
This commit is contained in:
co-authored by
Kunshang Ji
parent
5d7647a109
commit
482cfc20f0
@@ -56,11 +56,13 @@ steps:
|
||||
source_file_dependencies:
|
||||
- vllm/v1/engine/
|
||||
- tests/v1/engine/
|
||||
- tests/test_config/
|
||||
commands:
|
||||
- >-
|
||||
bash .buildkite/scripts/hardware_ci/run-intel-test.sh
|
||||
'cd tests &&
|
||||
pytest -v -s v1/engine --ignore v1/engine/test_preprocess_error_handling.py'
|
||||
pytest -v -s v1/engine --ignore v1/engine/test_preprocess_error_handling.py &&
|
||||
VLLM_XPU_ENABLE_XPU_GRAPH=1 pytest -v -s test_config.py'
|
||||
|
||||
- label: V1 e2e (2 GPUs)
|
||||
timeout_in_minutes: 30
|
||||
|
||||
@@ -22,4 +22,5 @@ steps:
|
||||
- >-
|
||||
bash .buildkite/scripts/hardware_ci/run-intel-test.sh
|
||||
'cd tests &&
|
||||
pytest -v -s ir &&
|
||||
pytest -v -s kernels/ir'
|
||||
|
||||
@@ -18,20 +18,21 @@ from vllm.platforms import current_platform
|
||||
|
||||
rms_norm_native = ir.ops.rms_norm.impls["native"].impl_fn
|
||||
|
||||
IS_GPGPU_DEVICE = current_platform.is_cuda_alike() or current_platform.is_xpu()
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not current_platform.is_cuda_alike() and not current_platform.is_xpu(),
|
||||
not IS_GPGPU_DEVICE,
|
||||
reason="Currently only kernels on CUDA, ROCm and XPU",
|
||||
)
|
||||
def test_rms_norm_registration():
|
||||
expected = {
|
||||
"native": True,
|
||||
"vllm_c": current_platform.is_cuda_alike(),
|
||||
"vllm_c": IS_GPGPU_DEVICE,
|
||||
"aiter": current_platform.is_rocm(),
|
||||
"oink": current_platform.has_device_capability(100)
|
||||
and hasattr(torch.ops, "oink")
|
||||
and hasattr(torch.ops.oink, "rmsnorm"),
|
||||
"xpu_kernels": current_platform.is_xpu(),
|
||||
}
|
||||
|
||||
actual = {
|
||||
@@ -46,7 +47,7 @@ def test_rms_norm_registration():
|
||||
@pytest.mark.parametrize("hidden_size", COMMON_HIDDEN_SIZES)
|
||||
@pytest.mark.parametrize("epsilon", [1e-6, 1e-5])
|
||||
@pytest.mark.skipif(
|
||||
not current_platform.is_cuda_alike() and not current_platform.is_xpu(),
|
||||
not IS_GPGPU_DEVICE,
|
||||
reason="Currently only kernels on CUDA, ROCm and XPU",
|
||||
)
|
||||
class TestRMSNorm:
|
||||
@@ -117,7 +118,7 @@ class TestRMSNorm:
|
||||
out_unit_weight = impl.impl_fn(x, torch.ones_like(weight), eps)
|
||||
assert_close(ir.ops.rms_norm, out_no_weight, out_unit_weight)
|
||||
|
||||
@pytest.mark.parametrize("provider", ["vllm_c", "aiter", "xpu_kernels", "native"])
|
||||
@pytest.mark.parametrize("provider", ["vllm_c", "aiter", "native"])
|
||||
def test_torch_opcheck(self, dtype, n_tokens, hidden_size, epsilon, provider):
|
||||
if not ir.ops.rms_norm.impls[provider].supported:
|
||||
pytest.skip(f"{provider} impl not supported on this platform")
|
||||
@@ -203,18 +204,17 @@ fused_add_rms_norm_native = ir.ops.fused_add_rms_norm.impls["native"].impl_fn
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not current_platform.is_cuda_alike() and not current_platform.is_xpu(),
|
||||
not IS_GPGPU_DEVICE,
|
||||
reason="Currently only kernels on CUDA, ROCm and XPU",
|
||||
)
|
||||
def test_fused_add_rms_norm_registration():
|
||||
expected = {
|
||||
"native": True,
|
||||
"vllm_c": current_platform.is_cuda_alike(),
|
||||
"vllm_c": IS_GPGPU_DEVICE,
|
||||
"aiter": current_platform.is_rocm(),
|
||||
"oink": current_platform.has_device_capability(100)
|
||||
and hasattr(torch.ops, "oink")
|
||||
and hasattr(torch.ops.oink, "fused_add_rms_norm"),
|
||||
"xpu_kernels": current_platform.is_xpu(),
|
||||
}
|
||||
|
||||
actual = {
|
||||
@@ -261,7 +261,7 @@ def test_vllm_c_fused_add_rms_norm_accepts_nd_input():
|
||||
@pytest.mark.parametrize("hidden_size", COMMON_HIDDEN_SIZES)
|
||||
@pytest.mark.parametrize("epsilon", [1e-6, 1e-5])
|
||||
@pytest.mark.skipif(
|
||||
not current_platform.is_cuda_alike() and not current_platform.is_xpu(),
|
||||
not IS_GPGPU_DEVICE,
|
||||
reason="Currently only kernels on CUDA, ROCm and XPU",
|
||||
)
|
||||
class TestFusedAddRMSNorm:
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Kernel implementations for vLLM."""
|
||||
|
||||
from . import aiter_ops, oink_ops, vllm_c, xpu_ops
|
||||
from . import aiter_ops, oink_ops, vllm_c
|
||||
|
||||
__all__ = ["vllm_c", "aiter_ops", "oink_ops", "xpu_ops"]
|
||||
__all__ = ["vllm_c", "aiter_ops", "oink_ops"]
|
||||
|
||||
@@ -12,6 +12,7 @@ CUDA_ALIKE = current_platform.is_cuda_alike()
|
||||
"""Most kernels in this file are supported on all CUDA-alike platforms."""
|
||||
IS_ROCM = current_platform.is_rocm()
|
||||
"""ROCm needs shape normalization before calling some vLLM C kernels."""
|
||||
GPGPU_DEVICE = CUDA_ALIKE or current_platform.is_xpu()
|
||||
|
||||
rms_no_var_size = lambda x, weight, epsilon, variance_size=None: (
|
||||
variance_size is None and (weight is None or weight.dtype == x.dtype)
|
||||
@@ -20,7 +21,7 @@ rms_no_var_size = lambda x, weight, epsilon, variance_size=None: (
|
||||
|
||||
|
||||
@ir.ops.rms_norm.register_impl(
|
||||
"vllm_c", supports_args=rms_no_var_size, supported=CUDA_ALIKE
|
||||
"vllm_c", supports_args=rms_no_var_size, supported=GPGPU_DEVICE
|
||||
)
|
||||
def rms_norm(
|
||||
x: Tensor, weight: Tensor | None, epsilon: float, variance_size: int | None = None
|
||||
@@ -53,7 +54,7 @@ matching input/weight dtype."""
|
||||
@ir.ops.fused_add_rms_norm.register_impl(
|
||||
"vllm_c",
|
||||
supports_args=rms_add_no_var_size,
|
||||
supported=CUDA_ALIKE,
|
||||
supported=GPGPU_DEVICE,
|
||||
inplace=True,
|
||||
)
|
||||
def fused_add_rms_norm(
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
import torch
|
||||
from torch import Tensor
|
||||
|
||||
from vllm import ir
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
current_platform.import_kernels()
|
||||
|
||||
|
||||
def is_xpu_kernels_found() -> bool:
|
||||
from importlib.util import find_spec
|
||||
|
||||
return find_spec("vllm_xpu_kernels") is not None
|
||||
|
||||
|
||||
XPU_KERNELS_SUPPORTED = is_xpu_kernels_found()
|
||||
"""Kernels in this file are supported if vLLM XPU kernels are installed."""
|
||||
|
||||
rms_no_var = lambda x, weight, epsilon, variance_size=None: variance_size is None and (
|
||||
weight is None or weight.dtype == x.dtype
|
||||
)
|
||||
|
||||
|
||||
@ir.ops.rms_norm.register_impl(
|
||||
"xpu_kernels", supports_args=rms_no_var, supported=XPU_KERNELS_SUPPORTED
|
||||
)
|
||||
def rms_norm(
|
||||
x: Tensor, weight: Tensor | None, epsilon: float, variance_size: int | None = None
|
||||
) -> Tensor:
|
||||
assert variance_size is None
|
||||
output = torch.empty(x.shape, device=x.device, dtype=x.dtype)
|
||||
torch.ops._C.rms_norm(output, x, weight, epsilon)
|
||||
return output
|
||||
|
||||
|
||||
rms_add_no_var_size = (
|
||||
lambda x, x_residual, weight, epsilon, variance_size=None: variance_size is None
|
||||
and (weight is None or weight.dtype == x.dtype)
|
||||
)
|
||||
|
||||
|
||||
@ir.ops.fused_add_rms_norm.register_impl(
|
||||
"xpu_kernels",
|
||||
supports_args=rms_add_no_var_size,
|
||||
supported=XPU_KERNELS_SUPPORTED,
|
||||
inplace=True,
|
||||
)
|
||||
def fused_add_rms_norm(
|
||||
x: Tensor,
|
||||
x_residual: Tensor,
|
||||
weight: Tensor | None,
|
||||
epsilon: float,
|
||||
variance_size: int | None = None,
|
||||
) -> tuple[Tensor, Tensor]:
|
||||
assert variance_size is None
|
||||
torch.ops._C.fused_add_rms_norm(x, x_residual, weight, epsilon)
|
||||
return x, x_residual
|
||||
@@ -465,7 +465,7 @@ class XPUPlatform(Platform):
|
||||
# use fused kernels where available when no codegen
|
||||
cc = vllm_config.compilation_config
|
||||
using_inductor = cc.backend == "inductor" and cc.mode != CompilationMode.NONE
|
||||
default = ["native"] if using_inductor else ["xpu_kernels", "native"]
|
||||
default = ["native"] if using_inductor else ["vllm_c", "native"]
|
||||
|
||||
return IrOpPriorityConfig.with_default(default)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user