[Bugfix][Platform] Don't resolve current_platform during import vllm (#60766)

Signed-off-by: Haotian An <haotiaa@amazon.com>
This commit is contained in:
haotiaa
2026-10-12 17:05:34 +00:00
committed by GitHub
parent fa39582756
commit 6e6e86078a
3 changed files with 34 additions and 4 deletions
@@ -1,6 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import subprocess
import sys
import pytest
import torch
@@ -31,6 +34,20 @@ def test_platform_plugins():
)
def test_import_vllm_does_not_resolve_platform():
# Platform plugins must be loaded after `import vllm` completes; resolving
# current_platform during it runs plugins against a half-imported vLLM.
# Needs a fresh interpreter, since vllm is already imported here.
code = (
"import sys, vllm\n"
"p = sys.modules.get('vllm.platforms')\n"
"assert p is None or p._current_platform is None, p._init_trace\n"
"from vllm.platforms import current_platform\n"
"assert current_platform.device_name == 'DummyDevice'\n"
)
subprocess.run([sys.executable, "-c", code], check=True)
def test_oot_custom_op(default_vllm_config, monkeypatch: pytest.MonkeyPatch):
# simulate workload by running an example
load_general_plugins()