Add LoRA metrics for potential auto scaling (#15149)

This commit is contained in:
Chenxi Li
2025-12-24 12:13:52 -08:00
committed by GitHub
parent ae434f7821
commit 17b38f88bc
2 changed files with 83 additions and 1 deletions
+34
View File
@@ -241,6 +241,11 @@ class SchedulerStats:
# CUDA graph
is_cuda_graph: float = 0.0
# LoRA pool metrics
lora_pool_slots_used: int = 0
lora_pool_slots_total: int = 0
lora_pool_utilization: float = 0.0
@dataclass
class DPCooperationInfo:
@@ -265,11 +270,13 @@ class SchedulerMetricsCollector:
def __init__(
self,
labels: Dict[str, str],
enable_lora: bool = False,
) -> None:
# We need to import prometheus_client after setting the env variable `PROMETHEUS_MULTIPROC_DIR`
from prometheus_client import Counter, Gauge, Histogram, Summary
self.labels = labels
self.enable_lora = enable_lora
self.last_log_time = time.perf_counter()
self.num_running_reqs = Gauge(
@@ -692,6 +699,27 @@ class SchedulerMetricsCollector:
labelnames=list(labels.keys()) + ["forward_mode"],
)
# LoRA pool metrics (only created when LoRA is enabled)
if self.enable_lora:
self.lora_pool_slots_used = Gauge(
name="sglang:lora_pool_slots_used",
documentation="Number of LoRA adapter slots currently occupied in GPU memory.",
labelnames=labels.keys(),
multiprocess_mode="mostrecent",
)
self.lora_pool_slots_total = Gauge(
name="sglang:lora_pool_slots_total",
documentation="Total number of LoRA adapter slots available (max_loras_per_batch).",
labelnames=labels.keys(),
multiprocess_mode="mostrecent",
)
self.lora_pool_utilization = Gauge(
name="sglang:lora_pool_utilization",
documentation="LoRA pool utilization ratio (used/total). 1.0 means pool is full.",
labelnames=labels.keys(),
multiprocess_mode="mostrecent",
)
self.new_token_ratio = Gauge(
name="sglang:new_token_ratio",
documentation="The new token ratio.",
@@ -868,6 +896,12 @@ class SchedulerMetricsCollector:
# CUDA graph
self._log_gauge(self.is_cuda_graph, stats.is_cuda_graph)
# LoRA pool metrics (only logged if LoRA is enabled)
if self.enable_lora:
self._log_gauge(self.lora_pool_slots_used, stats.lora_pool_slots_used)
self._log_gauge(self.lora_pool_slots_total, stats.lora_pool_slots_total)
self._log_gauge(self.lora_pool_utilization, stats.lora_pool_utilization)
self.last_log_time = time.perf_counter()
def log_grammar_stats(self, grammar_stats) -> None: