test_prompt_validation.py 951 Bytes
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
import pytest
5
import torch
6
7
8
9
10

from vllm import LLM


def test_empty_prompt():
11
    llm = LLM(model="openai-community/gpt2", enforce_eager=True)
12
    with pytest.raises(ValueError, match="decoder prompt cannot be empty"):
13
        llm.generate([""])
14
15
16


def test_out_of_vocab_token():
17
    llm = LLM(model="openai-community/gpt2", enforce_eager=True)
18
    with pytest.raises(ValueError, match="out of vocabulary"):
19
        llm.generate({"prompt_token_ids": [999999]})
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34


def test_require_mm_embeds():
    llm = LLM(
        model="llava-hf/llava-1.5-7b-hf",
        enforce_eager=True,
        enable_mm_embeds=False,
    )
    with pytest.raises(ValueError, match="--enable-mm-embeds"):
        llm.generate(
            {
                "prompt": "<image>",
                "multi_modal_data": {"image": torch.empty(1, 1, 1)},
            }
        )