| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """Make sure ignore_eos works. |
| 4 | |
| 5 | Run `pytest tests/samplers/test_ignore_eos.py`. |
| 6 | """ |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from vllm import SamplingParams |
| 11 | |
| 12 | # We also test with llama because it has generation_config to specify EOS |
| 13 | # (past regression). |
| 14 | MODELS = ["distilbert/distilgpt2", "meta-llama/Llama-3.2-1B"] |
| 15 | |
| 16 | |
| 17 | @pytest.mark.parametrize("model", MODELS) |
| 18 | @pytest.mark.parametrize("dtype", ["half"]) |
| 19 | @pytest.mark.parametrize("max_tokens", [512]) |
| 20 | def test_ignore_eos( |
| 21 | vllm_runner, |
| 22 | example_prompts, |
| 23 | model: str, |
| 24 | dtype: str, |
| 25 | max_tokens: int, |
| 26 | ) -> None: |
| 27 | with vllm_runner(model, dtype=dtype) as vllm_model: |
| 28 | sampling_params = SamplingParams(max_tokens=max_tokens, ignore_eos=True) |
| 29 | |
| 30 | for prompt in example_prompts: |
| 31 | ignore_eos_output = vllm_model.llm.generate( |
| 32 | prompt, sampling_params=sampling_params |
| 33 | ) |
| 34 | output_length = len(ignore_eos_output[0].outputs[0].token_ids) |
| 35 | assert output_length == max_tokens |