main
py 68 lines 2.22 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 import pytest
4
5 from vllm.exceptions import VLLMValidationError
6
7 MODEL_NAME = "sentence-transformers/all-MiniLM-L12-v2"
8 max_model_len = 128
9
10 input_str = """Immerse yourself in the enchanting chronicle of calculus, a
11 mathematical domain that has radically transformed our comprehension of
12 change and motion. Despite its roots in ancient civilizations, the
13 formal birth of calculus predominantly occurred in the 17th century,
14 primarily under the influential guidance of Sir Isaac Newton and Gottfried
15 Wilhelm Leibniz. The earliest traces of calculus concepts are found in
16 ancient Greek mathematics,most notably in the works of Eudoxus and
17 Archimedes, around 300 BCE. They utilized the 'method of exhaustion'—a
18 technique for computing areas and volumes through the use of finite sums.
19 This methodology laid crucial foundational work for integral calculus.
20 In the 17th century, both Newton and Leibniz independently pioneered
21 calculus, each contributing unique perspectives that would shape this new
22 field."""
23
24
25 @pytest.fixture(scope="module")
26 def vllm_model(vllm_runner):
27 with vllm_runner(
28 MODEL_NAME, runner="pooling", max_model_len=max_model_len
29 ) as model:
30 yield model
31
32
33 def test_smaller_truncation_size(
34 vllm_model,
35 ):
36 truncate_prompt_tokens = 10
37
38 vllm_output = vllm_model.llm.embed(
39 input_str,
40 tokenization_kwargs=dict(truncate_prompt_tokens=truncate_prompt_tokens),
41 )
42
43 prompt_tokens = vllm_output[0].prompt_token_ids
44
45 assert len(prompt_tokens) == truncate_prompt_tokens
46
47
48 def test_max_truncation_size(vllm_model):
49 truncate_prompt_tokens = -1
50
51 vllm_output = vllm_model.llm.embed(
52 input_str,
53 tokenization_kwargs=dict(truncate_prompt_tokens=truncate_prompt_tokens),
54 )
55
56 prompt_tokens = vllm_output[0].prompt_token_ids
57
58 assert len(prompt_tokens) == max_model_len
59
60
61 def test_bigger_truncation_size(vllm_model):
62 truncate_prompt_tokens = max_model_len + 1
63
64 with pytest.raises(VLLMValidationError):
65 vllm_model.llm.embed(
66 input_str,
67 tokenization_kwargs=dict(truncate_prompt_tokens=truncate_prompt_tokens),
68 )