lazy_utils.py 651 Bytes
Newer Older
1
2
3
4
5
6
7
8
# 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
9

10
11
12
        return ray.is_initialized()
    except ImportError:
        return False
13
14
    except AttributeError:
        return False
15
16
17
18
19
20
21


def is_in_ray_actor():
    """Check if we are in a Ray actor."""

    try:
        import ray
22
23
24
25
26

        return (
            ray.is_initialized()
            and ray.get_runtime_context().get_actor_id() is not None
        )
27
28
    except ImportError:
        return False
29
30
    except AttributeError:
        return False