metrics.py 24.2 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
import time
5
from collections import Counter as CollectionsCounter
6
from typing import Optional, Union, cast
7
8

import numpy as np
9
import prometheus_client
10

11
12
from vllm.config import SupportsMetricsInfo, VllmConfig
from vllm.engine.metrics_types import StatLoggerBase, Stats
13
from vllm.executor.ray_utils import ray
14
from vllm.logger import init_logger
15

16
17
18
19
20
if ray is not None:
    from ray.util import metrics as ray_metrics
else:
    ray_metrics = None

21
22
logger = init_logger(__name__)

23
prometheus_client.disable_created_metrics()
24
25
26
27

# The begin-* and end* here are used by the documentation generator
# to extract the metrics definitions.

28

29
# --8<-- [start:metrics-definitions]
30
class Metrics:
31
32
33
34
35
36
    """
    vLLM uses a multiprocessing-based frontend for the OpenAI server.
    This means that we need to run prometheus_client in multiprocessing mode
    See https://prometheus.github.io/client_python/multiprocess/ for more
    details on limitations.
    """
37

38
    labelname_finish_reason = "finished_reason"
39
40
41
    labelname_waiting_lora_adapters = "waiting_lora_adapters"
    labelname_running_lora_adapters = "running_lora_adapters"
    labelname_max_lora = "max_lora"
42
43
44
    _gauge_cls = prometheus_client.Gauge
    _counter_cls = prometheus_client.Counter
    _histogram_cls = prometheus_client.Histogram
45

46
    def __init__(self, labelnames: list[str], vllm_config: VllmConfig):
47
        # Unregister any existing vLLM collectors (for CI/CD)
48
        self._unregister_vllm_metrics()
49

50
51
        max_model_len = vllm_config.model_config.max_model_len

52
53
        # Use this flag to hide metrics that were deprecated in
        # a previous release and which will be removed future
54
        self.show_hidden_metrics = vllm_config.observability_config.show_hidden_metrics
55

56
        # System stats
57
        #   Scheduler State
58
        self.gauge_scheduler_running = self._gauge_cls(
59
60
            name="vllm:num_requests_running",
            documentation="Number of requests currently running on GPU.",
61
            labelnames=labelnames,
62
63
            multiprocess_mode="sum",
        )
64
        self.gauge_scheduler_waiting = self._gauge_cls(
65
66
            name="vllm:num_requests_waiting",
            documentation="Number of requests waiting to be processed.",
67
            labelnames=labelnames,
68
69
            multiprocess_mode="sum",
        )
70
71
72
73
74
75
76
77
78
79
        self.gauge_lora_info = self._gauge_cls(
            name="vllm:lora_requests_info",
            documentation="Running stats on lora requests.",
            labelnames=[
                self.labelname_running_lora_adapters,
                self.labelname_max_lora,
                self.labelname_waiting_lora_adapters,
            ],
            multiprocess_mode="livemostrecent",
        )
80

81
        #   KV Cache Usage in %
82
        self.gauge_gpu_cache_usage = self._gauge_cls(
83
84
            name="vllm:gpu_cache_usage_perc",
            documentation="GPU KV-cache usage. 1 means 100 percent usage.",
85
            labelnames=labelnames,
86
87
            multiprocess_mode="sum",
        )
88

89
        # Iteration stats
90
        self.counter_num_preemption = self._counter_cls(
91
92
            name="vllm:num_preemptions_total",
            documentation="Cumulative number of preemption from the engine.",
93
94
            labelnames=labelnames,
        )
95
        self.counter_prompt_tokens = self._counter_cls(
96
97
            name="vllm:prompt_tokens_total",
            documentation="Number of prefill tokens processed.",
98
99
            labelnames=labelnames,
        )
100
        self.counter_generation_tokens = self._counter_cls(
101
102
            name="vllm:generation_tokens_total",
            documentation="Number of generation tokens processed.",
103
104
            labelnames=labelnames,
        )
harrywu's avatar
harrywu committed
105
106
107
108
        self.histogram_iteration_tokens = self._histogram_cls(
            name="vllm:iteration_tokens_total",
            documentation="Histogram of number of tokens per engine_step.",
            labelnames=labelnames,
109
110
            buckets=[1, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384],
        )
111
        self.histogram_time_to_first_token = self._histogram_cls(
112
113
114
115
            name="vllm:time_to_first_token_seconds",
            documentation="Histogram of time to first token in seconds.",
            labelnames=labelnames,
            buckets=[
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
                0.001,
                0.005,
                0.01,
                0.02,
                0.04,
                0.06,
                0.08,
                0.1,
                0.25,
                0.5,
                0.75,
                1.0,
                2.5,
                5.0,
                7.5,
                10.0,
                20.0,
                40.0,
                80.0,
                160.0,
                640.0,
                2560.0,
            ],
        )
140
141
        # Deprecated in 0.11 - Renamed as vllm:inter_token_latency_seconds
        # TODO: in 0.12, only enable if show_hidden_metrics=True
142
        self.histogram_time_per_output_token = self._histogram_cls(
143
            name="vllm:time_per_output_token_seconds",
144
145
            documentation=(
                "Histogram of time per output token in seconds."
146
147
                "DEPRECATED: Use vllm:inter_token_latency_seconds instead."
            ),
148
149
            labelnames=labelnames,
            buckets=[
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
                0.01,
                0.025,
                0.05,
                0.075,
                0.1,
                0.15,
                0.2,
                0.3,
                0.4,
                0.5,
                0.75,
                1.0,
                2.5,
                5.0,
                7.5,
                10.0,
                20.0,
                40.0,
                80.0,
            ],
        )
171
172
173
        self.histogram_inter_token_latency = self._histogram_cls(
            name="vllm:inter_token_latency_seconds",
            documentation="Histogram of inter token latency in seconds.",
174
175
            labelnames=labelnames,
            buckets=[
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
                0.01,
                0.025,
                0.05,
                0.075,
                0.1,
                0.15,
                0.2,
                0.3,
                0.4,
                0.5,
                0.75,
                1.0,
                2.5,
                5.0,
                7.5,
                10.0,
                20.0,
                40.0,
                80.0,
            ],
        )
197
198
199

        # Request stats
        #   Latency
harrywu's avatar
harrywu committed
200
        request_latency_buckets = [
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
            0.3,
            0.5,
            0.8,
            1.0,
            1.5,
            2.0,
            2.5,
            5.0,
            10.0,
            15.0,
            20.0,
            30.0,
            40.0,
            50.0,
            60.0,
            120.0,
            240.0,
            480.0,
            960.0,
            1920.0,
            7680.0,
harrywu's avatar
harrywu committed
222
        ]
223
        self.histogram_e2e_time_request = self._histogram_cls(
224
225
226
            name="vllm:e2e_request_latency_seconds",
            documentation="Histogram of end to end request latency in seconds.",
            labelnames=labelnames,
227
228
            buckets=request_latency_buckets,
        )
harrywu's avatar
harrywu committed
229
230
        self.histogram_queue_time_request = self._histogram_cls(
            name="vllm:request_queue_time_seconds",
231
            documentation="Histogram of time spent in WAITING phase for request.",
harrywu's avatar
harrywu committed
232
            labelnames=labelnames,
233
234
            buckets=request_latency_buckets,
        )
harrywu's avatar
harrywu committed
235
236
        self.histogram_inference_time_request = self._histogram_cls(
            name="vllm:request_inference_time_seconds",
237
            documentation="Histogram of time spent in RUNNING phase for request.",
harrywu's avatar
harrywu committed
238
            labelnames=labelnames,
239
240
            buckets=request_latency_buckets,
        )
harrywu's avatar
harrywu committed
241
242
        self.histogram_prefill_time_request = self._histogram_cls(
            name="vllm:request_prefill_time_seconds",
243
            documentation="Histogram of time spent in PREFILL phase for request.",
harrywu's avatar
harrywu committed
244
            labelnames=labelnames,
245
246
            buckets=request_latency_buckets,
        )
harrywu's avatar
harrywu committed
247
248
        self.histogram_decode_time_request = self._histogram_cls(
            name="vllm:request_decode_time_seconds",
249
            documentation="Histogram of time spent in DECODE phase for request.",
harrywu's avatar
harrywu committed
250
            labelnames=labelnames,
251
252
            buckets=request_latency_buckets,
        )
253

254
        #   Metadata
255
        self.histogram_num_prompt_tokens_request = self._histogram_cls(
256
257
258
259
260
            name="vllm:request_prompt_tokens",
            documentation="Number of prefill tokens processed.",
            labelnames=labelnames,
            buckets=build_1_2_5_buckets(max_model_len),
        )
261
262
263
264
265
266
        self.histogram_num_generation_tokens_request = self._histogram_cls(
            name="vllm:request_generation_tokens",
            documentation="Number of generation tokens processed.",
            labelnames=labelnames,
            buckets=build_1_2_5_buckets(max_model_len),
        )
harrywu's avatar
harrywu committed
267
268
        self.histogram_max_num_generation_tokens_request = self._histogram_cls(
            name="vllm:request_max_num_generation_tokens",
269
            documentation="Histogram of maximum number of requested generation tokens.",
harrywu's avatar
harrywu committed
270
            labelnames=labelnames,
271
272
            buckets=build_1_2_5_buckets(max_model_len),
        )
273
        self.histogram_n_request = self._histogram_cls(
274
275
276
277
278
            name="vllm:request_params_n",
            documentation="Histogram of the n request parameter.",
            labelnames=labelnames,
            buckets=[1, 2, 5, 10, 20],
        )
279
280
281
282
283
284
        self.histogram_max_tokens_request = self._histogram_cls(
            name="vllm:request_params_max_tokens",
            documentation="Histogram of the max_tokens request parameter.",
            labelnames=labelnames,
            buckets=build_1_2_5_buckets(max_model_len),
        )
285
        self.counter_request_success = self._counter_cls(
286
            name="vllm:request_success_total",
287
            documentation="Count of successfully processed requests.",
288
289
            labelnames=labelnames + [Metrics.labelname_finish_reason],
        )
290

291
    # --8<-- [end:metrics-definitions]
292

293
    def _unregister_vllm_metrics(self) -> None:
294
        for collector in list(prometheus_client.REGISTRY._collector_to_names):
295
            if hasattr(collector, "_name") and "vllm" in collector._name:
296
297
298
299
300
301
302
                prometheus_client.REGISTRY.unregister(collector)


class _RayGaugeWrapper:
    """Wraps around ray.util.metrics.Gauge to provide same API as
    prometheus_client.Gauge"""

303
304
305
306
    def __init__(
        self,
        name: str,
        documentation: str = "",
307
        labelnames: Optional[list[str]] = None,
308
309
        multiprocess_mode: str = "",
    ):
310
        del multiprocess_mode
311
        labelnames_tuple = tuple(labelnames) if labelnames else None
312
313
314
        self._gauge = ray_metrics.Gauge(
            name=name, description=documentation, tag_keys=labelnames_tuple
        )
315
316
317
318
319
320
321
322

    def labels(self, **labels):
        self._gauge.set_default_tags(labels)
        return self

    def set(self, value: Union[int, float]):
        return self._gauge.set(value)

323
324
325
326
    def set_to_current_time(self):
        # ray metrics doesn't have set_to_current time, https://docs.ray.io/en/latest/_modules/ray/util/metrics.html
        return self._gauge.set(time.time())

327
328
329
330
331

class _RayCounterWrapper:
    """Wraps around ray.util.metrics.Counter to provide same API as
    prometheus_client.Counter"""

332
    def __init__(
333
        self, name: str, documentation: str = "", labelnames: Optional[list[str]] = None
334
    ):
335
        labelnames_tuple = tuple(labelnames) if labelnames else None
336
337
338
        self._counter = ray_metrics.Counter(
            name=name, description=documentation, tag_keys=labelnames_tuple
        )
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353

    def labels(self, **labels):
        self._counter.set_default_tags(labels)
        return self

    def inc(self, value: Union[int, float] = 1.0):
        if value == 0:
            return
        return self._counter.inc(value)


class _RayHistogramWrapper:
    """Wraps around ray.util.metrics.Histogram to provide same API as
    prometheus_client.Histogram"""

354
355
356
357
    def __init__(
        self,
        name: str,
        documentation: str = "",
358
359
        labelnames: Optional[list[str]] = None,
        buckets: Optional[list[float]] = None,
360
    ):
361
        labelnames_tuple = tuple(labelnames) if labelnames else None
362
        boundaries = buckets if buckets else []
363
364
365
366
367
368
        self._histogram = ray_metrics.Histogram(
            name=name,
            description=documentation,
            tag_keys=labelnames_tuple,
            boundaries=boundaries,
        )
369
370
371
372
373
374
375

    def labels(self, **labels):
        self._histogram.set_default_tags(labels)
        return self

    def observe(self, value: Union[int, float]):
        return self._histogram.observe(value)
376
377
378
379
380
381
382


class RayMetrics(Metrics):
    """
    RayMetrics is used by RayPrometheusStatLogger to log to Ray metrics.
    Provides the same metrics as Metrics but uses Ray's util.metrics library.
    """
383

384
385
    _gauge_cls: type[prometheus_client.Gauge] = cast(
        type[prometheus_client.Gauge], _RayGaugeWrapper
386
    )
387
388
    _counter_cls: type[prometheus_client.Counter] = cast(
        type[prometheus_client.Counter], _RayCounterWrapper
389
    )
390
391
    _histogram_cls: type[prometheus_client.Histogram] = cast(
        type[prometheus_client.Histogram], _RayHistogramWrapper
392
    )
393

394
    def __init__(self, labelnames: list[str], vllm_config: VllmConfig):
395
396
        if ray_metrics is None:
            raise ImportError("RayMetrics requires Ray to be installed.")
397
        super().__init__(labelnames, vllm_config)
398
399
400
401
402

    def _unregister_vllm_metrics(self) -> None:
        # No-op on purpose
        pass

403

404
def build_buckets(mantissa_lst: list[int], max_value: int) -> list[int]:
405
    """
406
407
    Builds a list of buckets with increasing powers of 10 multiplied by
    mantissa values until the value exceeds the specified maximum.
408
409
410

    """
    exponent = 0
411
    buckets: list[int] = []
412
413
414
415
416
417
418
419
420
421
    while True:
        for m in mantissa_lst:
            value = m * 10**exponent
            if value <= max_value:
                buckets.append(value)
            else:
                return buckets
        exponent += 1


422
def build_1_2_5_buckets(max_value: int) -> list[int]:
423
424
425
426
427
428
429
430
    """
    Example:
    >>> build_1_2_5_buckets(100)
    [1, 2, 5, 10, 20, 50, 100]
    """
    return build_buckets([1, 2, 5], max_value)


431
def build_1_2_3_5_8_buckets(max_value: int) -> list[int]:
432
433
434
435
436
437
438
439
    """
    Example:
    >>> build_1_2_3_5_8_buckets(100)
    [1, 2, 3, 5, 8, 10, 20, 30, 50, 80, 100]
    """
    return build_buckets([1, 2, 3, 5, 8], max_value)


440
def local_interval_elapsed(now: float, last_log: float, local_interval: float) -> bool:
441
442
443
444
    elapsed_time = now - last_log
    return elapsed_time > local_interval


445
def get_throughput(tracked_stats: list[int], now: float, last_log: float) -> float:
446
    return float(np.sum(tracked_stats) / (now - last_log))
447
448


449
450
451
class LoggingStatLogger(StatLoggerBase):
    """LoggingStatLogger is used in LLMEngine to log to Stdout."""

452
453
    def __init__(self, local_interval: float, vllm_config: VllmConfig) -> None:
        super().__init__(local_interval, vllm_config)
454
455
456
        self.last_prompt_throughput: Optional[float] = None
        self.last_generation_throughput: Optional[float] = None

457
458
    def log(self, stats: Stats) -> None:
        """Called by LLMEngine.
459
        Logs to Stdout every self.local_interval seconds."""
460
461
462
463
464
465

        # Save tracked stats for token counters.
        self.num_prompt_tokens.append(stats.num_prompt_tokens_iter)
        self.num_generation_tokens.append(stats.num_generation_tokens_iter)

        # Log locally every local_interval seconds.
466
        if local_interval_elapsed(stats.now, self.last_local_log, self.local_interval):
467
            # Compute summary metrics for tracked stats (and log them
468
            # to prometheus if applicable).
469
470
471
            prompt_throughput = get_throughput(
                self.num_prompt_tokens, now=stats.now, last_log=self.last_local_log
            )
472
            generation_throughput = get_throughput(
473
474
                self.num_generation_tokens, now=stats.now, last_log=self.last_local_log
            )
475

476
            log_fn = logger.info
477
478
479
480
481
482
483
484
            if not any(
                (
                    prompt_throughput,
                    generation_throughput,
                    self.last_prompt_throughput,
                    self.last_generation_throughput,
                )
            ):
485
486
487
488
                # Avoid log noise on an idle production system
                log_fn = logger.debug

            log_fn(
489
490
491
492
493
494
495
496
497
498
499
500
501
                "Avg prompt throughput: %.1f tokens/s, "
                "Avg generation throughput: %.1f tokens/s, "
                "Running: %d reqs, Swapped: %d reqs, "
                "Pending: %d reqs, GPU KV cache usage: %.1f%%, "
                "CPU KV cache usage: %.1f%%.",
                prompt_throughput,
                generation_throughput,
                stats.num_running_sys,
                stats.num_swapped_sys,
                stats.num_waiting_sys,
                stats.gpu_cache_usage_sys * 100,
                stats.cpu_cache_usage_sys * 100,
            )
502
503
504
505
            if (
                stats.cpu_prefix_cache_hit_rate >= 0
                or stats.gpu_prefix_cache_hit_rate >= 0
            ):
506
                log_fn(
507
508
509
510
                    "Prefix cache hit rate: GPU: %.2f%%, CPU: %.2f%%",
                    stats.gpu_prefix_cache_hit_rate * 100,
                    stats.cpu_prefix_cache_hit_rate * 100,
                )
511

512
513
514
515
516
517
518
519
520
            self._reset(stats, prompt_throughput, generation_throughput)

    def _reset(self, stats, prompt_throughput, generation_throughput) -> None:
        # Reset tracked stats for next interval.
        self.num_prompt_tokens = []
        self.num_generation_tokens = []
        self.last_local_log = stats.now
        self.last_prompt_throughput = prompt_throughput
        self.last_generation_throughput = generation_throughput
521

522
523
524
    def info(self, type: str, obj: SupportsMetricsInfo) -> None:
        raise NotImplementedError

525
526

class PrometheusStatLogger(StatLoggerBase):
527
    """PrometheusStatLogger is used LLMEngine to log to Prometheus."""
528

529
    _metrics_cls = Metrics
530
    _gauge_cls = prometheus_client.Gauge
531

532
    def __init__(
533
        self, local_interval: float, labels: dict[str, str], vllm_config: VllmConfig
534
    ) -> None:
535
        super().__init__(local_interval, vllm_config)
536
537
        # Prometheus metrics
        self.labels = labels
538
539
540
        self.metrics = self._metrics_cls(
            labelnames=list(labels.keys()), vllm_config=vllm_config
        )
541

542
543
544
    def _log_gauge(self, gauge, data: Union[int, float]) -> None:
        # Convenience function for logging to gauge.
        gauge.labels(**self.labels).set(data)
545

546
547
    def _log_counter(self, counter, data: Union[int, float]) -> None:
        # Convenience function for logging to counter.
548
549
        # Prevent ValueError from negative increment
        if data < 0:
550
            logger.warning("Skipping negative increment of %g to %s", data, counter)
551
            return
552
553
        counter.labels(**self.labels).inc(data)

554
555
556
    def _log_counter_labels(
        self, counter, data: CollectionsCounter, label_key: str
    ) -> None:
557
558
559
560
        # Convenience function for collection counter of labels.
        for label, count in data.items():
            counter.labels(**{**self.labels, label_key: label}).inc(count)

561
    def _log_histogram(self, histogram, data: Union[list[int], list[float]]) -> None:
562
563
564
        # Convenience function for logging list to histogram.
        for datum in data:
            histogram.labels(**self.labels).observe(datum)
565

566
    def _log_gauge_string(self, gauge, data: dict[str, str]) -> None:
567
        gauge.labels(**data).set_to_current_time()
568

569
    def _log_prometheus(self, stats: Stats) -> None:
570
        # System state data
571
572
573
        self._log_gauge(self.metrics.gauge_scheduler_running, stats.num_running_sys)
        self._log_gauge(self.metrics.gauge_scheduler_waiting, stats.num_waiting_sys)
        self._log_gauge(self.metrics.gauge_gpu_cache_usage, stats.gpu_cache_usage_sys)
574
575
576
        # Including max-lora in metric, in future this property of lora
        # config maybe extended to be dynamic.
        lora_info = {
577
578
579
580
581
582
583
            self.metrics.labelname_running_lora_adapters: ",".join(
                stats.running_lora_adapters
            ),
            self.metrics.labelname_waiting_lora_adapters: ",".join(
                stats.waiting_lora_adapters
            ),
            self.metrics.labelname_max_lora: stats.max_lora,
584
585
        }
        self._log_gauge_string(self.metrics.gauge_lora_info, lora_info)
586
        # Iteration level data
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
        self._log_counter(
            self.metrics.counter_num_preemption, stats.num_preemption_iter
        )
        self._log_counter(
            self.metrics.counter_prompt_tokens, stats.num_prompt_tokens_iter
        )
        self._log_counter(
            self.metrics.counter_generation_tokens, stats.num_generation_tokens_iter
        )
        self._log_histogram(
            self.metrics.histogram_iteration_tokens, [stats.num_tokens_iter]
        )
        self._log_histogram(
            self.metrics.histogram_time_to_first_token, stats.time_to_first_tokens_iter
        )
        self._log_histogram(
            self.metrics.histogram_time_per_output_token,
            stats.inter_token_latencies_iter,
        )
        self._log_histogram(
            self.metrics.histogram_inter_token_latency, stats.inter_token_latencies_iter
        )
609
610
611

        # Request level data
        # Latency
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
        self._log_histogram(
            self.metrics.histogram_e2e_time_request, stats.time_e2e_requests
        )
        self._log_histogram(
            self.metrics.histogram_queue_time_request, stats.time_queue_requests
        )
        self._log_histogram(
            self.metrics.histogram_inference_time_request, stats.time_inference_requests
        )
        self._log_histogram(
            self.metrics.histogram_prefill_time_request, stats.time_prefill_requests
        )
        self._log_histogram(
            self.metrics.histogram_decode_time_request, stats.time_decode_requests
        )
627
        # Metadata
628
629
630
631
632
633
634
635
636
637
        finished_reason_counter = CollectionsCounter(stats.finished_reason_requests)
        self._log_counter_labels(
            self.metrics.counter_request_success,
            finished_reason_counter,
            Metrics.labelname_finish_reason,
        )
        self._log_histogram(
            self.metrics.histogram_num_prompt_tokens_request,
            stats.num_prompt_tokens_requests,
        )
638
639
        self._log_histogram(
            self.metrics.histogram_num_generation_tokens_request,
640
641
            stats.num_generation_tokens_requests,
        )
642
        self._log_histogram(self.metrics.histogram_n_request, stats.n_requests)
harrywu's avatar
harrywu committed
643
644
        self._log_histogram(
            self.metrics.histogram_max_num_generation_tokens_request,
645
646
647
648
649
            stats.max_num_generation_tokens_requests,
        )
        self._log_histogram(
            self.metrics.histogram_max_tokens_request, stats.max_tokens_requests
        )
650

651
652
    def log(self, stats: Stats):
        """Logs to prometheus and tracked stats every iteration."""
653
654
655
656
        # Log to prometheus.
        self._log_prometheus(stats)

        # Save tracked stats for token counters.
657
658
        self.num_prompt_tokens.append(stats.num_prompt_tokens_iter)
        self.num_generation_tokens.append(stats.num_generation_tokens_iter)
659
660

        # Log locally every local_interval seconds.
661
        if local_interval_elapsed(stats.now, self.last_local_log, self.local_interval):
662
663
664
665
            # Reset tracked stats for next interval.
            self.num_prompt_tokens = []
            self.num_generation_tokens = []
            self.last_local_log = stats.now
666

667
668
669
670
671
672
673
674
675
676
    def info(self, type: str, obj: SupportsMetricsInfo) -> None:
        # Info type metrics are syntactic sugar for a gauge permanently set to 1
        # Since prometheus multiprocessing mode does not support Info, emulate
        # info here with a gauge.
        if type == "cache_config":
            metrics_info = obj.metrics_info()
            info_gauge = self._gauge_cls(
                name="vllm:cache_config_info",
                documentation="Information of the LLMEngine CacheConfig",
                labelnames=metrics_info.keys(),
677
678
                multiprocess_mode="mostrecent",
            )
679
680
            info_gauge.labels(**metrics_info).set(1)

681

682
683
class RayPrometheusStatLogger(PrometheusStatLogger):
    """RayPrometheusStatLogger uses Ray metrics instead."""
684

685
    _metrics_cls = RayMetrics
686
687
688

    def info(self, type: str, obj: SupportsMetricsInfo) -> None:
        return None