Skip to content

Commit d05dc7b

Browse files
njhillprashantgupta24
authored andcommitted
[BugFix] Avoid unnecessary Ray import warnings (vllm-project#6079)
1 parent fdc3c00 commit d05dc7b

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

vllm/config.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -682,11 +682,13 @@ def __init__(
682682

683683
from vllm.executor import ray_utils
684684
backend = "mp"
685-
ray_found = ray_utils.ray is not None
685+
ray_found = ray_utils.ray_is_available()
686686
if cuda_device_count_stateless() < self.world_size:
687687
if not ray_found:
688688
raise ValueError("Unable to load Ray which is "
689-
"required for multi-node inference")
689+
"required for multi-node inference, "
690+
"please install Ray with `pip install "
691+
"ray`.") from ray_utils.ray_import_err
690692
backend = "ray"
691693
elif ray_found:
692694
if self.placement_group:
@@ -718,6 +720,9 @@ def _verify_args(self) -> None:
718720
raise ValueError(
719721
"Unrecognized distributed executor backend. Supported values "
720722
"are 'ray' or 'mp'.")
723+
if self.distributed_executor_backend == "ray":
724+
from vllm.executor import ray_utils
725+
ray_utils.assert_ray_available()
721726
if not self.disable_custom_all_reduce and self.world_size > 1:
722727
if is_hip():
723728
self.disable_custom_all_reduce = True

vllm/engine/async_llm_engine.py

+5
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ def from_engine_args(
380380
"""Creates an async LLM engine from the engine arguments."""
381381
# Create the engine configs.
382382
engine_config = engine_args.create_engine_config()
383+
384+
if engine_args.engine_use_ray:
385+
from vllm.executor import ray_utils
386+
ray_utils.assert_ray_available()
387+
383388
distributed_executor_backend = (
384389
engine_config.parallel_config.distributed_executor_backend)
385390

vllm/executor/ray_utils.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,26 @@ def execute_model_compiled_dag_remote(self, ignored):
4242
output = pickle.dumps(output)
4343
return output
4444

45+
ray_import_err = None
46+
4547
except ImportError as e:
46-
logger.warning(
47-
"Failed to import Ray with %r. For multi-node inference, "
48-
"please install Ray with `pip install ray`.", e)
4948
ray = None # type: ignore
49+
ray_import_err = e
5050
RayWorkerWrapper = None # type: ignore
5151

5252

53+
def ray_is_available() -> bool:
54+
"""Returns True if Ray is available."""
55+
return ray is not None
56+
57+
58+
def assert_ray_available():
59+
"""Raise an exception if Ray is not available."""
60+
if ray is None:
61+
raise ValueError("Failed to import Ray, please install Ray with "
62+
"`pip install ray`.") from ray_import_err
63+
64+
5365
def initialize_ray_cluster(
5466
parallel_config: ParallelConfig,
5567
ray_address: Optional[str] = None,
@@ -65,10 +77,7 @@ def initialize_ray_cluster(
6577
ray_address: The address of the Ray cluster. If None, uses
6678
the default Ray cluster address.
6779
"""
68-
if ray is None:
69-
raise ImportError(
70-
"Ray is not installed. Please install Ray to use multi-node "
71-
"serving.")
80+
assert_ray_available()
7281

7382
# Connect to a ray cluster.
7483
if is_hip() or is_xpu():

0 commit comments

Comments
 (0)