@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / d830656a97
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 16, 22:00 UTC

[BugFix] Avoid unnecessary Ray import warnings (#6079)

Nick Hill committed Jul 2, 2024 at 23:09 UTC d830656a9722bfc719426ce6bdd13b3d9d456304
3 files changed +28 -9
vllm/config.py
+7 -2
@@ -682,11 +682,13 @@ class ParallelConfig:
682
683 from vllm.executor import ray_utils
684 backend = "mp"
685 - ray_found = ray_utils.ray is not None
685 + ray_found = ray_utils.ray_is_available()
686 if cuda_device_count_stateless() < self.world_size:
687 if not ray_found:
688 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
692 backend = "ray"
693 elif ray_found:
694 if self.placement_group:
@@ -718,6 +720,9 @@ class ParallelConfig:
720 raise ValueError(
721 "Unrecognized distributed executor backend. Supported values "
722 "are 'ray' or 'mp'.")
723 + if self.distributed_executor_backend == "ray":
724 + from vllm.executor import ray_utils
725 + ray_utils.assert_ray_available()
726 if not self.disable_custom_all_reduce and self.world_size > 1:
727 if is_hip():
728 self.disable_custom_all_reduce = True
vllm/engine/async_llm_engine.py
+5
@@ -380,6 +380,11 @@ class AsyncLLMEngine:
380 """Creates an async LLM engine from the engine arguments."""
381 # Create the engine configs.
382 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 +
388 distributed_executor_backend = (
389 engine_config.parallel_config.distributed_executor_backend)
390
vllm/executor/ray_utils.py
+16 -7
@@ -42,14 +42,26 @@ try:
42 output = pickle.dumps(output)
43 return output
44
45 + ray_import_err = None
46 +
47 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)
48 ray = None # type: ignore
49 + ray_import_err = e
50 RayWorkerWrapper = None # type: ignore
51
52
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 +
65 def initialize_ray_cluster(
66 parallel_config: ParallelConfig,
67 ray_address: Optional[str] = None,
@@ -65,10 +77,7 @@ def initialize_ray_cluster(
77 ray_address: The address of the Ray cluster. If None, uses
78 the default Ray cluster address.
79 """
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()
81
82 # Connect to a ray cluster.
83 if is_hip() or is_xpu():