Skip to content

[Bugfix]: Fix Promethus spec decode counter sum-of-sums #15415

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

Open
wants to merge 2 commits 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
24 changes: 21 additions & 3 deletions vllm/engine/metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

import time
from copy import copy
from typing import TYPE_CHECKING
from typing import Counter as CollectionsCounter
from typing import Dict, List, Optional, Type, Union, cast
Expand Down Expand Up @@ -669,20 +670,37 @@ def log(self, stats: Stats):
if local_interval_elapsed(stats.now, self.last_local_log,
self.local_interval):
if self.spec_decode_metrics is not None:
# The counters in self.spec_decode_metrics are aggregates.
# The Prometheus Counters must be incremented with deltas.
# Keep track of the previous value so we can compute deltas.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be inclined to do something like this:

def log_counter_from_cumulative(metric, cumulative, previous):
    self._log_counter(metric, cumulative - previous)

The method name helps the code to be self-documenting, requiring less comments

and then:

    self._log_from_cumulative(
        self.metrics.counter_spec_decode_num_accepted_tokens,
        self.spec_decode_metrics.accepted_tokens,
	self.spec_decode_prev_num_accepted)
    self.spec_decode_prev_num_accepted = self.spec_decode_metrics.accepted_tokens

since we don't need all of SpecDecodeWorkerMetrics

if self.last_spec_decode_metrics is None:
self.last_spec_decode_metrics = copy(
self.spec_decode_metrics)
self.last_spec_decode_metrics.accepted_tokens = 0
self.last_spec_decode_metrics.draft_tokens = 0
self.last_spec_decode_metrics.emitted_tokens = 0

snapshot = copy(self.spec_decode_metrics)

self._log_gauge(
self.metrics.gauge_spec_decode_draft_acceptance_rate,
self.spec_decode_metrics.draft_acceptance_rate)
self._log_gauge(self.metrics.gauge_spec_decode_efficiency,
self.spec_decode_metrics.system_efficiency)
self._log_counter(
self.metrics.counter_spec_decode_num_accepted_tokens,
self.spec_decode_metrics.accepted_tokens)
snapshot.accepted_tokens -
self.last_spec_decode_metrics.accepted_tokens)
self._log_counter(
self.metrics.counter_spec_decode_num_draft_tokens,
self.spec_decode_metrics.draft_tokens)
snapshot.draft_tokens -
self.last_spec_decode_metrics.draft_tokens)
self._log_counter(
self.metrics.counter_spec_decode_num_emitted_tokens,
self.spec_decode_metrics.emitted_tokens)
snapshot.emitted_tokens -
self.last_spec_decode_metrics.emitted_tokens)

self.last_spec_decode_metrics = snapshot

# Reset tracked stats for next interval.
self.num_prompt_tokens = []
Expand Down
1 change: 1 addition & 0 deletions vllm/engine/metrics_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(self, local_interval: float, vllm_config: VllmConfig) -> None:
self.last_local_log = time.time()
self.local_interval = local_interval
self.spec_decode_metrics: Optional[SpecDecodeWorkerMetrics] = None
self.last_spec_decode_metrics: Optional[SpecDecodeWorkerMetrics] = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This state could be on PrometheusStatLogger since it's not used by LoggingStatLogger


@abstractmethod
def log(self, stats: Stats) -> None:
Expand Down