Skip to content

Commit ad9bcdd

Browse files
committed
Enable engine config resolution on a CPU-only ingress replica
Signed-off-by: Jeffrey Wang <jeffreywang@anyscale.com>
1 parent 38ecf40 commit ad9bcdd

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • python/ray/llm/_internal/serve/routing_policies/kv_aware

python/ray/llm/_internal/serve/routing_policies/kv_aware/tokenizer.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from contextlib import contextmanager
12
from typing import Any, Dict, List, Optional, Union
23

34
import jinja2
@@ -20,6 +21,20 @@
2021
logger = get_logger(__name__)
2122

2223

24+
@contextmanager
25+
def _use_cpu_device():
26+
"""Resolve vLLM's device to CPU: the tokenizer's ingress replica has no
27+
accelerator, and config resolution otherwise fails without one."""
28+
from vllm.platforms import current_platform
29+
30+
# device_type is a class attribute; shadow it, then drop to restore.
31+
current_platform.device_type = "cpu"
32+
try:
33+
yield
34+
finally:
35+
current_platform.__dict__.pop("device_type", None)
36+
37+
2338
class TokenizeError(Exception):
2439
"""The request was rejected the same way vLLM's native ASGI route
2540
``/tokenize`` would reject it.
@@ -88,7 +103,8 @@ class Tokenizer:
88103

89104
def __init__(self, llm_config: LLMConfig):
90105
engine_config = llm_config.get_engine_config()
91-
_, vllm_config = _get_vllm_engine_config(llm_config)
106+
with _use_cpu_device():
107+
_, vllm_config = _get_vllm_engine_config(llm_config)
92108
self._model_config = vllm_config.model_config
93109

94110
frontend_args = FrontendArgs(**engine_config.frontend_kwargs)

0 commit comments

Comments
 (0)