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

4
import pytest
5
import os
6
import torch
7
8

from vllm import LLM
9
from ...utils import models_path_prefix
10
11
12


def test_empty_prompt():
zhuwenwen's avatar
zhuwenwen committed
13
    llm = LLM(model=os.path.join(models_path_prefix, "openai-community/gpt2"), enforce_eager=True)
14
    with pytest.raises(ValueError, match="decoder prompt cannot be empty"):
15
        llm.generate([""])
16
17
18


def test_out_of_vocab_token():
zhuwenwen's avatar
zhuwenwen committed
19
    llm = LLM(model=os.path.join(models_path_prefix, "openai-community/gpt2"), enforce_eager=True)
20
    with pytest.raises(ValueError, match="out of vocabulary"):
21
        llm.generate({"prompt_token_ids": [999999]})
22
23
24
25


def test_require_mm_embeds():
    llm = LLM(
26
        model=os.path.join(models_path_prefix, "llava-hf/llava-1.5-7b-hf"),
27
28
29
30
31
32
33
34
35
36
        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)},
            }
        )