Fix per file ruff ignores related to typing (#26254)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
+21
-21
@@ -3,7 +3,7 @@
|
||||
|
||||
import time
|
||||
from collections import Counter as CollectionsCounter
|
||||
from typing import Dict, List, Optional, Type, Union, cast
|
||||
from typing import Optional, Union, cast
|
||||
|
||||
import numpy as np
|
||||
import prometheus_client
|
||||
@@ -43,7 +43,7 @@ class Metrics:
|
||||
_counter_cls = prometheus_client.Counter
|
||||
_histogram_cls = prometheus_client.Histogram
|
||||
|
||||
def __init__(self, labelnames: List[str], vllm_config: VllmConfig):
|
||||
def __init__(self, labelnames: list[str], vllm_config: VllmConfig):
|
||||
# Unregister any existing vLLM collectors (for CI/CD)
|
||||
self._unregister_vllm_metrics()
|
||||
|
||||
@@ -304,7 +304,7 @@ class _RayGaugeWrapper:
|
||||
self,
|
||||
name: str,
|
||||
documentation: str = "",
|
||||
labelnames: Optional[List[str]] = None,
|
||||
labelnames: Optional[list[str]] = None,
|
||||
multiprocess_mode: str = "",
|
||||
):
|
||||
del multiprocess_mode
|
||||
@@ -330,7 +330,7 @@ class _RayCounterWrapper:
|
||||
prometheus_client.Counter"""
|
||||
|
||||
def __init__(
|
||||
self, name: str, documentation: str = "", labelnames: Optional[List[str]] = None
|
||||
self, name: str, documentation: str = "", labelnames: Optional[list[str]] = None
|
||||
):
|
||||
labelnames_tuple = tuple(labelnames) if labelnames else None
|
||||
self._counter = ray_metrics.Counter(
|
||||
@@ -355,8 +355,8 @@ class _RayHistogramWrapper:
|
||||
self,
|
||||
name: str,
|
||||
documentation: str = "",
|
||||
labelnames: Optional[List[str]] = None,
|
||||
buckets: Optional[List[float]] = None,
|
||||
labelnames: Optional[list[str]] = None,
|
||||
buckets: Optional[list[float]] = None,
|
||||
):
|
||||
labelnames_tuple = tuple(labelnames) if labelnames else None
|
||||
boundaries = buckets if buckets else []
|
||||
@@ -381,17 +381,17 @@ class RayMetrics(Metrics):
|
||||
Provides the same metrics as Metrics but uses Ray's util.metrics library.
|
||||
"""
|
||||
|
||||
_gauge_cls: Type[prometheus_client.Gauge] = cast(
|
||||
Type[prometheus_client.Gauge], _RayGaugeWrapper
|
||||
_gauge_cls: type[prometheus_client.Gauge] = cast(
|
||||
type[prometheus_client.Gauge], _RayGaugeWrapper
|
||||
)
|
||||
_counter_cls: Type[prometheus_client.Counter] = cast(
|
||||
Type[prometheus_client.Counter], _RayCounterWrapper
|
||||
_counter_cls: type[prometheus_client.Counter] = cast(
|
||||
type[prometheus_client.Counter], _RayCounterWrapper
|
||||
)
|
||||
_histogram_cls: Type[prometheus_client.Histogram] = cast(
|
||||
Type[prometheus_client.Histogram], _RayHistogramWrapper
|
||||
_histogram_cls: type[prometheus_client.Histogram] = cast(
|
||||
type[prometheus_client.Histogram], _RayHistogramWrapper
|
||||
)
|
||||
|
||||
def __init__(self, labelnames: List[str], vllm_config: VllmConfig):
|
||||
def __init__(self, labelnames: list[str], vllm_config: VllmConfig):
|
||||
if ray_metrics is None:
|
||||
raise ImportError("RayMetrics requires Ray to be installed.")
|
||||
super().__init__(labelnames, vllm_config)
|
||||
@@ -401,14 +401,14 @@ class RayMetrics(Metrics):
|
||||
pass
|
||||
|
||||
|
||||
def build_buckets(mantissa_lst: List[int], max_value: int) -> List[int]:
|
||||
def build_buckets(mantissa_lst: list[int], max_value: int) -> list[int]:
|
||||
"""
|
||||
Builds a list of buckets with increasing powers of 10 multiplied by
|
||||
mantissa values until the value exceeds the specified maximum.
|
||||
|
||||
"""
|
||||
exponent = 0
|
||||
buckets: List[int] = []
|
||||
buckets: list[int] = []
|
||||
while True:
|
||||
for m in mantissa_lst:
|
||||
value = m * 10**exponent
|
||||
@@ -419,7 +419,7 @@ def build_buckets(mantissa_lst: List[int], max_value: int) -> List[int]:
|
||||
exponent += 1
|
||||
|
||||
|
||||
def build_1_2_5_buckets(max_value: int) -> List[int]:
|
||||
def build_1_2_5_buckets(max_value: int) -> list[int]:
|
||||
"""
|
||||
Example:
|
||||
>>> build_1_2_5_buckets(100)
|
||||
@@ -428,7 +428,7 @@ def build_1_2_5_buckets(max_value: int) -> List[int]:
|
||||
return build_buckets([1, 2, 5], max_value)
|
||||
|
||||
|
||||
def build_1_2_3_5_8_buckets(max_value: int) -> List[int]:
|
||||
def build_1_2_3_5_8_buckets(max_value: int) -> list[int]:
|
||||
"""
|
||||
Example:
|
||||
>>> build_1_2_3_5_8_buckets(100)
|
||||
@@ -442,7 +442,7 @@ def local_interval_elapsed(now: float, last_log: float, local_interval: float) -
|
||||
return elapsed_time > local_interval
|
||||
|
||||
|
||||
def get_throughput(tracked_stats: List[int], now: float, last_log: float) -> float:
|
||||
def get_throughput(tracked_stats: list[int], now: float, last_log: float) -> float:
|
||||
return float(np.sum(tracked_stats) / (now - last_log))
|
||||
|
||||
|
||||
@@ -530,7 +530,7 @@ class PrometheusStatLogger(StatLoggerBase):
|
||||
_gauge_cls = prometheus_client.Gauge
|
||||
|
||||
def __init__(
|
||||
self, local_interval: float, labels: Dict[str, str], vllm_config: VllmConfig
|
||||
self, local_interval: float, labels: dict[str, str], vllm_config: VllmConfig
|
||||
) -> None:
|
||||
super().__init__(local_interval, vllm_config)
|
||||
# Prometheus metrics
|
||||
@@ -558,12 +558,12 @@ class PrometheusStatLogger(StatLoggerBase):
|
||||
for label, count in data.items():
|
||||
counter.labels(**{**self.labels, label_key: label}).inc(count)
|
||||
|
||||
def _log_histogram(self, histogram, data: Union[List[int], List[float]]) -> None:
|
||||
def _log_histogram(self, histogram, data: Union[list[int], list[float]]) -> None:
|
||||
# Convenience function for logging list to histogram.
|
||||
for datum in data:
|
||||
histogram.labels(**self.labels).observe(datum)
|
||||
|
||||
def _log_gauge_string(self, gauge, data: Dict[str, str]) -> None:
|
||||
def _log_gauge_string(self, gauge, data: dict[str, str]) -> None:
|
||||
gauge.labels(**data).set_to_current_time()
|
||||
|
||||
def _log_prometheus(self, stats: Stats) -> None:
|
||||
|
||||
Reference in New Issue
Block a user