[Frontend] Gate scale-out endpoints behind opt-in flag (#54579)
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
This commit is contained in:
@@ -17,9 +17,9 @@ log) and vLLM continues to boot normally.
|
||||
|
||||
Even when the SDK is installed, :func:`attach_router` also requires
|
||||
``VLLM_ENABLE_COHERE_API=1`` in the environment before it will expose
|
||||
the routes. This keeps non-Cohere deployments that pull in the SDK for
|
||||
unrelated reasons (e.g. test dependencies) from accidentally exposing
|
||||
the api.
|
||||
the chat route. The render route additionally requires
|
||||
``VLLM_ENABLE_SCALE_OUT_ENDPOINTS=1``. These gates keep unrelated
|
||||
deployments from accidentally exposing the APIs.
|
||||
|
||||
Note: the handlers must live at module scope (not inside
|
||||
``attach_router``) so that FastAPI's ``typing.get_type_hints`` resolves
|
||||
@@ -71,6 +71,7 @@ if _SDK_AVAILABLE:
|
||||
from vllm.entrypoints.scale_out.token_in_token_out.protocol import GenerateRequest
|
||||
|
||||
router = APIRouter()
|
||||
render_router = APIRouter()
|
||||
|
||||
def _serving(request: Request) -> CohereServingChatV2 | None:
|
||||
return getattr(request.app.state, "cohere_serving_chat_v2", None)
|
||||
@@ -154,7 +155,7 @@ if _SDK_AVAILABLE:
|
||||
case _:
|
||||
return StreamingResponse(content=result, media_type="text/event-stream")
|
||||
|
||||
@router.post(
|
||||
@render_router.post(
|
||||
"/cohere/v2/chat/render",
|
||||
dependencies=[Depends(validate_json_request)],
|
||||
response_model=GenerateRequest,
|
||||
@@ -273,7 +274,7 @@ if _SDK_AVAILABLE:
|
||||
|
||||
|
||||
def attach_router(app: FastAPI) -> None:
|
||||
"""Register the ``/cohere/v2/chat`` routes on ``app``.
|
||||
"""Register the enabled ``/cohere/v2/chat`` routes on ``app``.
|
||||
|
||||
No-op when either:
|
||||
|
||||
@@ -305,4 +306,6 @@ def attach_router(app: FastAPI) -> None:
|
||||
)
|
||||
return
|
||||
app.include_router(router)
|
||||
if envs.VLLM_ENABLE_SCALE_OUT_ENDPOINTS:
|
||||
app.include_router(render_router)
|
||||
app.add_middleware(CohereErrorEnvelopeMiddleware)
|
||||
|
||||
@@ -5,7 +5,9 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from vllm import envs
|
||||
from vllm.engine.protocol import EngineClient
|
||||
from vllm.logger import init_logger
|
||||
from vllm.tasks import SupportedTask
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -15,6 +17,8 @@ if TYPE_CHECKING:
|
||||
else:
|
||||
RequestLogger = object
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def init_render_state(
|
||||
state: "State",
|
||||
@@ -62,6 +66,25 @@ def register_scale_out_api_routers(
|
||||
app: FastAPI,
|
||||
supported_tasks: tuple["SupportedTask", ...],
|
||||
):
|
||||
dedicated_mode = None
|
||||
if "render" in supported_tasks:
|
||||
dedicated_mode = "`vllm launch render`"
|
||||
elif getattr(app.state.args, "tokens_only", False):
|
||||
dedicated_mode = "`--tokens-only`"
|
||||
|
||||
enabled = envs.VLLM_ENABLE_SCALE_OUT_ENDPOINTS
|
||||
if dedicated_mode is not None and enabled is False:
|
||||
raise ValueError(
|
||||
"`VLLM_ENABLE_SCALE_OUT_ENDPOINTS=0` conflicts with "
|
||||
f"{dedicated_mode}; unset it or set it to 1"
|
||||
)
|
||||
if dedicated_mode is None and not enabled:
|
||||
logger.info(
|
||||
"Scale-out endpoints are disabled. Set "
|
||||
"VLLM_ENABLE_SCALE_OUT_ENDPOINTS=1 to enable them."
|
||||
)
|
||||
return
|
||||
|
||||
from .render.api_router import router as render_render
|
||||
|
||||
app.include_router(render_render)
|
||||
|
||||
Reference in New Issue
Block a user