test_skip_tokenizer_init.py 1.21 KB
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0

3
import os
4
5
6
7
import pytest

from vllm.entrypoints.llm import LLM
from vllm.sampling_params import SamplingParams
8
9
10
from ..utils import models_path_prefix
from vllm.utils import SUPPORT_TC, gpuname
import vllm.envs as envs
11
12


13
@pytest.mark.parametrize("model", [os.path.join(models_path_prefix, "distilbert/distilgpt2")])
14
15
16
17
def test_skip_tokenizer_initialization(model: str):
    # This test checks if the flag skip_tokenizer_init skips the initialization
    # of tokenizer and detokenizer. The generated output is expected to contain
    # token ids.
18
19
20
    llm = LLM(
        model=model,
        skip_tokenizer_init=True,
21
        block_size=64 if gpuname.startswith('BW') and envs.VLLM_FLASH_ATTN_BACKEND else 16,
22
    )
23
    sampling_params = SamplingParams(prompt_logprobs=True, detokenize=True)
24
25

    with pytest.raises(ValueError, match="cannot pass text prompts when"):
26
        llm.generate("abc", sampling_params)
27

28
    outputs = llm.generate({"prompt_token_ids": [1, 2, 3]},
29
30
31
32
33
                           sampling_params=sampling_params)
    assert len(outputs) > 0
    completions = outputs[0].outputs
    assert len(completions) > 0
    assert completions[0].text == ""
34
    assert completions[0].token_ids