Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions python/ray/llm/_internal/serve/engines/vllm/vllm_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import inspect
import os
from typing import TYPE_CHECKING, AsyncGenerator, Optional, Tuple, Union

Expand Down Expand Up @@ -195,17 +196,22 @@ async def start(self) -> None:
state = State()
# TODO (Kourosh): There might be some variables that needs protection?
args = argparse.Namespace(
**vllm_frontend_args.__dict__,
**vllm_engine_args.__dict__,
**(vllm_frontend_args.__dict__ | vllm_engine_args.__dict__)
)

await init_app_state(
engine_client=self._engine_client,
# TODO (ahao): remove vllm_config for vllm v1.12
vllm_config=vllm_engine_config,
state=state,
args=args,
)
if "vllm_config" in inspect.signature(init_app_state).parameters:
await init_app_state(
self._engine_client,
vllm_config=vllm_engine_config,
state=state,
args=args,
)
else:
await init_app_state(
self._engine_client,
state=state,
args=args,
)
Comment on lines +202 to +214
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and reduce code duplication, you can refactor this logic to build a dictionary of keyword arguments and then call init_app_state once. This avoids repeating the call and makes the code more concise and easier to read.

        init_kwargs = {
            "engine_client": self._engine_client,
            "state": state,
            "args": args,
        }
        if "vllm_config" in inspect.signature(init_app_state).parameters:
            init_kwargs["vllm_config"] = vllm_engine_config

        await init_app_state(**init_kwargs)


self._oai_models = state.openai_serving_models
self._oai_serving_chat = state.openai_serving_chat
Expand Down