test_engine_logger_apis.py 2.13 KB
Newer Older
1
2
3
4
5
6
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import copy

import pytest

7
8
9
from tests.plugins.vllm_add_dummy_stat_logger.dummy_stat_logger.dummy_stat_logger import (  # noqa E501
    DummyStatLogger,
)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from vllm.v1.engine.async_llm import AsyncEngineArgs, AsyncLLM
from vllm.v1.metrics.ray_wrappers import RayPrometheusStatLogger


@pytest.fixture
def log_stats_enabled_engine_args():
    """
    Shared fixture providing common AsyncEngineArgs configuration
    used across multiple tests.
    """
    return AsyncEngineArgs(
        model="distilbert/distilgpt2",
        dtype="half",
        disable_log_stats=False,
        enforce_eager=True,
    )


@pytest.mark.asyncio
29
async def test_async_llm_replace_default_loggers(log_stats_enabled_engine_args):
30
31
32
33
    """
    RayPrometheusStatLogger should replace the default PrometheusStatLogger
    """

34
35
36
    engine = AsyncLLM.from_engine_args(
        log_stats_enabled_engine_args, stat_loggers=[RayPrometheusStatLogger]
    )
37
    assert isinstance(engine.logger_manager.stat_loggers[0], RayPrometheusStatLogger)
38
39
40
41
42
43
    engine.shutdown()


@pytest.mark.asyncio
async def test_async_llm_add_to_default_loggers(log_stats_enabled_engine_args):
    """
44
    It's still possible to use custom stat loggers exclusively by passing
45
46
47
48
49
50
51
    disable_log_stats=True in addition to a list of custom stat loggers.
    """
    # Create engine_args with disable_log_stats=True for this test
    disabled_log_engine_args = copy.deepcopy(log_stats_enabled_engine_args)
    disabled_log_engine_args.disable_log_stats = True

    # Disable default loggers; pass custom stat logger to the constructor
52
53
54
    engine = AsyncLLM.from_engine_args(
        disabled_log_engine_args, stat_loggers=[DummyStatLogger]
    )
55

56
57
    assert len(engine.logger_manager.stat_loggers) == 2
    assert len(engine.logger_manager.stat_loggers[0].per_engine_stat_loggers) == 1
58
    assert isinstance(
59
60
        engine.logger_manager.stat_loggers[0].per_engine_stat_loggers[0],
        DummyStatLogger,
61
    )
62
63
64
65
66

    # log_stats is still True, since custom stat loggers are used
    assert engine.log_stats

    engine.shutdown()