test_disable_sliding_window.py 1.71 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5
6
7
8
9
"""Compare the with and without prefix caching.

Run `pytest tests/prefix_caching/test_prefix_caching.py`.
"""
import pytest

from vllm import LLM
10
from vllm.distributed import cleanup_dist_env_and_memory
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

MODEL_LEN_LEN = [
    # Example models with sliding window.
    ("bigcode/starcoder2-3b", 4096, 16384),
    # ("mistralai/Mistral-7B-v0.1", 4096, 32768), << OOM in CI

    # Confirm model with sliding window works.
    # config has "use_sliding_window": false
    ("Qwen/Qwen1.5-0.5B-Chat", 32768, 32768),
    # config has no sliding window attribute.
    ("TinyLlama/TinyLlama-1.1B-Chat-v1.0", 2048, 2048),
]


@pytest.mark.parametrize("model_len_len", MODEL_LEN_LEN)
def test_disable_sliding_window(model_len_len, ):
    model, sliding_len, full_len = model_len_len
28
29
30
    disabled_llm = LLM(model, disable_sliding_window=True)
    disabled_llm.generate("Hi my name is")
    model_config = disabled_llm.llm_engine.model_config
31
32
33
34
    assert model_config.max_model_len == sliding_len, (
        "Max len expected to equal sliding_len of %s, but got %s", sliding_len,
        model_config.max_model_len)

35
    del disabled_llm
36
    cleanup_dist_env_and_memory()
37

38
39
40
41
42
43
    enabled_llm = LLM(model,
                      enforce_eager=True,
                      disable_sliding_window=False,
                      enable_prefix_caching=False)
    enabled_llm.generate("Hi my name is")
    model_config = enabled_llm.llm_engine.model_config
44
45
46
47
    assert model_config.max_model_len == full_len, (
        "Max len expected to equal full_len of %s, but got %s", full_len,
        model_config.max_model_len)

48
    del enabled_llm
49
    cleanup_dist_env_and_memory()