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

4
5
import pytest

6
from vllm.core.scheduler import Scheduler
7
8
9
from vllm.engine.arg_utils import EngineArgs
from vllm.engine.llm_engine import LLMEngine
from vllm.sampling_params import SamplingParams
10
from vllm.v1.core.sched.scheduler import Scheduler as V1Scheduler
11
from vllm.v1.engine.llm_engine import LLMEngine as V1LLMEngine
12
13


14
class DummyV0Scheduler(Scheduler):
15
16

    def schedule(self):
17
18
        raise Exception("Exception raised by DummyV0Scheduler")

19

20
class DummyV1Scheduler(V1Scheduler):
21

22
23
    def schedule(self):
        raise Exception("Exception raised by DummyV1Scheduler")
24
25


26
27
28
29
def test_scheduler_plugins_v0(monkeypatch: pytest.MonkeyPatch):
    with monkeypatch.context() as m:
        m.setenv("VLLM_USE_V1", "0")
        with pytest.raises(Exception) as exception_info:
30

31
32
33
34
35
            engine_args = EngineArgs(
                model="facebook/opt-125m",
                enforce_eager=True,  # reduce test time
                scheduler_cls=DummyV0Scheduler,
            )
36

37
            engine = LLMEngine.from_engine_args(engine_args=engine_args)
38

39
40
41
            sampling_params = SamplingParams(max_tokens=1)
            engine.add_request("0", "foo", sampling_params)
            engine.step()
42

43
44
        assert str(
            exception_info.value) == "Exception raised by DummyV0Scheduler"
45
46


47
48
49
50
51
52
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")
53

54
        with pytest.raises(Exception) as exception_info:
55

56
57
58
59
60
            engine_args = EngineArgs(
                model="facebook/opt-125m",
                enforce_eager=True,  # reduce test time
                scheduler_cls=DummyV1Scheduler,
            )
61

62
            engine = V1LLMEngine.from_engine_args(engine_args=engine_args)
63

64
65
66
            sampling_params = SamplingParams(max_tokens=1)
            engine.add_request("0", "foo", sampling_params)
            engine.step()
67

68
69
        assert str(
            exception_info.value) == "Exception raised by DummyV1Scheduler"