|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | + |
| 4 | +import pytest |
| 5 | +from dummy_stat_logger.dummy_stat_logger import DummyStatLogger |
| 6 | + |
| 7 | +from vllm.config import VllmConfig |
| 8 | +from vllm.engine.arg_utils import AsyncEngineArgs |
| 9 | +from vllm.v1.engine.async_llm import AsyncLLM |
| 10 | +from vllm.v1.metrics.loggers import load_stat_logger_plugin_factories |
| 11 | + |
| 12 | + |
| 13 | +def test_stat_logger_plugin_is_discovered(monkeypatch: pytest.MonkeyPatch): |
| 14 | + with monkeypatch.context() as m: |
| 15 | + m.setenv("VLLM_PLUGINS", "dummy_stat_logger") |
| 16 | + |
| 17 | + factories = load_stat_logger_plugin_factories() |
| 18 | + assert len(factories) == 1, f"Expected 1 factory, got {len(factories)}" |
| 19 | + assert factories[0] is DummyStatLogger, ( |
| 20 | + f"Expected DummyStatLogger class, got {factories[0]}" |
| 21 | + ) |
| 22 | + |
| 23 | + # instantiate and confirm the right type |
| 24 | + vllm_config = VllmConfig() |
| 25 | + instance = factories[0](vllm_config) |
| 26 | + assert isinstance(instance, DummyStatLogger) |
| 27 | + |
| 28 | + |
| 29 | +def test_no_plugins_loaded_if_env_empty(monkeypatch: pytest.MonkeyPatch): |
| 30 | + with monkeypatch.context() as m: |
| 31 | + m.setenv("VLLM_PLUGINS", "") |
| 32 | + |
| 33 | + factories = load_stat_logger_plugin_factories() |
| 34 | + assert factories == [] |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.asyncio |
| 38 | +async def test_stat_logger_plugin_integration_with_engine( |
| 39 | + monkeypatch: pytest.MonkeyPatch, |
| 40 | +): |
| 41 | + with monkeypatch.context() as m: |
| 42 | + m.setenv("VLLM_PLUGINS", "dummy_stat_logger") |
| 43 | + |
| 44 | + engine_args = AsyncEngineArgs( |
| 45 | + model="facebook/opt-125m", |
| 46 | + enforce_eager=True, # reduce test time |
| 47 | + disable_log_stats=True, # disable default loggers |
| 48 | + ) |
| 49 | + |
| 50 | + engine = AsyncLLM.from_engine_args(engine_args=engine_args) |
| 51 | + |
| 52 | + assert len(engine.logger_manager.stat_loggers) == 2 |
| 53 | + assert len(engine.logger_manager.stat_loggers[0].per_engine_stat_loggers) == 1 |
| 54 | + assert isinstance( |
| 55 | + engine.logger_manager.stat_loggers[0].per_engine_stat_loggers[0], |
| 56 | + DummyStatLogger, |
| 57 | + ) |
| 58 | + |
| 59 | + engine.shutdown() |
0 commit comments