test_prompt_validation.py 972 Bytes
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0

3
import pytest
4
import os
5
6

from vllm import LLM
7
from ...utils import models_path_prefix
8
from vllm.config import LoadFormat
9
10


Joe Runde's avatar
Joe Runde committed
11
12
13
14
15
16
17
18
@pytest.fixture(autouse=True)
def v1(run_with_both_engines):
    # Simple autouse wrapper to run both engines for each test
    # This can be promoted up to conftest.py to run for every
    # test in a package
    pass


19
def test_empty_prompt():
zhuwenwen's avatar
zhuwenwen committed
20
    llm = LLM(model=os.path.join(models_path_prefix, "gpt2"), 
21
22
              load_format=LoadFormat.RUNAI_STREAMER,
              enforce_eager=True)
23
24
    with pytest.raises(ValueError, match='Prompt cannot be empty'):
        llm.generate([""])
25
26


Joe Runde's avatar
Joe Runde committed
27
@pytest.mark.skip_v1
28
def test_out_of_vocab_token():
zhuwenwen's avatar
zhuwenwen committed
29
    llm = LLM(model=os.path.join(models_path_prefix, "gpt2"),
30
31
              load_format=LoadFormat.RUNAI_STREAMER,
              enforce_eager=True)
32
33
    with pytest.raises(ValueError, match='out of vocabulary'):
        llm.generate({"prompt_token_ids": [999999]})