Skip to content

Add add_logger API to AsyncLLM #20952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/v1/metrics/test_engine_logger_apis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest

from vllm.v1.engine.async_llm import AsyncEngineArgs, AsyncLLM
from vllm.v1.metrics.loggers import PrometheusStatLogger


@pytest.mark.asyncio
async def test_async_llm_add_logger():
# Minimal model config for test
model_name = "distilbert/distilgpt2"
dtype = "half"
engine_args = AsyncEngineArgs(
model=model_name,
dtype=dtype,
disable_log_stats=False,
enforce_eager=True,
)

# Force empty list to avoid default loggers
engine = AsyncLLM.from_engine_args(engine_args, stat_loggers=[])

# Add PrometheusStatLogger and verify no exception is raised
await engine.add_logger(PrometheusStatLogger)

# Verify that logger is present in the first DP rank
assert len(engine.stat_loggers[0]) == 1
assert isinstance(engine.stat_loggers[0][0], PrometheusStatLogger)
13 changes: 13 additions & 0 deletions vllm/v1/engine/async_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,19 @@ async def collective_rpc(self,
return await self.engine_core.collective_rpc_async(
method, timeout, args, kwargs)

async def add_logger(self, logger_factory: StatLoggerFactory) -> None:
if not self.log_stats:
raise RuntimeError(
"Stat logging is disabled. Set `disable_log_stats=False` "
"argument to enable.")

engine_num = self.vllm_config.parallel_config.data_parallel_size
if len(self.stat_loggers) == 0:
self.stat_loggers = [[] for _ in range(engine_num)]

for i, logger_list in enumerate(self.stat_loggers):
logger_list.append(logger_factory(self.vllm_config, i))

@property
def is_running(self) -> bool:
# Is None before the loop is started.
Expand Down