test_max_len.py 2.04 KB
Newer Older
1
2
3
# SPDX-License-Identifier: Apache-2.0
"""Test whether spec decoding handles the max model length properly."""

zhuwenwen's avatar
zhuwenwen committed
4
import os
5
6
7
import pytest

from vllm import LLM, SamplingParams
zhuwenwen's avatar
zhuwenwen committed
8
from ...utils import models_path_prefix
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

_PROMPTS = [
    "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
    "Repeat the following sentence 10 times: Consistency is key to mastering any skill.",  # noqa: E501
    "Who won the Turing Award in 2018, and for what contribution? Describe in detail.",  # noqa: E501
]


@pytest.mark.parametrize("num_speculative_tokens", [1, 3, 10])
def test_ngram_max_len(
    monkeypatch: pytest.MonkeyPatch,
    num_speculative_tokens: int,
):
    with monkeypatch.context() as m:
        m.setenv("VLLM_USE_V1", "1")

        llm = LLM(
zhuwenwen's avatar
zhuwenwen committed
26
            model=os.path.join(models_path_prefix, "facebook/opt-125m"),
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
            max_model_len=100,
            enforce_eager=True,  # For faster initialization.
            speculative_config={
                "method": "ngram",
                "prompt_lookup_max": 5,
                "prompt_lookup_min": 3,
                "num_speculative_tokens": num_speculative_tokens,
            },
        )
        sampling_params = SamplingParams(max_tokens=100, ignore_eos=True)
        llm.generate(_PROMPTS, sampling_params)


@pytest.mark.parametrize("num_speculative_tokens", [1, 3, 10])
def test_eagle_max_len(
    monkeypatch: pytest.MonkeyPatch,
    num_speculative_tokens: int,
):
    with monkeypatch.context() as m:
        m.setenv("VLLM_USE_V1", "1")

        llm = LLM(
zhuwenwen's avatar
zhuwenwen committed
49
            model=os.path.join(models_path_prefix, "meta-llama/Meta-Llama-3-8B-Instruct"),
50
51
52
            enforce_eager=True,  # For faster initialization.
            speculative_config={
                "method": "eagle",
zhuwenwen's avatar
zhuwenwen committed
53
                "model": os.path.join(models_path_prefix, "yuhuili/EAGLE-LLaMA3-Instruct-8B"),
54
55
56
57
58
59
                "num_speculative_tokens": num_speculative_tokens,
            },
            max_model_len=100,
        )
        sampling_params = SamplingParams(max_tokens=100, ignore_eos=True)
        llm.generate(_PROMPTS, sampling_params)