Skip to content

Commit ff7a057

Browse files
mayuyuacejikunshang
authored andcommitted
[XPU][UT] Fix OOM and skip graph case (vllm-project#49287)
Signed-off-by: mayuyuace <qiming1.zhang@intel.com> Signed-off-by: Qiming Zhang <qiming1.zhang@intel.com> Co-authored-by: Kunshang Ji <kunshang.ji@intel.com>
1 parent b5b5e69 commit ff7a057

6 files changed

Lines changed: 47 additions & 22 deletions

File tree

tests/conftest.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -914,13 +914,13 @@ def __enter__(self):
914914
return self
915915

916916
def __exit__(self, exc_type, exc_value, traceback):
917-
from tests.utils import wait_for_rocm_memory_to_settle
917+
from tests.utils import wait_for_memory_to_settle
918918

919919
del self.model
920920
cleanup_dist_env_and_memory()
921921
# ROCm frees VRAM lazily; wait so a runner started right after this HF
922922
# model exits does not OOM on its startup memory guard.
923-
wait_for_rocm_memory_to_settle(
923+
wait_for_memory_to_settle(
924924
threshold_ratio=getattr(self, "threshold_ratios", None)
925925
)
926926
if hasattr(self, "threshold_ratios"):
@@ -998,9 +998,24 @@ def __init__(
998998
# V1 startup requires free_memory >= total * gpu_memory_utilization.
999999
# ROCm CI can hand a test a device that is still lazily releasing
10001000
# VRAM from a previous process, so wait before constructing LLM.
1001-
from tests.utils import wait_for_rocm_memory_to_settle
1002-
1003-
wait_for_rocm_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
1001+
from tests.utils import wait_for_memory_to_settle
1002+
1003+
wait_for_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
1004+
elif current_platform.is_xpu():
1005+
# The XPU/oneAPI runtime keeps ~1 GiB of context resident in the
1006+
# parent pytest process for its whole lifetime (grown by in-process
1007+
# HfRunner models), and distributed tests additionally allocate a
1008+
# CCL context in the engine subprocess. The default utilization of
1009+
# 0.92 leaves too little headroom for both, so lower it on XPU when
1010+
# the caller did not request an explicit value.
1011+
if "gpu_memory_utilization" not in kwargs:
1012+
kwargs["gpu_memory_utilization"] = 0.9
1013+
gpu_memory_utilization = kwargs["gpu_memory_utilization"]
1014+
# XPU (Level Zero) can also release device memory lazily after a
1015+
# previous engine shuts down, so wait before constructing LLM.
1016+
from tests.utils import wait_for_memory_to_settle
1017+
1018+
wait_for_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
10041019

10051020
with init_ctx:
10061021
self.llm = LLM(
@@ -1326,14 +1341,14 @@ def collective_rpc(self, *args, **kwargs):
13261341
def __enter__(self):
13271342
return self
13281343

1329-
def _wait_for_rocm_memory_release(self, gpu_memory_utilization: float) -> None:
1330-
from tests.utils import wait_for_rocm_memory_to_settle
1344+
def _wait_for_memory_release(self, gpu_memory_utilization: float) -> None:
1345+
from tests.utils import wait_for_memory_to_settle
13311346

13321347
# V1 startup requires free_memory >= total * gpu_memory_utilization.
13331348
# Wait for the complementary used-memory ratio so the next runner does
13341349
# not fail the startup guard immediately after this runner exits. The
13351350
# wait is bounded so cleanup failures fail this test instead of hanging.
1336-
wait_for_rocm_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
1351+
wait_for_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
13371352

13381353
def __exit__(self, exc_type, exc_value, traceback):
13391354
# Explicitly shutdown the engine core to release GPU resources
@@ -1359,7 +1374,7 @@ def __exit__(self, exc_type, exc_value, traceback):
13591374
del self.llm
13601375
torch._dynamo.reset()
13611376
cleanup_dist_env_and_memory()
1362-
self._wait_for_rocm_memory_release(gpu_memory_utilization)
1377+
self._wait_for_memory_release(gpu_memory_utilization)
13631378

13641379

13651380
@pytest.fixture(scope="session")
@@ -1746,7 +1761,7 @@ def clean_gpu_memory_between_tests():
17461761

17471762
import gc
17481763

1749-
from tests.utils import wait_for_gpu_memory_to_clear, wait_for_rocm_memory_to_settle
1764+
from tests.utils import wait_for_gpu_memory_to_clear, wait_for_memory_to_settle
17501765

17511766
num_gpus = torch.accelerator.device_count()
17521767

@@ -1755,7 +1770,7 @@ def _wait_for_settled_gpu_memory() -> None:
17551770
return
17561771
try:
17571772
if current_platform.is_rocm():
1758-
wait_for_rocm_memory_to_settle()
1773+
wait_for_memory_to_settle()
17591774
else:
17601775
wait_for_gpu_memory_to_clear(
17611776
devices=list(range(num_gpus)),

tests/models/language/generation/test_hybrid.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from tests.models.registry import HF_EXAMPLE_MODELS
1010
from tests.utils import multi_gpu_test
1111
from vllm import LLM
12+
from vllm.config import CUDAGraphMode
1213
from vllm.engine.arg_utils import EngineArgs
1314
from vllm.platforms import current_platform
1415
from vllm.sampling_params import SamplingParams
@@ -210,6 +211,8 @@ def test_mamba_cache_cg_padding(
210211
cudagraph_dispatcher.initialize_cudagraph_keys(
211212
vllm_config.compilation_config.cudagraph_mode
212213
)
214+
if cudagraph_dispatcher.cudagraph_mode == CUDAGraphMode.NONE:
215+
pytest.skip("CUDA/XPU graph is disabled.Please enable it to run this test. ")
213216
while (
214217
len(example_prompts)
215218
== cudagraph_dispatcher.dispatch(len(example_prompts))[1].num_tokens

tests/models/language/pooling/test_colbert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytest
1212
import torch
1313

14-
from tests.utils import wait_for_rocm_memory_to_settle
14+
from tests.utils import wait_for_memory_to_settle
1515
from vllm.distributed import cleanup_dist_env_and_memory
1616
from vllm.entrypoints.pooling.scoring.utils import compute_maxsim_score
1717

@@ -165,7 +165,7 @@ def _hf_colbert_model(model_name: str, hf_spec: dict, device: torch.device):
165165
finally:
166166
del hf_model, linear_weight
167167
cleanup_dist_env_and_memory()
168-
wait_for_rocm_memory_to_settle()
168+
wait_for_memory_to_settle()
169169

170170

171171
def _assert_embeddings_close(vllm_outputs, hf_embeddings):

tests/models/multimodal/generation/test_voxtral_realtime.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ async def async_engine():
104104
from vllm.platforms import current_platform
105105

106106
if current_platform.is_rocm():
107-
from tests.utils import wait_for_rocm_memory_to_settle
107+
from tests.utils import wait_for_memory_to_settle
108108

109-
wait_for_rocm_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
109+
wait_for_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
110110

111111
engine_args = AsyncEngineArgs(**ENGINE_CONFIG)
112112
llm = AsyncLLM.from_engine_args(engine_args)
@@ -122,9 +122,9 @@ async def async_engine():
122122
from vllm.distributed import cleanup_dist_env_and_memory
123123

124124
cleanup_dist_env_and_memory()
125-
from tests.utils import wait_for_rocm_memory_to_settle
125+
from tests.utils import wait_for_memory_to_settle
126126

127-
wait_for_rocm_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
127+
wait_for_memory_to_settle(threshold_ratio=1.0 - gpu_memory_utilization)
128128

129129

130130
def test_voxtral_realtime_forward(audio_assets, tokenizer, vllm_runner, monkeypatch):

tests/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,13 @@ def record_gpu_memory_usage_stats(
15401540
mem_info = amdsmi_get_gpu_vram_usage(dev_handle)
15411541
gb_used = mem_info["vram_used"] / 2**10
15421542
gb_total = mem_info["vram_total"] / 2**10
1543+
elif current_platform.is_xpu():
1544+
# nvml/amdsmi are unavailable on XPU. Query device memory through
1545+
# torch.accelerator.get_memory_info, which the XPU platform patches
1546+
# to return (free, total) bytes via Level Zero.
1547+
free_b, total_b = torch.accelerator.get_memory_info(device)
1548+
gb_used = (total_b - free_b) / 2**30
1549+
gb_total = total_b / 2**30
15431550
else:
15441551
dev_handle = get_nvml_device_handle(device)
15451552
mem_info = nvmlDeviceGetMemoryInfo(dev_handle)
@@ -1680,19 +1687,19 @@ def wait_for_gpu_memory_to_clear(
16801687
time.sleep(poll_interval_s)
16811688

16821689

1683-
def wait_for_rocm_memory_to_settle(
1690+
def wait_for_memory_to_settle(
16841691
*,
16851692
threshold_ratio: float | dict[int, float] | None = 0.1,
16861693
timeout_s: float = 240,
16871694
) -> None:
1688-
"""Block until ROCm device VRAM usage drops below ``threshold_ratio``.
1695+
"""Block until ROCm or XPU device VRAM usage drops below ``threshold_ratio``.
16891696
1690-
ROCm reclaims GPU memory more lazily than CUDA, so back-to-back model
1697+
ROCm and XPU reclaims GPU memory more lazily than CUDA, so back-to-back model
16911698
loads in a single test process can OOM the *next* engine/model startup
16921699
even after ``cleanup_dist_env_and_memory``. This gives the driver time to
16931700
actually release VRAM before the next allocation. No-op off ROCm.
16941701
"""
1695-
if not current_platform.is_rocm():
1702+
if not current_platform.is_rocm() and not current_platform.is_xpu():
16961703
return
16971704

16981705
num_gpus = current_platform.device_count()

tests/v1/kv_connector/nixl_integration/run_accuracy_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ wait_for_server() {
112112
# Function to clean up previous instances
113113
wait_for_gpu_memory_release() {
114114
if [[ "$SMI_BIN" == *"rocm"* ]]; then
115-
PYTHONPATH="${GIT_ROOT}" python3 -c "from tests.utils import wait_for_rocm_memory_to_settle; wait_for_rocm_memory_to_settle()"
115+
PYTHONPATH="${GIT_ROOT}" python3 -c "from tests.utils import wait_for_memory_to_settle; wait_for_memory_to_settle()"
116116
fi
117117
}
118118

0 commit comments

Comments
 (0)