diff --git a/vllm/entrypoints/api_server.py b/vllm/entrypoints/api_server.py index 03c0222d75fab..23d90678da65c 100644 --- a/vllm/entrypoints/api_server.py +++ b/vllm/entrypoints/api_server.py @@ -8,9 +8,8 @@ import asyncio import json import ssl -from dataclasses import asdict -from typing import AsyncGenerator from argparse import Namespace +from dataclasses import asdict from typing import Any, AsyncGenerator, Optional from fastapi import FastAPI, Request @@ -19,8 +18,8 @@ from vllm.engine.arg_utils import AsyncEngineArgs from vllm.engine.async_llm_engine import AsyncLLMEngine from vllm.entrypoints.launcher import serve_http -from vllm.logger import init_logger from vllm.inputs import TokensPrompt +from vllm.logger import init_logger from vllm.lora.request import LoRARequest from vllm.sampling_params import SamplingParams from vllm.usage.usage_lib import UsageContext @@ -115,8 +114,8 @@ def build_app(args: Namespace) -> FastAPI: async def init_app( - args: Namespace, - llm_engine: Optional[AsyncLLMEngine] = None, + args: Namespace, + llm_engine: Optional[AsyncLLMEngine] = None, ) -> FastAPI: app = build_app(args) @@ -125,7 +124,7 @@ async def init_app( engine_args = AsyncEngineArgs.from_cli_args(args) engine = (llm_engine if llm_engine is not None else AsyncLLMEngine.from_engine_args( - engine_args, usage_context=UsageContext.API_SERVER)) + engine_args, usage_context=UsageContext.API_SERVER)) return app @@ -155,28 +154,32 @@ async def run_server(args: Namespace, if __name__ == "__main__": - parser = FlexibleArgumentParser() - parser.add_argument("--host", type=str, default=None) - parser.add_argument("--port", type=int, default=8000) - parser.add_argument("--ssl-keyfile", type=str, default=None) - parser.add_argument("--ssl-certfile", type=str, default=None) - parser.add_argument("--ssl-ca-certs", - type=str, - default=None, - help="The CA certificates file") - parser.add_argument( - "--ssl-cert-reqs", - type=int, - default=int(ssl.CERT_NONE), - help="Whether client certificate is required (see stdlib ssl module's)" - ) - parser.add_argument( - "--root-path", - type=str, - default=None, - help="FastAPI root_path when app is behind a path based routing proxy") - parser.add_argument("--log-level", type=str, default="debug") - parser = AsyncEngineArgs.add_cli_args(parser) - args = parser.parse_args() - - asyncio.run(run_server(args)) + try: + parser = FlexibleArgumentParser() + parser.add_argument("--host", type=str, default=None) + parser.add_argument("--port", type=int, default=8000) + parser.add_argument("--ssl-keyfile", type=str, default=None) + parser.add_argument("--ssl-certfile", type=str, default=None) + parser.add_argument("--ssl-ca-certs", + type=str, + default=None, + help="The CA certificates file") + parser.add_argument( + "--ssl-cert-reqs", + type=int, + default=int(ssl.CERT_NONE), + help="Whether client certificate is required (see stdlib ssl module's)" + ) + parser.add_argument( + "--root-path", + type=str, + default=None, + help="FastAPI root_path when app is behind a path based routing proxy") + parser.add_argument("--log-level", type=str, default="debug") + parser = AsyncEngineArgs.add_cli_args(parser) + args = parser.parse_args() + + asyncio.run(run_server(args)) + except Exception as e: + logger.error(str(e)) + raise