[Bugfix][CPU] Fall back to CpuPlatform when zentorch fails to import (#54923)
Signed-off-by: R <Ganesh.R@amd.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Ganesh R committed
Sep 16, 2026 at 14:45 UTC
82731931ae1a770ef0439a2afa88a54cb850cdfa
2 files changed
+59
-2
tests/test_zen_cpu_platform_detection.py
+50
-2
@@ -65,7 +65,7 @@ def test_cpu_target_selects_cpu_platform_from_non_cpu_wheel(
65
rocm_plugin.assert_not_called()
66
67
68
-def test_platform_detection_logs_zentorch_import_failure(caplog):
68
+def test_broken_zentorch_falls_back_to_cpu_platform(caplog):
69
original_import = builtins.__import__
70
71
def import_with_broken_zentorch(name, *args, **kwargs):
@@ -88,6 +88,54 @@ def test_platform_detection_logs_zentorch_import_failure(caplog):
88
):
89
platform = resolve_current_platform_cls_qualname()
90
91
+ assert platform == "vllm.platforms.cpu.CpuPlatform"
92
+ assert "zentorch failed to import" in caplog.text
93
+ assert "OSError: incompatible shared library" in caplog.text
94
+
95
+
96
+def test_zentorch_failure_other_than_oserror_is_not_recovered(caplog):
97
+ original_import = builtins.__import__
98
+
99
+ def import_with_broken_zentorch(name, *args, **kwargs):
100
+ if name == "zentorch":
101
+ raise RuntimeError("unknown zentorch failure")
102
+ return original_import(name, *args, **kwargs)
103
+
104
+ with (
105
+ patch("vllm.platforms.envs.VLLM_TARGET_DEVICE", "cuda"),
106
+ patch.dict(
107
+ "vllm.platforms.builtin_platform_plugins",
108
+ {"cpu": cpu_platform_plugin},
109
+ clear=True,
110
+ ),
111
+ patch("vllm.platforms.load_plugins_by_group", return_value={}),
112
+ patch("vllm.platforms.vllm_version_matches_substr", return_value=True),
113
+ patch("vllm.platforms._is_amd_zen_cpu", return_value=True),
114
+ patch.object(builtins, "__import__", side_effect=import_with_broken_zentorch),
115
+ caplog.at_level(logging.DEBUG, logger="vllm.platforms"),
116
+ ):
117
+ platform = resolve_current_platform_cls_qualname()
118
+
119
+ assert platform == "vllm.platforms.interface.UnspecifiedPlatform"
120
+ assert "RuntimeError: unknown zentorch failure" in caplog.text
121
+
122
+
123
+def test_platform_plugin_failure_is_logged(caplog):
124
+ def failing_plugin():
125
+ raise RuntimeError("plugin exploded")
126
+
127
+ with (
128
+ patch("vllm.platforms.envs.VLLM_TARGET_DEVICE", "cuda"),
129
+ patch.dict(
130
+ "vllm.platforms.builtin_platform_plugins",
131
+ {"cpu": failing_plugin},
132
+ clear=True,
133
+ ),
134
+ patch("vllm.platforms.load_plugins_by_group", return_value={}),
135
+ caplog.at_level(logging.DEBUG, logger="vllm.platforms"),
136
+ ):
137
+ platform = resolve_current_platform_cls_qualname()
138
+
139
assert platform == "vllm.platforms.interface.UnspecifiedPlatform"
140
assert "Platform plugin cpu failed during detection" in caplog.text
93
- assert "OSError: incompatible shared library" in caplog.text
141
+ assert "RuntimeError: plugin exploded" in caplog.text
vllm/platforms/__init__.py
+9
@@ -217,6 +217,15 @@ def cpu_platform_plugin() -> str | None:
217
"AMD Zen CPU detected but zentorch not installed, "
218
"falling back to CpuPlatform."
219
)
220
+ except OSError:
221
+ # An ABI-mismatched build fails here with an undefined-symbol
222
+ # error; other failures are not known to be safe to recover from.
223
+ logger.warning(
224
+ "AMD Zen CPU detected but zentorch failed to import, falling "
225
+ "back to CpuPlatform. This usually means the zentorch build "
226
+ "does not match the installed torch version.",
227
+ exc_info=True,
228
+ )
229
230
return "vllm.platforms.cpu.CpuPlatform"
231