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

🐛 fixup request cancellation for v0.6.5 #196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 1 addition & 10 deletions src/vllm_tgis_adapter/grpc/grpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
extract_trace_headers,
log_tracing_disabled_warning,
)
from vllm.utils import iterate_with_cancellation

from vllm_tgis_adapter.logging import init_logger
from vllm_tgis_adapter.tgis_utils import logs
Expand Down Expand Up @@ -262,11 +261,8 @@ async def Generate(
),
)

async def is_cancelled() -> bool:
return context.cancelled()

result_generator: AsyncIterator[tuple[int, RequestOutput]] = (
merge_async_iterators(*generators, is_cancelled=is_cancelled)
merge_async_iterators(*generators)
)

resp_options = request.params.response
Expand Down Expand Up @@ -357,11 +353,6 @@ async def GenerateStream( # noqa: PLR0915, C901
**kwargs,
)

async def is_cancelled() -> bool:
return context.cancelled()

result_generator = iterate_with_cancellation(result_generator, is_cancelled)

resp_options = request.params.response

first_response = None
Expand Down
15 changes: 15 additions & 0 deletions src/vllm_tgis_adapter/tgis_utils/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import asyncio
import functools
import logging
import time
Expand Down Expand Up @@ -86,6 +87,12 @@ async def generate_with_logging(*args, **kwargs) -> AsyncGenerator[RequestOutput
async for response in old_generate_fn(*args, **kwargs):
last = response
yield response
except asyncio.CancelledError:
_log_cancellation(
request_id=request_id,
correlation_id=correlation_id,
)
raise
except BaseException as e:
# Log any error
_log_error(
Expand Down Expand Up @@ -118,6 +125,14 @@ def _log_error(request_id: str, correlation_id: str, exception_str: str) -> None
)


def _log_cancellation(request_id: str, correlation_id: str) -> None:
logger.info(
"Request cancelled: request_id=%s correlation_id=%s",
request_id,
correlation_id,
)


def _log_request(
request_id: str,
params: SamplingParams,
Expand Down
Loading