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

4
import os
5
6
7
8
import pytest

from vllm.entrypoints.llm import LLM
from vllm.sampling_params import SamplingParams
9
from ..utils import models_path_prefix
10
from vllm.platforms import current_platform
11
12


13
@pytest.mark.skip_v1
14
@pytest.mark.parametrize("model", [os.path.join(models_path_prefix, "distilbert/distilgpt2")])
15
16
17
18
19
20
21
22
def test_computed_prefix_blocks(model: str):
    # This test checks if the engine generates completions both with and
    # without optional detokenization, that detokenization includes text
    # and no-detokenization doesn't, and that both completions have the same
    # token_ids.
    prompt = (
        "You are a helpful assistant. How do I build a car from cardboard and "
        "paper clips? Is there an easy to follow video tutorial available "
23
24
        "online for free?"
    )
25

26
    llm = LLM(model=model, block_size=64 if current_platform.is_rocm() else 16)
27
    sampling_params = SamplingParams(max_tokens=10, temperature=0.0, detokenize=False)
28

29
    outputs_no_detokenization = llm.generate(prompt, sampling_params)[0].outputs[0]
30
    sampling_params.detokenize = True
31
    outputs_with_detokenization = llm.generate(prompt, sampling_params)[0].outputs[0]
32

33
34
35
    assert outputs_no_detokenization.text == ""
    assert outputs_with_detokenization.text != ""
    assert outputs_no_detokenization.token_ids == outputs_with_detokenization.token_ids