From 82731931ae1a770ef0439a2afa88a54cb850cdfa Mon Sep 17 00:00:00 2001 From: Ganesh R Date: Wed, 16 Sep 2026 14:45:12 +0530 Subject: [PATCH] [Bugfix][CPU] Fall back to CpuPlatform when zentorch fails to import (#54923) Signed-off-by: R Co-authored-by: Cursor --- tests/test_zen_cpu_platform_detection.py | 52 +++++++++++++++++++++++- vllm/platforms/__init__.py | 9 ++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/tests/test_zen_cpu_platform_detection.py b/tests/test_zen_cpu_platform_detection.py index 9f386f70cd..0c99c6568a 100644 --- a/tests/test_zen_cpu_platform_detection.py +++ b/tests/test_zen_cpu_platform_detection.py @@ -65,7 +65,7 @@ def test_cpu_target_selects_cpu_platform_from_non_cpu_wheel( rocm_plugin.assert_not_called() -def test_platform_detection_logs_zentorch_import_failure(caplog): +def test_broken_zentorch_falls_back_to_cpu_platform(caplog): original_import = builtins.__import__ def import_with_broken_zentorch(name, *args, **kwargs): @@ -88,6 +88,54 @@ def test_platform_detection_logs_zentorch_import_failure(caplog): ): platform = resolve_current_platform_cls_qualname() + assert platform == "vllm.platforms.cpu.CpuPlatform" + assert "zentorch failed to import" in caplog.text + assert "OSError: incompatible shared library" in caplog.text + + +def test_zentorch_failure_other_than_oserror_is_not_recovered(caplog): + original_import = builtins.__import__ + + def import_with_broken_zentorch(name, *args, **kwargs): + if name == "zentorch": + raise RuntimeError("unknown zentorch failure") + return original_import(name, *args, **kwargs) + + with ( + patch("vllm.platforms.envs.VLLM_TARGET_DEVICE", "cuda"), + patch.dict( + "vllm.platforms.builtin_platform_plugins", + {"cpu": cpu_platform_plugin}, + clear=True, + ), + patch("vllm.platforms.load_plugins_by_group", return_value={}), + patch("vllm.platforms.vllm_version_matches_substr", return_value=True), + patch("vllm.platforms._is_amd_zen_cpu", return_value=True), + patch.object(builtins, "__import__", side_effect=import_with_broken_zentorch), + caplog.at_level(logging.DEBUG, logger="vllm.platforms"), + ): + platform = resolve_current_platform_cls_qualname() + + assert platform == "vllm.platforms.interface.UnspecifiedPlatform" + assert "RuntimeError: unknown zentorch failure" in caplog.text + + +def test_platform_plugin_failure_is_logged(caplog): + def failing_plugin(): + raise RuntimeError("plugin exploded") + + with ( + patch("vllm.platforms.envs.VLLM_TARGET_DEVICE", "cuda"), + patch.dict( + "vllm.platforms.builtin_platform_plugins", + {"cpu": failing_plugin}, + clear=True, + ), + patch("vllm.platforms.load_plugins_by_group", return_value={}), + caplog.at_level(logging.DEBUG, logger="vllm.platforms"), + ): + platform = resolve_current_platform_cls_qualname() + assert platform == "vllm.platforms.interface.UnspecifiedPlatform" assert "Platform plugin cpu failed during detection" in caplog.text - assert "OSError: incompatible shared library" in caplog.text + assert "RuntimeError: plugin exploded" in caplog.text diff --git a/vllm/platforms/__init__.py b/vllm/platforms/__init__.py index b34b0b9a7d..7cf0843669 100644 --- a/vllm/platforms/__init__.py +++ b/vllm/platforms/__init__.py @@ -217,6 +217,15 @@ def cpu_platform_plugin() -> str | None: "AMD Zen CPU detected but zentorch not installed, " "falling back to CpuPlatform." ) + except OSError: + # An ABI-mismatched build fails here with an undefined-symbol + # error; other failures are not known to be safe to recover from. + logger.warning( + "AMD Zen CPU detected but zentorch failed to import, falling " + "back to CpuPlatform. This usually means the zentorch build " + "does not match the installed torch version.", + exc_info=True, + ) return "vllm.platforms.cpu.CpuPlatform"