Skip to content

Commit f5159e3

Browse files
author
Your Name
committed
metrics
1 parent c7c48fe commit f5159e3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

vllm/beam/metrics.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import re
22
from typing import Optional
33

4-
from prometheus_client import Summary
4+
from prometheus_client import Summary
55

66
from vllm.beam.emoji import emoji_count
77
from vllm.beam.stats import en_stopword_count, contains_more_than_four_quotes_in_a_row, \
88
top_ngram_count
99
from vllm.entrypoints.openai.protocol import CompletionRequest
10+
from vllm.entrypoints.openai.protocol import CompletionResponse
1011

1112
label_ptype_and_num_msg = dict(labelnames=["model_name"])
1213

@@ -50,6 +51,11 @@
5051
"The number of digit appears in the output",
5152
**label_ptype_and_num_msg,
5253
)
54+
OUTPUT_FILTERED = Summary(
55+
"output_filtered",
56+
"The count of filtered output",
57+
**label_ptype_and_num_msg,
58+
)
5359

5460
def gibberish_stat(name):
5561
return Summary(name, f"gibberish stat: {name}", **label_ptype_and_num_msg)
@@ -62,7 +68,7 @@ def gibberish_stat(name):
6268
RECOMMENDATION = gibberish_stat("recommendation")
6369
LIKELY_GIBBERISH = gibberish_stat("likely_gibberish_v0")
6470

65-
def report_metrics(request: CompletionRequest, output: Optional[str]):
71+
def report_metrics(request: CompletionRequest, output: Optional[str], response: Optional[CompletionResponse] = None):
6672
if output is None:
6773
return
6874

@@ -108,6 +114,10 @@ def report_metrics(request: CompletionRequest, output: Optional[str]):
108114
record(model_name, PREMIUMS, n_premiums)
109115
record(model_name, RECOMMENDATION, n_recommendations)
110116
record(model_name, LIKELY_GIBBERISH, int(likely_gibberish))
117+
if response is not None and isinstance(response, CompletionResponse):
118+
filtered = any([choice.is_filtered for choice in response.choices])
119+
record(model_name, OUTPUT_FILTERED, int(filtered))
120+
111121

112122

113123
def record(model_name, stat, value):

vllm/entrypoints/openai/serving_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async def _chunk_generator():
142142

143143
yield "data: [DONE]\n\n"
144144

145-
report_metrics(request, output)
145+
report_metrics(request, output, final)
146146

147147
return _chunk_generator()
148148

0 commit comments

Comments
 (0)