11# SPDX-License-Identifier: Apache-2.0
22import asyncio
3- import logging
43from collections .abc import AsyncGenerator , Mapping
54from copy import copy
65from typing import Optional , Union
3332from vllm .v1 .engine .parallel_sampling import ParentRequest
3433from vllm .v1 .engine .processor import Processor
3534from vllm .v1 .executor .abstract import Executor
36- from vllm .v1 .metrics .loggers import (LoggingStatLogger , PrometheusStatLogger ,
37- StatLoggerBase )
35+ from vllm .v1 .metrics .loggers import (StatLoggerBase , StatLoggerFactory ,
36+ setup_default_loggers )
3837from vllm .v1 .metrics .stats import IterationStats , SchedulerStats
3938
4039logger = init_logger (__name__ )
@@ -52,7 +51,28 @@ def __init__(
5251 use_cached_outputs : bool = False ,
5352 log_requests : bool = True ,
5453 start_engine_loop : bool = True ,
54+ stat_loggers : Optional [list [StatLoggerFactory ]] = None ,
5555 ) -> None :
56+ """
57+ Create an AsyncLLM.
58+
59+ Args:
60+ vllm_config: global configuration.
61+ executor_class: an Executor impl, e.g. MultiprocExecutor.
62+ log_stats: Whether to log stats.
63+ usage_context: Usage context of the LLM.
64+ mm_registry: Multi-modal registry.
65+ use_cached_outputs: Whether to use cached outputs.
66+ log_requests: Whether to log requests.
67+ start_engine_loop: Whether to start the engine loop.
68+ stat_loggers: customized stat loggers for the engine.
69+ If not provided, default stat loggers will be used.
70+ PLEASE BE AWARE THAT STAT LOGGER IS NOT STABLE
71+ IN V1, AND ITS BASE CLASS INTERFACE MIGHT CHANGE.
72+
73+ Returns:
74+ None
75+ """
5676 if not envs .VLLM_USE_V1 :
5777 raise ValueError (
5878 "Using V1 AsyncLLMEngine, but envs.VLLM_USE_V1=False. "
@@ -66,15 +86,12 @@ def __init__(
6686 self .log_stats = log_stats
6787
6888 # Set up stat loggers; independent set for each DP rank.
69- self .stat_loggers : list [list [StatLoggerBase ]] = []
70- if self .log_stats :
71- for i in range (vllm_config .parallel_config .data_parallel_size ):
72- loggers : list [StatLoggerBase ] = []
73- if logger .isEnabledFor (logging .INFO ):
74- loggers .append (LoggingStatLogger (engine_index = i ))
75- loggers .append (
76- PrometheusStatLogger (vllm_config , engine_index = i ))
77- self .stat_loggers .append (loggers )
89+ self .stat_loggers : list [list [StatLoggerBase ]] = setup_default_loggers (
90+ vllm_config = vllm_config ,
91+ log_stats = self .log_stats ,
92+ engine_num = vllm_config .parallel_config .data_parallel_size ,
93+ custom_stat_loggers = stat_loggers ,
94+ )
7895
7996 # Tokenizer (+ ensure liveness if running in another process).
8097 self .tokenizer = init_tokenizer_from_configs (
@@ -118,7 +135,7 @@ def from_vllm_config(
118135 vllm_config : VllmConfig ,
119136 start_engine_loop : bool = True ,
120137 usage_context : UsageContext = UsageContext .ENGINE_CONTEXT ,
121- stat_loggers : Optional [dict [ str , StatLoggerBase ]] = None ,
138+ stat_loggers : Optional [list [ StatLoggerFactory ]] = None ,
122139 disable_log_requests : bool = False ,
123140 disable_log_stats : bool = False ,
124141 ) -> "AsyncLLM" :
@@ -129,17 +146,12 @@ def from_vllm_config(
129146 "AsyncLLMEngine.from_vllm_config(...) or explicitly set "
130147 "VLLM_USE_V1=0 or 1 and report this issue on Github." )
131148
132- # FIXME(rob): refactor VllmConfig to include the StatLoggers
133- # include StatLogger in the Oracle decision.
134- if stat_loggers is not None :
135- raise ValueError ("Custom StatLoggers are not yet supported on V1. "
136- "Explicitly set VLLM_USE_V1=0 to disable V1." )
137-
138149 # Create the LLMEngine.
139150 return cls (
140151 vllm_config = vllm_config ,
141152 executor_class = Executor .get_class (vllm_config ),
142153 start_engine_loop = start_engine_loop ,
154+ stat_loggers = stat_loggers ,
143155 log_requests = not disable_log_requests ,
144156 log_stats = not disable_log_stats ,
145157 usage_context = usage_context ,
@@ -151,6 +163,7 @@ def from_engine_args(
151163 engine_args : AsyncEngineArgs ,
152164 start_engine_loop : bool = True ,
153165 usage_context : UsageContext = UsageContext .ENGINE_CONTEXT ,
166+ stat_loggers : Optional [list [StatLoggerFactory ]] = None ,
154167 ) -> "AsyncLLM" :
155168 """Create an AsyncLLM from the EngineArgs."""
156169
@@ -166,6 +179,7 @@ def from_engine_args(
166179 log_stats = not engine_args .disable_log_stats ,
167180 start_engine_loop = start_engine_loop ,
168181 usage_context = usage_context ,
182+ stat_loggers = stat_loggers ,
169183 )
170184
171185 def __del__ (self ):
0 commit comments