Fix eager AMX backend probe imports (#34496)
Co-authored-by: Xiaoyu Zhang <1182563586@qq.com>
This commit is contained in:
co-authored by
Xiaoyu Zhang
parent
ba1d980b35
commit
827552bc1d
@@ -181,6 +181,44 @@ def test_platform_detect_does_not_raise():
|
||||
assert PlatformInfo.detect().device_type in ("cpu", "cuda", "hip", "npu")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"relative_path",
|
||||
(
|
||||
"srt/utils/common.py",
|
||||
"multimodal_gen/runtime/utils/common.py",
|
||||
),
|
||||
)
|
||||
def test_amx_backend_probe_is_lazy(relative_path):
|
||||
loader = (
|
||||
"package = importlib.util.find_spec('sglang'); "
|
||||
"path = pathlib.Path(next(iter(package.submodule_search_locations))) / "
|
||||
f"{relative_path!r}; "
|
||||
"spec = importlib.util.spec_from_file_location('_common_under_test', path); "
|
||||
"module = importlib.util.module_from_spec(spec); "
|
||||
"sys.modules[spec.name] = module; "
|
||||
"spec.loader.exec_module(module)"
|
||||
)
|
||||
code = "; ".join(
|
||||
(
|
||||
"import builtins, importlib.util, pathlib, sys",
|
||||
"from unittest import mock",
|
||||
"real_import = builtins.__import__",
|
||||
"import_mock = mock.Mock(wraps=real_import)",
|
||||
"builtins.__import__ = import_mock",
|
||||
loader,
|
||||
"builtins.__import__ = real_import",
|
||||
"attempted = any(call.args and call.args[0] == 'sgl_kernel' "
|
||||
"for call in import_mock.call_args_list)",
|
||||
"print('DIRTY' if attempted else 'CLEAN')",
|
||||
)
|
||||
)
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", code], capture_output=True, text=True
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert "CLEAN" in result.stdout
|
||||
|
||||
|
||||
def test_import_stays_metadata_only():
|
||||
# Importing the namespace must not pull in the AOT backend (sgl_kernel) or
|
||||
# the JIT compilation infra (sglang.kernels.jit), which import torch / nvcc.
|
||||
|
||||
Reference in New Issue
Block a user