2025-02-02 14:58:18 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2025-06-03 11:20:17 -07:00
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
2025-02-02 14:58:18 -05:00
|
|
|
|
2024-11-20 18:36:33 -08:00
|
|
|
# Description: Test the lazy import module
|
|
|
|
|
# The utility function cannot be placed in `vllm.utils`
|
|
|
|
|
# this needs to be a standalone script
|
|
|
|
|
import sys
|
|
|
|
|
|
2025-02-03 13:40:25 +08:00
|
|
|
# List of modules that should not be imported too early.
|
|
|
|
|
# Lazy import `torch._inductor.async_compile` to avoid creating
|
|
|
|
|
# too many processes before we set the number of compiler threads.
|
|
|
|
|
# Lazy import `cv2` to avoid bothering users who only use text models.
|
|
|
|
|
# `cv2` can easily mess up the environment.
|
|
|
|
|
module_names = ["torch._inductor.async_compile", "cv2"]
|
|
|
|
|
|
2025-12-15 19:12:05 -08:00
|
|
|
# set all modules in `module_names` to be None.
|
|
|
|
|
# if we import any modules during `import vllm`, there would be a
|
|
|
|
|
# hard error and nice stacktrace on the first import.
|
|
|
|
|
for module_name in module_names:
|
|
|
|
|
sys.modules[module_name] = None # type: ignore[assignment]
|
2025-02-03 13:40:25 +08:00
|
|
|
|
2025-12-15 19:12:05 -08:00
|
|
|
import vllm # noqa
|