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

3
4
import pytest

5
from vllm.config import LoadFormat
6
7
8
from vllm.entrypoints.llm import LLM
from vllm.sampling_params import SamplingParams

9
from ..conftest import MODEL_WEIGHTS_S3_BUCKET
10

11

12
13
@pytest.mark.parametrize("model",
                         [f"{MODEL_WEIGHTS_S3_BUCKET}/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,
              load_format=LoadFormat.RUNAI_STREAMER)
21
    sampling_params = SamplingParams(prompt_logprobs=True, detokenize=True)
22
23

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

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