Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create socket before starting the engine and pass socket into the vllm server on startup #233

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/vllm_tgis_adapter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import vllm
from vllm.entrypoints.openai.api_server import (
build_async_engine_client,
create_server_socket,
)
from vllm.entrypoints.openai.cli_args import make_arg_parser
from vllm.utils import FlexibleArgumentParser
Expand All @@ -32,12 +33,18 @@
async def start_servers(args: argparse.Namespace) -> None:
loop = asyncio.get_running_loop()

# workaround to make sure that we bind the port before the engine is set up.
# This avoids race conditions with ray.
# see https://github.com/vllm-project/vllm/issues/8204
sock_addr = (args.host or "", args.port)
sock = create_server_socket(sock_addr)

tasks: list[asyncio.Task] = []
async with build_async_engine_client(args) as engine:
add_logging_wrappers(engine)

http_server_task = loop.create_task(
run_http_server(args, engine),
run_http_server(args, engine, sock),
name="http_server",
)
# The http server task will catch interrupt signals for us
Expand Down
6 changes: 6 additions & 0 deletions src/vllm_tgis_adapter/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

if TYPE_CHECKING:
import argparse
import socket

from fastapi import Request, Response
from vllm.engine.async_llm_engine import AsyncLLMEngine
Expand All @@ -24,6 +25,7 @@
async def run_http_server(
args: argparse.Namespace,
engine: AsyncLLMEngine | AsyncEngineClient,
sock: socket.socket | None = None,
**uvicorn_kwargs, # noqa: ANN003
) -> None:
# modified copy of vllm.entrypoints.openai.api_server.run_server that
Expand Down Expand Up @@ -63,6 +65,10 @@ async def set_correlation_id(request: Request, call_next: Callable) -> Response:
}
serve_kwargs.update(uvicorn_kwargs)

# should only be used in versions of vllm >= 0.7.3
if "sock" in inspect.getfullargspec(serve_http).args:
serve_kwargs["sock"] = sock

shutdown_coro = await serve_http(app, **serve_kwargs)

# launcher.serve_http returns a shutdown coroutine to await
Expand Down