Skip to content

vllm.v1.metrics.ray_wrappers

RayCounterWrapper

Bases: RayPrometheusMetric

Wraps around ray.util.metrics.Counter to provide same API as prometheus_client.Counter

Source code in vllm/v1/metrics/ray_wrappers.py
class RayCounterWrapper(RayPrometheusMetric):
    """Wraps around ray.util.metrics.Counter to provide same API as
    prometheus_client.Counter"""

    def __init__(self,
                 name: str,
                 documentation: Optional[str] = "",
                 labelnames: Optional[list[str]] = None):
        labelnames_tuple = tuple(labelnames) if labelnames else None
        self.metric = ray_metrics.Counter(name=name,
                                          description=documentation,
                                          tag_keys=labelnames_tuple)

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

metric instance-attribute

metric = Counter(
    name=name,
    description=documentation,
    tag_keys=labelnames_tuple,
)

__init__

__init__(
    name: str,
    documentation: Optional[str] = "",
    labelnames: Optional[list[str]] = None,
)
Source code in vllm/v1/metrics/ray_wrappers.py
def __init__(self,
             name: str,
             documentation: Optional[str] = "",
             labelnames: Optional[list[str]] = None):
    labelnames_tuple = tuple(labelnames) if labelnames else None
    self.metric = ray_metrics.Counter(name=name,
                                      description=documentation,
                                      tag_keys=labelnames_tuple)

inc

inc(value: Union[int, float] = 1.0)
Source code in vllm/v1/metrics/ray_wrappers.py
def inc(self, value: Union[int, float] = 1.0):
    if value == 0:
        return
    return self.metric.inc(value)

RayGaugeWrapper

Bases: RayPrometheusMetric

Wraps around ray.util.metrics.Gauge to provide same API as prometheus_client.Gauge

Source code in vllm/v1/metrics/ray_wrappers.py
class RayGaugeWrapper(RayPrometheusMetric):
    """Wraps around ray.util.metrics.Gauge to provide same API as
    prometheus_client.Gauge"""

    def __init__(self,
                 name: str,
                 documentation: Optional[str] = "",
                 labelnames: Optional[list[str]] = None):
        labelnames_tuple = tuple(labelnames) if labelnames else None
        self.metric = ray_metrics.Gauge(name=name,
                                        description=documentation,
                                        tag_keys=labelnames_tuple)

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

    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.metric.set(time.time())

metric instance-attribute

metric = Gauge(
    name=name,
    description=documentation,
    tag_keys=labelnames_tuple,
)

__init__

__init__(
    name: str,
    documentation: Optional[str] = "",
    labelnames: Optional[list[str]] = None,
)
Source code in vllm/v1/metrics/ray_wrappers.py
def __init__(self,
             name: str,
             documentation: Optional[str] = "",
             labelnames: Optional[list[str]] = None):
    labelnames_tuple = tuple(labelnames) if labelnames else None
    self.metric = ray_metrics.Gauge(name=name,
                                    description=documentation,
                                    tag_keys=labelnames_tuple)

set

set(value: Union[int, float])
Source code in vllm/v1/metrics/ray_wrappers.py
def set(self, value: Union[int, float]):
    return self.metric.set(value)

set_to_current_time

set_to_current_time()
Source code in vllm/v1/metrics/ray_wrappers.py
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.metric.set(time.time())

RayHistogramWrapper

Bases: RayPrometheusMetric

Wraps around ray.util.metrics.Histogram to provide same API as prometheus_client.Histogram

Source code in vllm/v1/metrics/ray_wrappers.py
class RayHistogramWrapper(RayPrometheusMetric):
    """Wraps around ray.util.metrics.Histogram to provide same API as
    prometheus_client.Histogram"""

    def __init__(self,
                 name: str,
                 documentation: Optional[str] = "",
                 labelnames: Optional[list[str]] = None,
                 buckets: Optional[list[float]] = None):
        labelnames_tuple = tuple(labelnames) if labelnames else None
        boundaries = buckets if buckets else []
        self.metric = ray_metrics.Histogram(name=name,
                                            description=documentation,
                                            tag_keys=labelnames_tuple,
                                            boundaries=boundaries)

    def observe(self, value: Union[int, float]):
        return self.metric.observe(value)

metric instance-attribute

metric = Histogram(
    name=name,
    description=documentation,
    tag_keys=labelnames_tuple,
    boundaries=boundaries,
)

__init__

__init__(
    name: str,
    documentation: Optional[str] = "",
    labelnames: Optional[list[str]] = None,
    buckets: Optional[list[float]] = None,
)
Source code in vllm/v1/metrics/ray_wrappers.py
def __init__(self,
             name: str,
             documentation: Optional[str] = "",
             labelnames: Optional[list[str]] = None,
             buckets: Optional[list[float]] = None):
    labelnames_tuple = tuple(labelnames) if labelnames else None
    boundaries = buckets if buckets else []
    self.metric = ray_metrics.Histogram(name=name,
                                        description=documentation,
                                        tag_keys=labelnames_tuple,
                                        boundaries=boundaries)

observe

observe(value: Union[int, float])
Source code in vllm/v1/metrics/ray_wrappers.py
def observe(self, value: Union[int, float]):
    return self.metric.observe(value)

RayPrometheusMetric

Source code in vllm/v1/metrics/ray_wrappers.py
class RayPrometheusMetric:

    def __init__(self):
        if ray_metrics is None:
            raise ImportError(
                "RayPrometheusMetric requires Ray to be installed.")

        self.metric: Metric = None

    def labels(self, *labels, **labelskwargs):
        if labelskwargs:
            for k, v in labelskwargs.items():
                if not isinstance(v, str):
                    labelskwargs[k] = str(v)

            self.metric.set_default_tags(labelskwargs)

        if labels:
            if len(labels) != len(self.metric._tag_keys):
                raise ValueError(
                    "Number of labels must match the number of tag keys. "
                    f"Expected {len(self.metric._tag_keys)}, got {len(labels)}"
                )

            self.metric.set_default_tags(
                dict(zip(self.metric._tag_keys, labels)))

        return self

metric instance-attribute

metric: Metric = None

__init__

__init__()
Source code in vllm/v1/metrics/ray_wrappers.py
def __init__(self):
    if ray_metrics is None:
        raise ImportError(
            "RayPrometheusMetric requires Ray to be installed.")

    self.metric: Metric = None

labels

labels(*labels, **labelskwargs)
Source code in vllm/v1/metrics/ray_wrappers.py
def labels(self, *labels, **labelskwargs):
    if labelskwargs:
        for k, v in labelskwargs.items():
            if not isinstance(v, str):
                labelskwargs[k] = str(v)

        self.metric.set_default_tags(labelskwargs)

    if labels:
        if len(labels) != len(self.metric._tag_keys):
            raise ValueError(
                "Number of labels must match the number of tag keys. "
                f"Expected {len(self.metric._tag_keys)}, got {len(labels)}"
            )

        self.metric.set_default_tags(
            dict(zip(self.metric._tag_keys, labels)))

    return self

RayPrometheusStatLogger

Bases: PrometheusStatLogger

RayPrometheusStatLogger uses Ray metrics instead.

Source code in vllm/v1/metrics/ray_wrappers.py
class RayPrometheusStatLogger(PrometheusStatLogger):
    """RayPrometheusStatLogger uses Ray metrics instead."""

    _gauge_cls = RayGaugeWrapper
    _counter_cls = RayCounterWrapper
    _histogram_cls = RayHistogramWrapper
    _spec_decoding_cls = RaySpecDecodingProm

    def __init__(self, vllm_config: VllmConfig, engine_index: int = 0):
        super().__init__(vllm_config, engine_index)

    @staticmethod
    def _unregister_vllm_metrics():
        # No-op on purpose
        pass

_counter_cls class-attribute instance-attribute

_counter_cls = RayCounterWrapper

_gauge_cls class-attribute instance-attribute

_gauge_cls = RayGaugeWrapper

_histogram_cls class-attribute instance-attribute

_histogram_cls = RayHistogramWrapper

_spec_decoding_cls class-attribute instance-attribute

_spec_decoding_cls = RaySpecDecodingProm

__init__

__init__(vllm_config: VllmConfig, engine_index: int = 0)
Source code in vllm/v1/metrics/ray_wrappers.py
def __init__(self, vllm_config: VllmConfig, engine_index: int = 0):
    super().__init__(vllm_config, engine_index)

_unregister_vllm_metrics staticmethod

_unregister_vllm_metrics()
Source code in vllm/v1/metrics/ray_wrappers.py
@staticmethod
def _unregister_vllm_metrics():
    # No-op on purpose
    pass

RaySpecDecodingProm

Bases: SpecDecodingProm

RaySpecDecodingProm is used by RayMetrics to log to Ray metrics. Provides the same metrics as SpecDecodingProm but uses Ray's util.metrics library.

Source code in vllm/v1/metrics/ray_wrappers.py
class RaySpecDecodingProm(SpecDecodingProm):
    """
    RaySpecDecodingProm is used by RayMetrics to log to Ray metrics.
    Provides the same metrics as SpecDecodingProm but uses Ray's
    util.metrics library.
    """

    _counter_cls = RayCounterWrapper

_counter_cls class-attribute instance-attribute

_counter_cls = RayCounterWrapper