Skip to content

Commit ac38dde

Browse files
committed
up
Signed-off-by: Rui Qiao <[email protected]>
1 parent 02606d9 commit ac38dde

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

tests/config/test_config_generation.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,36 @@ def create_config():
3636
assert deep_compare(normal_config_dict, empty_config_dict), (
3737
"Configs with normal CUDA_VISIBLE_DEVICES and CUDA_VISIBLE_DEVICES=\"\""
3838
" should be equivalent")
39+
40+
41+
def test_ray_runtime_env(monkeypatch: pytest.MonkeyPatch):
42+
# In testing, this method needs to be nested inside as ray does not
43+
# see the test module.
44+
def create_config():
45+
engine_args = EngineArgs(model="deepseek-ai/DeepSeek-V2-Lite",
46+
trust_remote_code=True)
47+
return engine_args.create_engine_config()
48+
49+
config = create_config()
50+
parallel_config = config.parallel_config
51+
assert parallel_config.ray_runtime_env is None
52+
53+
import ray
54+
ray.init()
55+
56+
runtime_env = {
57+
"env_vars": {
58+
"TEST_ENV_VAR": "test_value",
59+
},
60+
}
61+
62+
config_ref = ray.remote(create_config).options(
63+
runtime_env=runtime_env, ).remote()
64+
65+
config = ray.get(config_ref)
66+
parallel_config = config.parallel_config
67+
assert parallel_config.ray_runtime_env is not None
68+
assert parallel_config.ray_runtime_env.env_vars().get(
69+
"TEST_ENV_VAR") == "test_value"
70+
71+
ray.shutdown()

vllm/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656

5757
if TYPE_CHECKING:
5858
from _typeshed import DataclassInstance
59-
from ray.util.placement_group import PlacementGroup
6059
from ray.runtime_env import RuntimeEnv
60+
from ray.util.placement_group import PlacementGroup
6161
from transformers.configuration_utils import PretrainedConfig
6262

6363
import vllm.model_executor.layers.quantization as me_quant

vllm/engine/arg_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ def create_engine_config(
10681068
# as opposed to is_in_ray_actor().
10691069
import ray
10701070
ray_runtime_env = ray.get_runtime_context().runtime_env
1071-
logger.info(f"Using ray runtime env: {ray_runtime_env}")
1071+
logger.info("Using ray runtime env: %s", ray_runtime_env)
10721072

10731073
# Get the current placement group if Ray is initialized and
10741074
# we are in a Ray actor. If so, then the placement group will be

vllm/ray/lazy_utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3+
4+
5+
def is_ray_initialized():
6+
"""Check if Ray is initialized."""
7+
try:
8+
import ray
9+
return ray.is_initialized()
10+
except ImportError:
11+
return False
12+
13+
14+
def is_in_ray_actor():
15+
"""Check if we are in a Ray actor."""
16+
17+
try:
18+
import ray
19+
return (ray.is_initialized()
20+
and ray.get_runtime_context().get_actor_id() is not None)
21+
except ImportError:
22+
return False

vllm/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171

7272
import vllm.envs as envs
7373
from vllm.logger import enable_trace_function_call, init_logger
74-
from vllm.ray.utils import is_in_ray_actor
74+
from vllm.ray.lazy_utils import is_in_ray_actor
7575

7676
if TYPE_CHECKING:
7777
from argparse import Namespace

0 commit comments

Comments
 (0)