2025-08-01 23:54:40 -07:00
|
|
|
# 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
|
2025-10-05 15:06:22 +01:00
|
|
|
|
2025-08-01 23:54:40 -07:00
|
|
|
return ray.is_initialized()
|
|
|
|
|
except ImportError:
|
|
|
|
|
return False
|
2025-11-20 22:54:10 -08:00
|
|
|
except AttributeError:
|
|
|
|
|
return False
|
2025-08-01 23:54:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_in_ray_actor():
|
|
|
|
|
"""Check if we are in a Ray actor."""
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import ray
|
2025-10-05 15:06:22 +01:00
|
|
|
|
2025-08-01 23:54:40 -07:00
|
|
|
return (
|
|
|
|
|
ray.is_initialized()
|
|
|
|
|
and ray.get_runtime_context().get_actor_id() is not None
|
|
|
|
|
)
|
|
|
|
|
except ImportError:
|
|
|
|
|
return False
|
2025-11-20 22:54:10 -08:00
|
|
|
except AttributeError:
|
|
|
|
|
return False
|