@@ -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 )),
0 commit comments