1
1
import re
2
2
from typing import Optional
3
3
4
- from prometheus_client import Summary
4
+ from prometheus_client import Summary
5
5
6
6
from vllm .beam .emoji import emoji_count
7
7
from vllm .beam .stats import en_stopword_count , contains_more_than_four_quotes_in_a_row , \
8
8
top_ngram_count
9
9
from vllm .entrypoints .openai .protocol import CompletionRequest
10
+ from vllm .entrypoints .openai .protocol import CompletionResponse
10
11
11
12
label_ptype_and_num_msg = dict (labelnames = ["model_name" ])
12
13
50
51
"The number of digit appears in the output" ,
51
52
** label_ptype_and_num_msg ,
52
53
)
54
+ OUTPUT_FILTERED = Summary (
55
+ "output_filtered" ,
56
+ "The count of filtered output" ,
57
+ ** label_ptype_and_num_msg ,
58
+ )
53
59
54
60
def gibberish_stat (name ):
55
61
return Summary (name , f"gibberish stat: { name } " , ** label_ptype_and_num_msg )
@@ -62,7 +68,7 @@ def gibberish_stat(name):
62
68
RECOMMENDATION = gibberish_stat ("recommendation" )
63
69
LIKELY_GIBBERISH = gibberish_stat ("likely_gibberish_v0" )
64
70
65
- def report_metrics (request : CompletionRequest , output : Optional [str ]):
71
+ def report_metrics (request : CompletionRequest , output : Optional [str ], response : Optional [ CompletionResponse ] = None ):
66
72
if output is None :
67
73
return
68
74
@@ -108,6 +114,10 @@ def report_metrics(request: CompletionRequest, output: Optional[str]):
108
114
record (model_name , PREMIUMS , n_premiums )
109
115
record (model_name , RECOMMENDATION , n_recommendations )
110
116
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
+
111
121
112
122
113
123
def record (model_name , stat , value ):
0 commit comments