test_scheduler_plugins.py 1.29 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
5
6
7
import pytest

from vllm.engine.arg_utils import EngineArgs
from vllm.sampling_params import SamplingParams
8
9
from vllm.v1.core.sched.scheduler import Scheduler
from vllm.v1.engine.llm_engine import LLMEngine
10
11


12
class DummyV1Scheduler(Scheduler):
13

14
15
    def schedule(self):
        raise Exception("Exception raised by DummyV1Scheduler")
16
17


18
19
20
21
22
23
def test_scheduler_plugins_v1(monkeypatch: pytest.MonkeyPatch):
    with monkeypatch.context() as m:
        m.setenv("VLLM_USE_V1", "1")
        # Explicitly turn off engine multiprocessing so
        # that the scheduler runs in this process
        m.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "0")
24

25
        with pytest.raises(Exception) as exception_info:
26

27
28
29
30
31
            engine_args = EngineArgs(
                model="facebook/opt-125m",
                enforce_eager=True,  # reduce test time
                scheduler_cls=DummyV1Scheduler,
            )
32

33
            engine = LLMEngine.from_engine_args(engine_args=engine_args)
34

35
36
37
            sampling_params = SamplingParams(max_tokens=1)
            engine.add_request("0", "foo", sampling_params)
            engine.step()
38

39
40
        assert str(
            exception_info.value) == "Exception raised by DummyV1Scheduler"