Fix spec decode benchmark metrics (#41916)

Signed-off-by: noobhappylife <aratar1991@hotmail.com>
This commit is contained in:
noobHappylife
2026-05-07 09:23:21 -07:00
committed by GitHub
parent 2a16ece2d3
commit 06a60d3dd0
+23 -19
View File
@@ -128,26 +128,30 @@ async def fetch_spec_decode_metrics(
continue continue
if line.startswith("vllm:spec_decode"): if line.startswith("vllm:spec_decode"):
# Extract metric name (before labels) to avoid matching
# substrings inside label values.
parts = line.split(None, 1)
metric_name = parts[0].split("{")[0]
if not metric_name.endswith("_total"):
continue
found_spec_decode = True found_spec_decode = True
parts = line.split() with contextlib.suppress(ValueError):
if parts: if "num_drafts" in metric_name:
with contextlib.suppress(ValueError): num_drafts += int(float(parts[-1]))
if "num_drafts" in line: elif "num_draft_tokens" in metric_name:
num_drafts += int(float(parts[-1])) num_draft_tokens += int(float(parts[-1]))
elif "num_draft_tokens" in line: elif "num_accepted_tokens_per_pos" in metric_name:
num_draft_tokens += int(float(parts[-1])) pos_label = 'position="'
elif "num_accepted_tokens_per_pos" in line: if pos_label in line:
pos_label = 'position="' start = line.index(pos_label) + len(pos_label)
if pos_label in line: end = line.index('"', start)
start = line.index(pos_label) + len(pos_label) pos = int(line[start:end])
end = line.index('"', start) val = int(float(parts[-1]))
pos = int(line[start:end]) accepted_per_pos[pos] = (
val = int(float(parts[-1])) accepted_per_pos.get(pos, 0) + val
accepted_per_pos[pos] = ( )
accepted_per_pos.get(pos, 0) + val elif "num_accepted_tokens" in metric_name:
) num_accepted_tokens += int(float(parts[-1]))
elif "num_accepted_tokens" in line:
num_accepted_tokens += int(float(parts[-1]))
if not found_spec_decode: if not found_spec_decode:
return None return None