Skip to content

Commit

Permalink
Make log statistics interval configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Sakalya Deshpande <[email protected]>
  • Loading branch information
I746365 committed Feb 16, 2025
1 parent d3d547e commit 87df0fa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions vllm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,9 @@ class ObservabilityConfig:

# If set, collects the model execute time for the request.
collect_model_execute_time: bool = False

# Interval for collecting log_stats. default value is 5.0
log_stats_interval: float = 5.0

def compute_hash(self) -> str:
"""
Expand Down
8 changes: 7 additions & 1 deletion vllm/engine/arg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class EngineArgs:
max_num_seqs: Optional[int] = None
max_logprobs: int = 20 # Default value for OpenAI Chat Completions API
disable_log_stats: bool = False
log_stats_interval: float = 5.0
revision: Optional[str] = None
code_revision: Optional[str] = None
rope_scaling: Optional[Dict[str, Any]] = None
Expand Down Expand Up @@ -1025,6 +1026,11 @@ def add_cli_args(parser: FlexibleArgumentParser) -> FlexibleArgumentParser:
"Different platforms may support different configs. Make sure the "
"configs are valid for the platform you are using. The input format"
" is like '{\"config_key\":\"config_value\"}'")

parser.add_argument('--log-stats-interval',
type=float,
default=EngineArgs.log_stats_interval,
help='Interval for collecting log statistics.')
return parser

@classmethod
Expand Down Expand Up @@ -1319,7 +1325,7 @@ def create_engine_config(self,
or "all" in detailed_trace_modules,
collect_model_execute_time="worker" in detailed_trace_modules
or "all" in detailed_trace_modules,
)
log_stats_interval=self.log_stats_interval)

config = VllmConfig(
model_config=model_config,
Expand Down
7 changes: 4 additions & 3 deletions vllm/engine/llm_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
from vllm.version import __version__ as VLLM_VERSION

logger = init_logger(__name__)
_LOCAL_LOGGING_INTERVAL_SEC = 5

_G = TypeVar("_G", bound=BaseTokenizerGroup, default=BaseTokenizerGroup)
_O = TypeVar("_O", RequestOutput, PoolingRequestOutput)
Expand Down Expand Up @@ -370,11 +369,13 @@ def get_tokenizer_for_seq(sequence: Sequence) -> AnyTokenizer:
self.stat_loggers = {
"logging":
LoggingStatLogger(
local_interval=_LOCAL_LOGGING_INTERVAL_SEC,
local_interval=self.vllm_config.observability_config.
log_stats_interval,
vllm_config=vllm_config),
"prometheus":
PrometheusStatLogger(
local_interval=_LOCAL_LOGGING_INTERVAL_SEC,
local_interval=self.vllm_config.observability_config.
log_stats_interval,
labels=dict(
model_name=self.model_config.served_model_name),
vllm_config=vllm_config),
Expand Down
2 changes: 1 addition & 1 deletion vllm/v1/engine/async_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
self.stat_loggers: List[StatLoggerBase] = []
if self.log_stats:
self.stat_loggers.extend([
LoggingStatLogger(),
LoggingStatLogger(vllm_config),
PrometheusStatLogger(vllm_config),
])

Expand Down
10 changes: 5 additions & 5 deletions vllm/v1/metrics/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

logger = init_logger(__name__)

_LOCAL_LOGGING_INTERVAL_SEC = 5.0


class StatLoggerBase(ABC):

Expand All @@ -28,8 +26,9 @@ def log(self, scheduler_stats: SchedulerStats,

class LoggingStatLogger(StatLoggerBase):

def __init__(self):
def __init__(self, vllm_config: VllmConfig):
self._reset(time.monotonic())
self.vllm_config = vllm_config

def _reset(self, now):
self.last_log_time = now
Expand All @@ -42,9 +41,10 @@ def _reset(self, now):
self.prefix_caching_metrics = PrefixCachingMetrics()

def _local_interval_elapsed(self, now: float) -> bool:
# Log every _LOCAL_LOGGING_INTERVAL_SEC.
# Log every configured log_stats_interval level
elapsed_time = now - self.last_log_time
return elapsed_time > _LOCAL_LOGGING_INTERVAL_SEC
interval = self.vllm_config.observability_config.log_stats_interval
return elapsed_time > interval

def _track_iteration_stats(self, iteration_stats: IterationStats):
# Save tracked stats for token counters.
Expand Down

0 comments on commit 87df0fa

Please sign in to comment.