test_ignore_eos.py 1.32 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
"""Make sure ignore_eos works.

Run `pytest tests/samplers/test_ignore_eos.py`.
"""

import pytest
9
import os
10
11

from vllm import SamplingParams
12
from ..utils import models_path_prefix
13

14
15
16
17
18
19
20

@pytest.fixture(autouse=True)
def v1(run_with_both_engines):
    """We can run both engines for this test."""
    pass


Simon Mo's avatar
Simon Mo committed
21
22
# We also test with llama because it has generation_config to specify EOS
# (past regression).
zhuwenwen's avatar
zhuwenwen committed
23
MODELS = [os.path.join(models_path_prefix, "distilbert/distilgpt2"), os.path.join(models_path_prefix, "meta-llama/Llama-3.2-1B")]
24
25
26
27


@pytest.mark.parametrize("model", MODELS)
@pytest.mark.parametrize("dtype", ["half"])
Simon Mo's avatar
Simon Mo committed
28
29
@pytest.mark.parametrize("max_tokens", [512])
def test_ignore_eos(
30
31
32
33
34
35
    vllm_runner,
    example_prompts,
    model: str,
    dtype: str,
    max_tokens: int,
) -> None:
36
37
38
    with vllm_runner(model, dtype=dtype) as vllm_model:
        sampling_params = SamplingParams(max_tokens=max_tokens,
                                         ignore_eos=True)
Simon Mo's avatar
Simon Mo committed
39

40
41
42
43
44
        for prompt in example_prompts:
            ignore_eos_output = vllm_model.model.generate(
                prompt, sampling_params=sampling_params)
            output_length = len(ignore_eos_output[0].outputs[0].token_ids)
            assert output_length == max_tokens