Skip to content
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c0ffa12
[Hardware][XPU] Added registration of verified batch-invariant kernel…
tzielinski-habana May 5, 2026
974211e
Refactoring and minor fixes
tzielinski-habana May 7, 2026
498fa8b
Update tests/v1/determinism/test_xpu_batch_invariant.py
tzielinski-habana May 7, 2026
5024a1b
Merge branch 'main' into xpu_rl
tzielinski-habana May 7, 2026
1f38d3b
Updated docs
tzielinski-habana May 7, 2026
34eb0db
Added matmul registration and guarded cublas
tzielinski-habana May 14, 2026
a3c4a04
Merge branch 'main' into xpu_rl
tzielinski-habana May 18, 2026
3ee67e1
Refactoring
tzielinski-habana May 18, 2026
323c0b2
Swapped positions of common and matmul overrides
tzielinski-habana May 19, 2026
448e30b
Added matmul and integration tests
tzielinski-habana May 20, 2026
5cf2167
Only TRITON_ATTN works
tzielinski-habana May 21, 2026
fc49b26
Minor test improvements
tzielinski-habana May 21, 2026
5b5ba56
Further test improvements
tzielinski-habana May 21, 2026
bb50331
Test fix
tzielinski-habana May 21, 2026
7e5dae1
Merge branch 'main' into xpu_rl
tzielinski-habana May 21, 2026
e3c7a9a
Merge branch 'main' into xpu_rl
tzielinski-habana May 21, 2026
75fded1
Tests refactoring
tzielinski-habana May 22, 2026
0aafea4
Merge branch 'main' into xpu_rl
xuechendi May 26, 2026
4bf9342
Merge pull request #1 from tzielinski-habana/xpu_rl_test_refactoring
tzielinski-habana May 27, 2026
4082a73
Addressed review comments
tzielinski-habana May 27, 2026
2f3acd3
More tests modifications
tzielinski-habana May 27, 2026
5c1bd64
Merge branch 'main' into xpu_rl
tzielinski-habana May 28, 2026
eef602e
Added oneCCL allreduce setting for batch invariance
tzielinski-habana Jun 1, 2026
9f8cc09
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 9, 2026
3cf1de9
Reduced scope of batch invariance kernel registrations
tzielinski-habana Jun 16, 2026
d958731
Added tests
tzielinski-habana Jun 17, 2026
965f17a
xfail some tests
tzielinski-habana Jun 17, 2026
9c8f502
Merge branch 'vllm-project:main' into bi_reduced_scope
tzielinski-habana Jun 17, 2026
8bc664d
Removed unused variable
tzielinski-habana Jun 17, 2026
217bab7
Removed 1 test file and docs mention
tzielinski-habana Jun 17, 2026
75ee644
Merge branch 'vllm-project:main' into xpu_rl
tzielinski-habana Jun 17, 2026
e4ffbfd
Merge bi_reduced_scope into xpu_rl (adopting bi_reduced_scope content)
tzielinski-habana Jun 17, 2026
7684491
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 17, 2026
d344a3a
Better dispatch key handling
tzielinski-habana Jun 18, 2026
29f9711
Refactored skipping of unsupported XPU backends
tzielinski-habana Jun 18, 2026
39bb6a2
Restrict enable_batch_invariant_mode to XPU and CUDA
tzielinski-habana Jun 18, 2026
da41d11
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 24, 2026
3a3d5b6
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 24, 2026
469c601
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 24, 2026
f576920
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 24, 2026
36869b7
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 24, 2026
1fa657e
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 24, 2026
16ca2c7
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 24, 2026
c123747
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 25, 2026
a53f61b
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 25, 2026
b032b34
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 26, 2026
194750a
Merge branch 'main' into xpu_rl
tzielinski-habana Jun 26, 2026
9d9c9d9
Merge branch 'main' into xpu_rl
tzielinski-habana Jul 6, 2026
3c52f32
Refactored devices and backends handling in tests
tzielinski-habana Jul 7, 2026
e04f0f2
Removed skip_unsupported_backend
tzielinski-habana Jul 9, 2026
beccb29
Merge branch 'main' into xpu_rl
tzielinski-habana Jul 10, 2026
458a448
Merge branch 'main' into xpu_rl
tzielinski-habana Jul 14, 2026
94ce14c
Merge branch 'main' into xpu_rl
tzielinski-habana Jul 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions tests/v1/determinism/test_batch_invariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
TEST_MODEL,
_extract_step_logprobs,
_random_prompt,
skip_unsupported,
skip_if_not_cuda,
skip_unsupported_device,
skip_unsupported_xpu_backends,
)

import vllm.envs as envs
from vllm import LLM, SamplingParams
from vllm.platforms import current_platform


@skip_unsupported
@skip_unsupported_device
@pytest.mark.flaky(reruns=3)
@pytest.mark.timeout(1000)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -49,6 +52,13 @@ def test_v1_generation_is_deterministic_across_batch_sizes_with_needle(
seed.
- Keep max_tokens and max_model_len bounded for speed and memory use.
"""
skip_unsupported_xpu_backends(backend)

# Not all batch-invariant kernels are registered on XPU yet
# (e.g. attention, custom ops), so e2e determinism is not guaranteed.
if current_platform.is_xpu():
pytest.xfail("Not all batch-invariant kernels registered on XPU yet")

seed = int(os.getenv("VLLM_TEST_SEED", "12345"))
random.seed(seed)

Expand Down Expand Up @@ -143,7 +153,7 @@ def test_v1_generation_is_deterministic_across_batch_sizes_with_needle(
llm.shutdown()


@skip_unsupported
@skip_unsupported_device
@pytest.mark.parametrize(
"backend",
BACKENDS,
Expand All @@ -157,6 +167,13 @@ def test_logprobs_bitwise_batch_invariance_bs1_vs_bsN(
block_m,
block_n,
):
skip_unsupported_xpu_backends(backend)

# Not all batch-invariant kernels are registered on XPU yet
# (e.g. attention, custom ops), so e2e determinism is not guaranteed.
if current_platform.is_xpu():
pytest.xfail("Not all batch-invariant kernels registered on XPU yet")
Comment on lines +167 to +170

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e2e determinism is not guaranteed

We want it is guaranteed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but that means the PR needs to be much larger. I wanted to register a subset of the kernels first and add the other ones later.


seed = int(os.getenv("VLLM_TEST_SEED", "12345"))
random.seed(seed)
tp_size = int(os.getenv("VLLM_TEST_TP_SIZE", "1"))
Expand Down Expand Up @@ -375,7 +392,7 @@ def test_logprobs_bitwise_batch_invariance_bs1_vs_bsN(
pytest.fail(msg)


@skip_unsupported
@skip_unsupported_device
@pytest.mark.parametrize(
"backend",
BACKENDS,
Expand All @@ -385,6 +402,8 @@ def test_simple_generation(backend):
Simple test that runs the model with a basic prompt and prints the output.
Useful for quick smoke testing and debugging.
"""
skip_unsupported_xpu_backends(backend)

model = TEST_MODEL

llm = LLM(
Expand Down Expand Up @@ -425,7 +444,7 @@ def test_simple_generation(backend):
llm.shutdown()


@skip_unsupported
@skip_unsupported_device
@pytest.mark.parametrize(
"backend",
BACKENDS,
Expand All @@ -442,6 +461,8 @@ def test_logprobs_without_batch_invariance_should_fail(
The test will PASS if we detect differences (proving batch invariance matters).
The test will FAIL if everything matches (suggesting batch invariance isn't needed).
"""
skip_unsupported_xpu_backends(backend)

# CRITICAL: Disable batch invariance for this test
monkeypatch.setenv("VLLM_BATCH_INVARIANT", "0")
monkeypatch.setattr(envs, "VLLM_BATCH_INVARIANT", False)
Expand Down Expand Up @@ -641,7 +662,7 @@ def test_logprobs_without_batch_invariance_should_fail(
pytest.fail(fail_msg)


@skip_unsupported
@skip_if_not_cuda
@pytest.mark.parametrize("backend", ["FLASH_ATTN"])
def test_decode_logprobs_match_prefill_logprobs(
backend,
Expand Down
6 changes: 3 additions & 3 deletions tests/v1/determinism/test_matmul_batch_invariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

import pytest
import torch
from utils import skip_unsupported
from utils import skip_unsupported_device

from vllm.model_executor.layers.batch_invariant import matmul_batch_invariant
from vllm.platforms import current_platform

DEVICE_TYPE = current_platform.device_type


@skip_unsupported
@skip_unsupported_device
@pytest.mark.parametrize(
"a_shape,b_shape",
[
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_matmul_correctness(a_shape, b_shape, dtype):
)


@skip_unsupported
@skip_unsupported_device
@pytest.mark.parametrize("dtype", [torch.float16, torch.bfloat16])
def test_matmul_batch_invariance(dtype):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/v1/determinism/test_nvfp4_batch_invariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from utils import (
_extract_step_logprobs,
_random_prompt,
skip_unsupported,
skip_if_not_cuda,
)

from vllm import LLM, SamplingParams
Expand Down Expand Up @@ -40,7 +40,7 @@ def _make_llm(max_num_seqs: int, backend: str) -> LLM:
)


@skip_unsupported
@skip_if_not_cuda
@pytest.mark.parametrize("backend", ["FLASH_ATTN"])
def test_dense_nvfp4_generation_is_deterministic_across_batch_sizes_e2e(backend):
seed = int(os.getenv("VLLM_TEST_SEED", "12345"))
Expand Down
4 changes: 2 additions & 2 deletions tests/v1/determinism/test_online_batch_invariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import openai
import pytest
from utils import BACKENDS, TEST_MODEL, _random_prompt, skip_unsupported
from utils import BACKENDS, TEST_MODEL, _random_prompt, skip_if_not_cuda

from tests.utils import RemoteOpenAIServer

Expand Down Expand Up @@ -133,7 +133,7 @@ def _compare_bs1_vs_bsn_single_process(
)


@skip_unsupported
@skip_if_not_cuda
@pytest.mark.parametrize("backend", BACKENDS)
def test_logprobs_bitwise_batch_invariance_bs1_vs_bsN(
backend: str,
Expand Down
45 changes: 37 additions & 8 deletions tests/v1/determinism/test_rms_norm_batch_invariant.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import pytest
import torch
from utils import skip_unsupported
from utils import skip_if_not_cuda, skip_unsupported_device

from vllm.model_executor.layers.batch_invariant import (
rms_norm_batch_invariant,
Expand All @@ -20,7 +20,7 @@
DEVICE_TYPE = current_platform.device_type


@skip_unsupported
@skip_if_not_cuda
@pytest.mark.parametrize("batch_size", [1, 4, 16, 64])
@pytest.mark.parametrize("hidden_size", [512, 2048, 4096, 8192])
@pytest.mark.parametrize("dtype", [torch.float16, torch.bfloat16])
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_rms_norm_batch_invariant_vs_standard(
)


@skip_unsupported
@skip_if_not_cuda
@pytest.mark.parametrize("hidden_size", [512, 4096])
@pytest.mark.parametrize("dtype", [torch.float16, torch.bfloat16])
@pytest.mark.parametrize("eps", [1e-6])
Expand Down Expand Up @@ -166,7 +166,7 @@ def fused_add_rms_norm(x, residual, w, e) -> tuple[torch.Tensor, torch.Tensor]:
)


@skip_unsupported
@skip_if_not_cuda
@pytest.mark.parametrize("batch_size", [1, 16, 128])
@pytest.mark.parametrize("seq_len", [1, 32, 512])
@pytest.mark.parametrize("hidden_size", [2048, 4096])
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_rms_norm_3d_input(
)


@skip_unsupported
@skip_if_not_cuda
def test_rms_norm_numerical_stability(default_vllm_config):
"""
Test RMS norm numerical stability with extreme values.
Expand Down Expand Up @@ -270,7 +270,7 @@ def test_rms_norm_numerical_stability(default_vllm_config):
)


@skip_unsupported
@skip_unsupported_device
def test_rms_norm_formula(default_vllm_config):
"""
Test that RMS norm follows the correct mathematical formula.
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_rms_norm_formula(default_vllm_config):
)


@skip_unsupported
@skip_if_not_cuda
@pytest.mark.parametrize("hidden_size", [128, 1024, 4096, 16384])
def test_rms_norm_different_hidden_sizes(default_vllm_config, hidden_size: int):
"""
Expand Down Expand Up @@ -341,7 +341,7 @@ def test_rms_norm_different_hidden_sizes(default_vllm_config, hidden_size: int):
)


@skip_unsupported
@skip_unsupported_device
def test_rms_norm_determinism(default_vllm_config):
"""
Test that batch-invariant RMS norm produces deterministic results.
Expand Down Expand Up @@ -377,6 +377,35 @@ def test_rms_norm_determinism(default_vllm_config):
)


@skip_unsupported_device
@pytest.mark.parametrize("dtype", [torch.float16, torch.bfloat16])
def test_rms_norm_batch_invariance(dtype):
"""Same row gives identical rms_norm result regardless of batch neighbors.

This verifies that the output for a given row is independent of what other
rows are present in the batch — the core batch-invariance property.
"""
device = torch.device(DEVICE_TYPE)
torch.manual_seed(42)
hidden_size = 2048
eps = 1e-6

weight = torch.randn(hidden_size, dtype=dtype, device=device)
row = torch.randn(1, hidden_size, dtype=dtype, device=device)

# Compute rms_norm on the single row alone
out_single = rms_norm_batch_invariant(row, weight, eps=eps)

# Embed the same row in a larger batch with random neighbors
batch = torch.randn(8, hidden_size, dtype=dtype, device=device)
batch[4] = row[0]
out_batch = rms_norm_batch_invariant(batch, weight, eps=eps)

assert torch.equal(out_single[0], out_batch[4]), (
"rms_norm output for a row differs when batch context changes"
)


if __name__ == "__main__":
# Run a quick smoke test
print("Running quick smoke test of RMS norm implementations...")
Expand Down
20 changes: 19 additions & 1 deletion tests/v1/determinism/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@
from vllm.transformers_utils.model_arch_config_convertor import (
ModelArchConfigConvertorBase,
)
from vllm.triton_utils import HAS_TRITON
from vllm.v1.attention.backends.fa_utils import flash_attn_supports_mla

skip_unsupported = pytest.mark.skipif(
skip_if_not_cuda = pytest.mark.skipif(
not (current_platform.is_cuda() and current_platform.has_device_capability(80)),
# Supports testing on Ampere and Ada Lovelace devices.
# Note: For devices with SM < 90, batch invariance does not support CUDA Graphs.
reason="Requires CUDA and >= Ampere (SM80)",
)

skip_unsupported_device = pytest.mark.skipif(
not (
(current_platform.is_cuda() and current_platform.has_device_capability(80))
or (current_platform.is_xpu() and HAS_TRITON)
),
reason="Requires CUDA >= Ampere (SM80) or Intel XPU with Triton",
)

DEFAULT_MODEL = "Qwen/Qwen3-1.7B"
TEST_MODEL = os.getenv("VLLM_TEST_MODEL", DEFAULT_MODEL)

Expand All @@ -42,6 +51,15 @@
if flash_attn_supports_mla():
BACKENDS.append("FLASH_ATTN_MLA")

XPU_BACKENDS: list[str] = [
"TRITON_ATTN",
]


def skip_unsupported_xpu_backends(backend: str):
if current_platform.is_xpu() and backend not in XPU_BACKENDS:
pytest.skip(f"Backend {backend} not verified for batch invariance on XPU")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently all devices and backends are quite complicated, please organize them all together, design with a cleaner version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do



def _random_prompt(min_words: int = 1024, max_words: int = 1024 * 2) -> str:
# Generate more realistic prompts that will actually produce varied tokens
Expand Down
Loading
Loading