[Misc] Add and enable Triton kernel unit tests on XPU (#45694)

Signed-off-by: pmanczak <pmanczak@users.noreply.github.com>
Signed-off-by: pmanczak <pawel.manczak@intel.com>
Co-authored-by: pmanczak <pmanczak@users.noreply.github.com>
This commit is contained in:
pmanczak
2026-08-07 02:53:03 -07:00
committed by GitHub
co-authored by pmanczak
parent 5ec47f3e48
commit 6b5bec7bed
5 changed files with 58 additions and 13 deletions
+11 -8
View File
@@ -5,6 +5,7 @@ import pytest
import torch
import torch.nn.functional as F
from vllm.platforms import current_platform
from vllm.third_party.flash_linear_attention.ops.layernorm_guard import (
layer_norm_fwd,
layernorm_fn,
@@ -12,6 +13,8 @@ from vllm.third_party.flash_linear_attention.ops.layernorm_guard import (
)
from vllm.utils.torch_utils import set_random_seed
DEVICE = "xpu" if current_platform.is_xpu() else "cuda"
def layer_norm_ref(
x,
@@ -115,7 +118,7 @@ def test_layer_norm_fwd_basic(
) -> None:
"""Test basic layer norm forward pass without z (gate) tensor."""
set_random_seed(seed)
device = torch.device("cuda:0")
device = torch.device(DEVICE)
# Create inputs
x = torch.randn(num_tokens, hidden_size, dtype=dtype, device=device)
@@ -157,7 +160,7 @@ def test_layer_norm_fwd_with_gate(
) -> None:
"""Test layer norm forward pass with z (gate) tensor."""
set_random_seed(42)
device = torch.device("cuda:0")
device = torch.device(DEVICE)
# Create inputs
x = torch.randn(num_tokens, hidden_size, dtype=dtype, device=device)
@@ -214,7 +217,7 @@ def test_layer_norm_fwd_with_groups(
)
set_random_seed(42)
device = torch.device("cuda:0")
device = torch.device(DEVICE)
# Create inputs
x = torch.randn(num_tokens, hidden_size, dtype=dtype, device=device)
@@ -254,7 +257,7 @@ def test_layer_norm_rows_per_block(
) -> None:
"""Test that rows_per_block logic works correctly for various M sizes."""
set_random_seed(42)
device = torch.device("cuda:0")
device = torch.device(DEVICE)
hidden_size = 1024
# Create inputs
@@ -279,7 +282,7 @@ def test_strided_input(dtype: torch.dtype) -> None:
"""Test that the kernel handles non-contiguous (strided)
inputs correctly."""
set_random_seed(42)
device = torch.device("cuda:0")
device = torch.device(DEVICE)
num_tokens = 128
hidden_size = 1024
@@ -319,7 +322,7 @@ def test_output_buffer_provided(
) -> None:
"""Test that the kernel works when an output buffer is provided."""
set_random_seed(42)
device = torch.device("cuda:0")
device = torch.device(DEVICE)
# Create inputs
x = torch.randn(num_tokens, hidden_size, dtype=dtype, device=device)
@@ -360,7 +363,7 @@ def test_multidimensional_input(
) -> None:
"""Test that the autograd function handles multidimensional inputs."""
set_random_seed(42)
device = torch.device("cuda:0")
device = torch.device(DEVICE)
hidden_size = shape[-1]
# Create inputs
@@ -404,7 +407,7 @@ def test_rmsnorm_gated_forward_native_dtype(
from vllm.model_executor.layers.layernorm import RMSNormGated
device = torch.device("cuda:0")
device = torch.device(DEVICE)
set_random_seed(42)
layer = RMSNormGated(