[CPU] Fix torch.compile crash from torch.accelerator.synchronize on CPU-only hosts (#49960)
Signed-off-by: R <Ganesh.R@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com>
Ganesh R committed
Aug 3, 2026 at 17:18 UTC
ec40f6a8a62d588dbd216d0509374666caea2f4a
2 files changed
+13
-2
vllm/v1/worker/cpu/shm.py
+7
-1
@@ -17,6 +17,12 @@ def noop(*args: Any, **kwargs: Any) -> None:
17
pass
18
19
20
+# Distinct no-op so empty_cache does not alias synchronize: Dynamo's
21
+# handle_synchronize is keyed on that object and asserts on CPU-only hosts.
22
+def empty_cache_noop(*args: Any, **kwargs: Any) -> None:
23
+ pass
24
+
25
+
26
def fake_pin_memory(self: torch.Tensor, *args: Any, **kwargs: Any) -> torch.Tensor:
27
return self
28
@@ -58,7 +64,7 @@ torch.cuda.Stream = _StreamPlaceholder
64
torch.cuda.set_stream = noop
65
torch.cuda.current_stream = lambda *args, **kwargs: _StreamPlaceholder()
66
torch.accelerator.synchronize = noop
61
-torch.accelerator.empty_cache = noop
67
+torch.accelerator.empty_cache = empty_cache_noop
68
torch.Tensor.pin_memory = fake_pin_memory
69
torch.Tensor.record_stream = noop
70
torch.accelerator.get_memory_info = get_memory_info
vllm/v1/worker/cpu_model_runner.py
+6
-1
@@ -240,5 +240,10 @@ def _set_torch_accelerator_to_noop() -> None:
240
def noop(*args: Any, **kwargs: Any) -> None:
241
pass
242
243
+ # Distinct no-op so empty_cache does not alias synchronize: Dynamo's
244
+ # handle_synchronize is keyed on that object and asserts on CPU-only hosts.
245
+ def empty_cache_noop(*args: Any, **kwargs: Any) -> None:
246
+ pass
247
+
248
torch.accelerator.synchronize = noop
244
- torch.accelerator.empty_cache = noop
249
+ torch.accelerator.empty_cache = empty_cache_noop