vllm

Форк
0
/
test_mixtral.py 
53 строки · 4.5 Кб
1
import pytest
2
import torch
3

4
import vllm
5
from vllm.lora.request import LoRARequest
6

7
MODEL_PATH = "mistralai/Mixtral-8x7B-Instruct-v0.1"
8

9

10
def do_sample(llm, lora_path: str, lora_id: int):
11
    prompts = [
12
        "[system] Given a target sentence construct the underlying meaning representation\nof the input sentence as a single function with attributes and attribute\nvalues. This function should describe the target string accurately and the\nfunction must be one of the following ['inform', 'request', 'give_opinion',\n'confirm', 'verify_attribute', 'suggest', 'request_explanation',\n'recommend', 'request_attribute'].\n\nThe attributes must be one of the following:\n['name', 'exp_release_date', 'release_year', 'developer', 'esrb', 'rating',\n'genres', 'player_perspective', 'has_multiplayer', 'platforms',\n'available_on_steam', 'has_linux_release', 'has_mac_release', 'specifier'] [/system] [user] Here is the target sentence:\nSpellForce 3 is a pretty bad game. The developer Grimlore Games is clearly a bunch of no-talent hacks, and 2017 was a terrible year for games anyway. [/user] [assistant]",
13
        "[system] Given a target sentence construct the underlying meaning representation\nof the input sentence as a single function with attributes and attribute\nvalues. This function should describe the target string accurately and the\nfunction must be one of the following ['inform', 'request', 'give_opinion',\n'confirm', 'verify_attribute', 'suggest', 'request_explanation',\n'recommend', 'request_attribute'].\n\nThe attributes must be one of the following:\n['name', 'exp_release_date', 'release_year', 'developer', 'esrb', 'rating',\n'genres', 'player_perspective', 'has_multiplayer', 'platforms',\n'available_on_steam', 'has_linux_release', 'has_mac_release', 'specifier'] [/system] [user] Here is the target sentence:\nI wanted to like Grimlore Games' 2017 entry, but in SpellForce 3 they just didn't get anything right. [/user] [assistant]",
14
        "[system] Given a target sentence construct the underlying meaning representation\nof the input sentence as a single function with attributes and attribute\nvalues. This function should describe the target string accurately and the\nfunction must be one of the following ['inform', 'request', 'give_opinion',\n'confirm', 'verify_attribute', 'suggest', 'request_explanation',\n'recommend', 'request_attribute'].\n\nThe attributes must be one of the following:\n['name', 'exp_release_date', 'release_year', 'developer', 'esrb', 'rating',\n'genres', 'player_perspective', 'has_multiplayer', 'platforms',\n'available_on_steam', 'has_linux_release', 'has_mac_release', 'specifier'] [/system] [user] Here is the target sentence:\nBioShock is a good role-playing, action-adventure, shooter that released for PlayStation, Xbox, and PC in 2007. It is available on Steam, and it has a Mac release but not a Linux release. [/user] [assistant]",
15
    ]
16
    sampling_params = vllm.SamplingParams(temperature=0, max_tokens=256)
17
    outputs = llm.generate(
18
        prompts,
19
        sampling_params,
20
        lora_request=LoRARequest(str(lora_id), lora_id, lora_path)
21
        if lora_id else None)
22
    # Print the outputs.
23
    generated_texts = []
24
    for output in outputs:
25
        prompt = output.prompt
26
        generated_text = output.outputs[0].text.strip()
27
        generated_texts.append(generated_text)
28
        print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
29
    return generated_texts
30

31

32
@pytest.mark.parametrize("tp_size", [4])
33
def test_mixtral_lora(mixtral_lora_files, tp_size):
34
    if torch.cuda.device_count() < tp_size:
35
        pytest.skip(f"Not enough GPUs for tensor parallelism {tp_size}")
36

37
    llm = vllm.LLM(MODEL_PATH,
38
                   enable_lora=True,
39
                   max_num_seqs=16,
40
                   max_loras=4,
41
                   tensor_parallel_size=tp_size,
42
                   worker_use_ray=True)
43

44
    expected_lora_output = [
45
        "give_opinion(name[SpellForce 3], release_year[2017], developer[Grimlore Games], rating[poor])",
46
        "give_opinion(name[SpellForce 3], release_year[2017], developer[Grimlore Games], rating[poor])",
47
        "inform(name[BioShock], release_year[2007], rating[good], genres[action-adventure, role-playing, shooter], platforms[PlayStation, Xbox, PC], available_on_steam[yes], has_linux_release[no], has_mac_release[yes])",
48
    ]
49

50
    assert do_sample(llm, mixtral_lora_files,
51
                     lora_id=1) == expected_lora_output
52
    assert do_sample(llm, mixtral_lora_files,
53
                     lora_id=2) == expected_lora_output
54

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.