vllm/vllm/ray/lazy_utils.py
Chenheli Hua e4c3182c68
[Small] Capture AttributeError when checking ray dependency. (#29024)
Signed-off-by: Chenheli Hua <huachenheli@outlook.com>
2025-11-20 22:54:10 -08:00

31 lines
651 B
Python

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
def is_ray_initialized():
"""Check if Ray is initialized."""
try:
import ray
return ray.is_initialized()
except ImportError:
return False
except AttributeError:
return False
def is_in_ray_actor():
"""Check if we are in a Ray actor."""
try:
import ray
return (
ray.is_initialized()
and ray.get_runtime_context().get_actor_id() is not None
)
except ImportError:
return False
except AttributeError:
return False