Skip to content

Commit

Permalink
[V1][Metrics] Fix "Duplicated timeseries" error in test_async_llm.py
Browse files Browse the repository at this point in the history
Fixes:

ValueError: Duplicated timeseries in CollectorRegistry: {'vllm:num_requests_running'}

Same solution as in v0 - in case there are multiple engine instances
in the same process (only in tests?), just de-register the metrics
before registering them.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
  • Loading branch information
markmc committed Jan 26, 2025
1 parent 3a5426a commit 3ff78fe
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vllm/v1/metrics/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def __init__(self, labels: Dict[str, str]):
labelnames = self.labels.keys()
labelvalues = self.labels.values()

self._unregister_vllm_metrics()

self.gauge_scheduler_running = prometheus_client.Gauge(
name="vllm:num_requests_running",
documentation="Number of requests in model execution batches.",
Expand All @@ -63,3 +65,10 @@ def log(self, scheduler_stats: SchedulerStats):
"""Log to prometheus."""
self.gauge_scheduler_running.set(scheduler_stats.num_running_reqs)
self.gauge_scheduler_waiting.set(scheduler_stats.num_waiting_reqs)

@staticmethod
def _unregister_vllm_metrics():
# Unregister any existing vLLM collectors (for CI/CD
for collector in list(prometheus_client.REGISTRY._collector_to_names):
if hasattr(collector, "_name") and "vllm" in collector._name:
prometheus_client.REGISTRY.unregister(collector)

0 comments on commit 3ff78fe

Please sign in to comment.