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 1 commit
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
4 changes: 2 additions & 2 deletions tests/v1/metrics/test_ray_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ async def run(self):
disable_log_stats=False,
)

engine = AsyncLLM.from_engine_args(
engine_args, stat_loggers=[RayPrometheusStatLogger])
engine = AsyncLLM.from_engine_args(engine_args)
await engine.add_logger(RayPrometheusStatLogger)

for i, prompt in enumerate(example_prompts):
results = engine.generate(
Expand Down
19 changes: 19 additions & 0 deletions vllm/v1/engine/async_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,25 @@ 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)]

logger_type = type(logger_factory)
for logger in self.stat_loggers[0]:
if type(logger) is logger_type:
raise KeyError(
f"Logger with type {logger_type} already exists.")

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