A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[XPU]fix cuda event used in XPU model runner (#23708)
Signed-off-by: Kunshang Ji <kunshang.ji@intel.com>
Kunshang Ji committed
Aug 27, 2025 at 15:27 UTC
64466778397482e0cb9ff9f6b320ca6d9dc567ae
1 file changed
+21
-1
vllm/v1/worker/xpu_model_runner.py
+21
-1
@@ -1,5 +1,6 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+from contextlib import contextmanager
4
from typing import TYPE_CHECKING
5
6
import torch
@@ -22,7 +23,8 @@ class XPUModelRunner(GPUModelRunner):
23
vllm_config: VllmConfig,
24
device: torch.device,
25
):
25
- super().__init__(vllm_config, device)
26
+ with _torch_cuda_wrapper():
27
+ super().__init__(vllm_config, device)
28
# FIXME: To be verified.
29
self.cascade_attn_enabled = False
30
@@ -31,3 +33,21 @@ class XPUModelRunner(GPUModelRunner):
33
34
def _sync_device(self) -> None:
35
torch.xpu.synchronize()
36
+
37
+
38
+@contextmanager
39
+def _torch_cuda_wrapper():
40
+
41
+ class _EventPlaceholder:
42
+
43
+ def __init__(self, *args, **kwargs) -> None:
44
+ self.record = lambda: None
45
+ self.synchronize = lambda: None
46
+
47
+ try:
48
+ # replace cuda Event with xpu Event, this should work by default
49
+ torch.cuda.Event = torch.xpu.Event
50
+ yield
51
+ finally:
52
+ # if anything goes wrong, just patch it with a placeholder
53
+ torch.cuda.Event = _EventPlaceholder