forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR updates our grpc_server to add TGIS-style logs similar to https://github.com/IBM/text-generation-inference/blob/main/router/src/grpc_server.rs#L504-L512 This also disables the vllm per-request logging so that we don't double-log each request The timing info collected here is pretty rough, it doesn't plumb into the LLMEngine, it just times the generators to get the total time spent in the engine. We could do better, but this is a start. Example logs: ``` INFO 04-09 21:51:01 logs.py:43] generate_stream{input=[b'This is the story of Obama ridin...'] prefix_id= input_chars=[70] params=sampling { } stopping { max_new_tokens: 200 min_new_tokens: 16 } response { } decoding { } tokenization_time=0.45ms queue_and_inference_time=1096.67ms time_per_token=5.48ms total_time=1097.12ms input_toks=16}: Streaming response generated 200 tokens before NOT_FINISHED, output 848 chars: b' California. The story is told i...' INFO 04-09 21:51:08 logs.py:43] generate{input=[b'Lorem ipsum dolor sit amet, cons...', b'foooood man where is it'] prefix_id= input_chars=[469] params=sampling { } stopping { max_new_tokens: 20 min_new_tokens: 16 } response { } decoding { } tokenization_time=2.03ms queue_and_inference_time=122.23ms time_per_token=6.11ms total_time=124.26ms input_toks=124}: Sub-request 0 from batch of 2 generated 20 tokens before MAX_TOKENS, output 25 chars: b'?\\n\\n<!--\\n<!--\\n<!--\\n<!--\\n<!' INFO 04-09 21:51:08 logs.py:43] generate{input=[b'Lorem ipsum dolor sit amet, cons...', b'foooood man where is it'] prefix_id= input_chars=[469] params=sampling { } stopping { max_new_tokens: 20 min_new_tokens: 16 } response { } decoding { } tokenization_time=2.07ms queue_and_inference_time=122.22ms time_per_token=6.11ms total_time=124.29ms input_toks=7}: Sub-request 1 from batch of 2 generated 20 tokens before MAX_TOKENS, output 70 chars: b"?\\nI don't know.\\nI don't know.\\nI ..." ``` --------- Signed-off-by: Joe Runde <[email protected]> Signed-off-by: Joe Runde <[email protected]>
- Loading branch information
Showing
3 changed files
with
152 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Some methods for producing logs similar to TGIS""" | ||
import logging | ||
from typing import List | ||
|
||
from google.protobuf import text_format | ||
|
||
from vllm.entrypoints.grpc.pb.generation_pb2 import (GenerationResponse, | ||
Parameters, StopReason) | ||
|
||
|
||
def log_response(inputs: List[str], params: Parameters, prefix_id: str, | ||
response: GenerationResponse, times, kind_log: str, | ||
method_str: str, logger: logging.Logger): | ||
"""Logs responses similar to how the TGIS server does""" | ||
# This time contains both request validation and tokenization | ||
tokenization_time = times.engine_start - times.request_start | ||
llm_engine_time = times.end - times.engine_start | ||
time_per_token = _safe_div(llm_engine_time, response.generated_token_count) | ||
total_time = times.end - times.request_start | ||
output_len = len(response.text) | ||
short_output = _truncate(response.text, 32) | ||
short_input = [_truncate(input_, 32) for input_ in inputs] | ||
input_chars = sum(len(input_) for input_ in inputs) | ||
|
||
paramstr = text_format.MessageToString(params, as_one_line=True) | ||
span_str = (f"{method_str}{{input={short_input} prefix_id={prefix_id} " | ||
f"input_chars=[{input_chars}] params={paramstr} " | ||
f"tokenization_time={tokenization_time * 1e3:.2f}ms " | ||
f"queue_and_inference_time={llm_engine_time * 1e3:.2f}ms " | ||
f"time_per_token={time_per_token * 1e3:.2f}ms " | ||
f"total_time={total_time * 1e3:.2f}ms " | ||
f"input_toks={response.input_token_count}}}") | ||
stop_reason_str = StopReason.Name(response.stop_reason) | ||
|
||
if response.stop_reason == StopReason.ERROR: | ||
level = logging.ERROR | ||
elif response.stop_reason in { | ||
StopReason.CANCELLED, StopReason.TOKEN_LIMIT | ||
}: | ||
level = logging.WARN | ||
else: | ||
level = logging.INFO | ||
logger.log( | ||
level, f"{span_str}: {kind_log} generated " | ||
f"{response.generated_token_count} tokens before " | ||
f"{stop_reason_str}, output {output_len} chars: " | ||
f"{short_output}") | ||
|
||
|
||
def _truncate(text: str, len_: int) -> bytes: | ||
"""Truncates a string and escapes control characters""" | ||
text = f"{text:.{len_}}..." if len(text) > len_ else text | ||
return text.encode("unicode_escape") | ||
|
||
|
||
def _safe_div(a: float, b: float, *, default: float = 0.0) -> float: | ||
"""Simple safe division with a default answer for divide-by-zero. | ||
""" | ||
try: | ||
return a / b | ||
except ZeroDivisionError: | ||
return default |