main
py 31 lines 1.24 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import pytest
5
6 from vllm.entrypoints.llm import LLM
7 from vllm.sampling_params import SamplingParams
8
9
10 @pytest.mark.parametrize("model", ["distilbert/distilgpt2"])
11 def test_computed_prefix_blocks(model: str):
12 # This test checks if the engine generates completions both with and
13 # without optional detokenization, that detokenization includes text
14 # and no-detokenization doesn't, and that both completions have the same
15 # token_ids.
16 prompt = (
17 "You are a helpful assistant. How do I build a car from cardboard and "
18 "paper clips? Is there an easy to follow video tutorial available "
19 "online for free?"
20 )
21
22 llm = LLM(model=model)
23 sampling_params = SamplingParams(max_tokens=10, temperature=0.0, detokenize=False)
24
25 outputs_no_detokenization = llm.generate(prompt, sampling_params)[0].outputs[0]
26 sampling_params.detokenize = True
27 outputs_with_detokenization = llm.generate(prompt, sampling_params)[0].outputs[0]
28
29 assert outputs_no_detokenization.text == ""
30 assert outputs_with_detokenization.text != ""
31 assert outputs_no_detokenization.token_ids == outputs_with_detokenization.token_ids