Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
25 changes: 25 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,21 @@ def __init__(
from tests.utils import wait_for_rocm_memory_to_settle

wait_for_rocm_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
elif current_platform.is_xpu():
# The XPU/oneAPI runtime keeps ~1 GiB of context resident in the
# parent pytest process for its whole lifetime (grown by in-process
# HfRunner models), and distributed tests additionally allocate a
# CCL context in the engine subprocess. The default utilization of
# 0.92 leaves too little headroom for both, so lower it on XPU when
# the caller did not request an explicit value.
if "gpu_memory_utilization" not in kwargs:
kwargs["gpu_memory_utilization"] = 0.9
gpu_memory_utilization = kwargs["gpu_memory_utilization"]
# XPU (Level Zero) can also release device memory lazily after a
# previous engine shuts down, so wait before constructing LLM.
from tests.utils import wait_for_xpu_memory_to_settle

wait_for_xpu_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we merge wait_for_xpu_memory_to_settle and wait_for_rocm_memory_to_settle to single function wait_for_memory_to_settle ?

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.

Merged.


with init_ctx:
self.llm = LLM(
Expand Down Expand Up @@ -1301,6 +1316,15 @@ def _wait_for_rocm_memory_release(self, gpu_memory_utilization: float) -> None:
# wait is bounded so cleanup failures fail this test instead of hanging.
wait_for_rocm_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)

def _wait_for_xpu_memory_release(self, gpu_memory_utilization: float) -> None:
from tests.utils import wait_for_xpu_memory_to_settle

# V1 startup requires free_memory >= total * gpu_memory_utilization.
# XPU (Level Zero) releases device memory lazily after an engine shuts
# down, so wait for the complementary used-memory ratio to settle before
# the next allocation. Bounded so cleanup failures do not hang the suite.
wait_for_xpu_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)

def __exit__(self, exc_type, exc_value, traceback):
# Explicitly shutdown the engine core to release GPU resources
# This is needed because when executing consecutive tests, the GC
Expand All @@ -1326,6 +1350,7 @@ def __exit__(self, exc_type, exc_value, traceback):
torch._dynamo.reset()
cleanup_dist_env_and_memory()
self._wait_for_rocm_memory_release(gpu_memory_utilization)
self._wait_for_xpu_memory_release(gpu_memory_utilization)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can merge _wait_for_rocm_memory_release and _wait_for_xpu_memory_release to single function _wait_for_memory_release

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.

Merged.



@pytest.fixture(scope="session")
Expand Down
4 changes: 4 additions & 0 deletions tests/models/language/generation/test_hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ def test_chunked_prefill_with_parallel_sampling(
@pytest.mark.parametrize("model", [SSM_MODELS[0], HYBRID_MODELS[0]])
@pytest.mark.parametrize("max_tokens", [20])
@pytest.mark.parametrize("conv_state_layout", ["SD", "DS"])
@pytest.mark.skipif(
not current_platform.is_cuda_alike(),
reason="flash attn is not yet available for use with the SYCL Graph extension",
)
def test_mamba_cache_cg_padding(
vllm_runner,
example_prompts,
Expand Down
38 changes: 38 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,13 @@ def record_gpu_memory_usage_stats(
mem_info = amdsmi_get_gpu_vram_usage(dev_handle)
gb_used = mem_info["vram_used"] / 2**10
gb_total = mem_info["vram_total"] / 2**10
elif current_platform.is_xpu():
# nvml/amdsmi are unavailable on XPU. Query device memory through
# torch.accelerator.get_memory_info, which the XPU platform patches
# to return (free, total) bytes via Level Zero.
free_b, total_b = torch.accelerator.get_memory_info(device)
gb_used = (total_b - free_b) / 2**30
gb_total = total_b / 2**30
else:
dev_handle = get_nvml_device_handle(device)
mem_info = nvmlDeviceGetMemoryInfo(dev_handle)
Expand Down Expand Up @@ -1716,6 +1723,37 @@ def wait_for_rocm_memory_to_settle(
)


def wait_for_xpu_memory_to_settle(
*,
threshold_ratio: float | dict[int, float] | None = 0.1,
timeout_s: float = 240,
) -> None:
"""Block until XPU device memory usage drops below ``threshold_ratio``.

Like ROCm, XPU (Level Zero) can release device memory lazily after an
engine shuts down, so back-to-back model loads in a single test process
can OOM the *next* engine/model startup even after
``cleanup_dist_env_and_memory``. This gives the driver time to actually
release device memory before the next allocation. No-op off XPU.
"""
if not current_platform.is_xpu():
return

num_gpus = current_platform.device_count()
if num_gpus == 0:
return
if threshold_ratio is None:
threshold_ratio = 0.1

wait_for_gpu_memory_to_clear(
devices=list(range(num_gpus)),
threshold_ratio=threshold_ratio,
timeout_s=timeout_s,
stable_duration_s=2.0,
poll_interval_s=1.0,
)


_P = ParamSpec("_P")


Expand Down
Loading