test_whisper.py 6.2 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5

import pytest

6
from vllm import SamplingParams
7
8
from vllm.assets.audio import AudioAsset

9
from ....conftest import VllmRunner
10
from ....utils import create_new_process_for_each_test, multi_gpu_test
11
12
13

PROMPTS = [
    {
14
        "prompt": "<|startoftranscript|><|en|><|transcribe|><|notimestamps|>",
15
16
17
18
19
20
21
22
23
24
25
        "multi_modal_data": {
            "audio": AudioAsset("mary_had_lamb").audio_and_sample_rate,
        },
    },
    {  # Test explicit encoder/decoder prompt
        "encoder_prompt": {
            "prompt": "",
            "multi_modal_data": {
                "audio": AudioAsset("winning_call").audio_and_sample_rate,
            },
        },
26
27
        "decoder_prompt": "<|startoftranscript|><|en|><|transcribe|><|notimestamps|>",
    },
28
29
30
31
32
33
34
35
36
37
38
39
40
]

EXPECTED = {
    "openai/whisper-tiny": [
        " He has birth words I spoke in the original corner of that. And a"
        " little piece of black coat poetry. Mary had a little sandwich,"
        " sweet, with white and snow. And everyone had it very went the last"
        " would sure to go.",
        " >> And the old one, fit John the way to Edgar Martinez. >> One more"
        " to line down the field line for our base camp. Here comes joy. Here"
        " is June and the third base. They're going to wave him in. The throw"
        " to the plate will be late. The Mariners are going to play for the"
        " American League Championship. I don't believe it. It just continues"
41
        " by all five.",
42
43
44
45
46
47
48
49
50
    ],
    "openai/whisper-small": [
        " The first words I spoke in the original pornograph. A little piece"
        " of practical poetry. Mary had a little lamb, its fleece was quite a"
        " slow, and everywhere that Mary went the lamb was sure to go.",
        " And the old one pitch on the way to Edgar Martinez one month. Here"
        " comes joy. Here is Junior to third base. They're gonna wave him"
        " in. The throw to the plate will be late. The Mariners are going to"
        " play for the American League Championship. I don't believe it. It"
51
        " just continues. My, oh my.",
52
53
54
55
56
57
58
59
60
61
    ],
    "openai/whisper-medium": [
        " The first words I spoke in the original phonograph, a little piece"
        " of practical poetry. Mary had a little lamb, its fleece was quite as"
        " slow, and everywhere that Mary went the lamb was sure to go.",
        " And the 0-1 pitch on the way to Edgar Martinez swung on the line"
        " down the left field line for Obeyshev. Here comes Joy. Here is"
        " Jorgen at third base. They're going to wave him in. The throw to the"
        " plate will be late. The Mariners are going to play for the American"
        " League Championship. I don't believe it. It just continues. My, oh"
62
        " my.",
63
64
65
66
67
68
69
70
71
72
    ],
    "openai/whisper-large-v3": [
        " The first words I spoke in the original phonograph, a little piece"
        " of practical poetry. Mary had a little lamb, its feet were quite as"
        " slow, and everywhere that Mary went, the lamb was sure to go.",
        " And the 0-1 pitch on the way to Edgar Martinez. Swung on the line."
        " Now the left field line for a base hit. Here comes Joy. Here is"
        " Junior to third base. They're going to wave him in. The throw to the"
        " plate will be late. The Mariners are going to play for the American"
        " League Championship. I don't believe it. It just continues. My, oh,"
73
        " my.",
74
75
76
77
78
79
80
81
82
83
    ],
    "openai/whisper-large-v3-turbo": [
        " The first words I spoke in the original phonograph, a little piece"
        " of practical poetry. Mary had a little lamb, its streets were quite"
        " as slow, and everywhere that Mary went the lamb was sure to go.",
        " And the 0-1 pitch on the way to Edgar Martinez. Swung on the line"
        " down the left field line for a base hit. Here comes Joy. Here is"
        " Junior to third base. They're going to wave him in. The throw to the"
        " plate will be late. The Mariners are going to play for the American"
        " League Championship. I don't believe it. It just continues. My, oh,"
84
85
        " my.",
    ],
86
87
88
89
}


def run_test(
90
    vllm_runner: type[VllmRunner],
91
92
93
    model: str,
    *,
    tensor_parallel_size: int,
94
    distributed_executor_backend: str | None = None,
95
    dtype: str = "half",
96
97
98
99
) -> None:
    prompt_list = PROMPTS * 10
    expected_list = EXPECTED[model] * 10

100
    with vllm_runner(
101
        model,
102
        dtype=dtype,
103
104
105
        max_model_len=448,
        tensor_parallel_size=tensor_parallel_size,
        distributed_executor_backend=distributed_executor_backend,
106
    ) as vllm_model:
107
        llm = vllm_model.llm
108

109
110
111
112
113
        sampling_params = SamplingParams(
            temperature=0,
            top_p=1.0,
            max_tokens=200,
        )
114

115
        outputs = llm.generate(prompt_list, sampling_params)
116
117
118
119
120
121
122

    for output, expected in zip(outputs, expected_list):
        print(output.outputs[0].text)
        assert output.outputs[0].text == expected


@pytest.mark.core_model
123
@pytest.mark.parametrize("model", ["openai/whisper-large-v3-turbo"])
124
@pytest.mark.parametrize("dtype", ["half"])
125
@create_new_process_for_each_test()
126
def test_models(vllm_runner, model, dtype) -> None:
127
128
129
130
    run_test(
        vllm_runner,
        model,
        tensor_parallel_size=1,
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
        dtype=dtype,
    )


@pytest.mark.cpu_model
@pytest.mark.parametrize("model", ["openai/whisper-large-v3-turbo"])
@pytest.mark.parametrize("dtype", ["half"])
def test_models_cpu(vllm_runner, model, dtype) -> None:
    # @create_new_process_for_each_test() does not work for some runners
    # TODO: to fix cpu privilege issues in run-cpu-test-arm.sh
    run_test(
        vllm_runner,
        model,
        tensor_parallel_size=1,
        dtype=dtype,
146
    )
147
148
149
150
151
152


@multi_gpu_test(num_gpus=2)
@pytest.mark.core_model
@pytest.mark.parametrize("model", ["openai/whisper-large-v3-turbo"])
@pytest.mark.parametrize("distributed_executor_backend", ["ray", "mp"])
153
@create_new_process_for_each_test()
154
155
156
157
158
159
160
161
162
163
164
def test_models_distributed(
    vllm_runner,
    model,
    distributed_executor_backend,
) -> None:
    run_test(
        vllm_runner,
        model,
        tensor_parallel_size=2,
        distributed_executor_backend=distributed_executor_backend,
    )