[Misc][DP] support customized aggregated logger for dp (#24354)
Signed-off-by: Lu Fang <fanglu@fb.com>
This commit is contained in:
@@ -17,7 +17,12 @@ from vllm.platforms import current_platform
|
||||
from vllm.sampling_params import RequestOutputKind
|
||||
from vllm.utils import set_default_torch_num_threads
|
||||
from vllm.v1.engine.async_llm import AsyncLLM
|
||||
from vllm.v1.metrics.loggers import LoggingStatLogger
|
||||
from vllm.v1.metrics.loggers import (
|
||||
AggregatedLoggingStatLogger,
|
||||
LoggingStatLogger,
|
||||
PerEngineStatLoggerAdapter,
|
||||
PrometheusStatLogger,
|
||||
)
|
||||
|
||||
if not current_platform.is_cuda():
|
||||
pytest.skip(reason="V1 currently only supported on CUDA.", allow_module_level=True)
|
||||
@@ -384,6 +389,12 @@ class MockLoggingStatLogger(LoggingStatLogger):
|
||||
self.log = MagicMock()
|
||||
|
||||
|
||||
class MockAggregatedStatLogger(AggregatedLoggingStatLogger):
|
||||
def __init__(self, vllm_config: VllmConfig, engine_indexes: list[int]):
|
||||
super().__init__(vllm_config, engine_indexes)
|
||||
self.log = MagicMock()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_customize_loggers(monkeypatch):
|
||||
"""Test that we can customize the loggers.
|
||||
@@ -401,10 +412,45 @@ async def test_customize_loggers(monkeypatch):
|
||||
|
||||
await engine.do_log_stats()
|
||||
|
||||
stat_loggers = engine.logger_manager.per_engine_logger_dict
|
||||
assert len(stat_loggers) == 1
|
||||
assert len(stat_loggers[0]) == 2 # LoggingStatLogger + MockLoggingStatLogger
|
||||
stat_loggers[0][0].log.assert_called_once()
|
||||
stat_loggers = engine.logger_manager.stat_loggers
|
||||
assert (
|
||||
len(stat_loggers) == 3
|
||||
) # MockLoggingStatLogger + LoggingStatLogger + Promethus Logger
|
||||
print(f"{stat_loggers=}")
|
||||
stat_loggers[0].per_engine_stat_loggers[0].log.assert_called_once()
|
||||
assert isinstance(stat_loggers[1], PerEngineStatLoggerAdapter)
|
||||
assert isinstance(stat_loggers[1].per_engine_stat_loggers[0], LoggingStatLogger)
|
||||
assert isinstance(stat_loggers[2], PrometheusStatLogger)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_customize_aggregated_loggers(monkeypatch):
|
||||
"""Test that we can customize the aggregated loggers.
|
||||
If a customized logger is provided at the init, it should
|
||||
be added to the default loggers.
|
||||
"""
|
||||
|
||||
with monkeypatch.context() as m, ExitStack() as after:
|
||||
m.setenv("VLLM_USE_V1", "1")
|
||||
|
||||
with set_default_torch_num_threads(1):
|
||||
engine = AsyncLLM.from_engine_args(
|
||||
TEXT_ENGINE_ARGS,
|
||||
stat_loggers=[MockLoggingStatLogger, MockAggregatedStatLogger],
|
||||
)
|
||||
after.callback(engine.shutdown)
|
||||
|
||||
await engine.do_log_stats()
|
||||
|
||||
stat_loggers = engine.logger_manager.stat_loggers
|
||||
assert len(stat_loggers) == 4
|
||||
# MockLoggingStatLogger + MockAggregatedStatLogger
|
||||
# + LoggingStatLogger + PrometheusStatLogger
|
||||
stat_loggers[0].per_engine_stat_loggers[0].log.assert_called_once()
|
||||
stat_loggers[1].log.assert_called_once()
|
||||
assert isinstance(stat_loggers[2], PerEngineStatLoggerAdapter)
|
||||
assert isinstance(stat_loggers[2].per_engine_stat_loggers[0], LoggingStatLogger)
|
||||
assert isinstance(stat_loggers[3], PrometheusStatLogger)
|
||||
|
||||
|
||||
@pytest.mark.asyncio(scope="module")
|
||||
|
||||
Reference in New Issue
Block a user