test_integration.py 5.74 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5
6
7
8
"""Tests which cover integration of the speculative decoding framework with
other features, e.g. cuda graphs.
"""

import pytest

9
10
11
from .conftest import run_equality_correctness_test

MAIN_MODEL = "JackFram/llama-68m"
12
13
14
15
16


@pytest.mark.parametrize(
    "common_llm_kwargs",
    [{
17
        "model_name": "JackFram/llama-68m",
18
19
20

        # Verify equality when cuda graphs allowed.
        "enforce_eager": False,
21
22
23

        # The original model is float32, keep it for numerical stability.
        "dtype": "float32",
24
25
26
27
28
29
    }])
@pytest.mark.parametrize(
    "per_test_common_llm_kwargs",
    [
        {
            # Identical models.
30
31
32
33
            "speculative_config": {
                "model": "JackFram/llama-68m",
                "num_speculative_tokens": 5,
            },
34
35
36
37
38
39
40
        },
    ])
@pytest.mark.parametrize("baseline_llm_kwargs", [{}])
@pytest.mark.parametrize("test_llm_kwargs", [{}])
@pytest.mark.parametrize("batch_size", [8])
@pytest.mark.parametrize("output_len", [32])
@pytest.mark.parametrize("seed", [1])
41
42
43
44
def test_spec_decode_cuda_graph(vllm_runner, common_llm_kwargs,
                                per_test_common_llm_kwargs,
                                baseline_llm_kwargs, test_llm_kwargs,
                                batch_size: int, output_len: int, seed: int):
45
46
    """Verify spec decode equality when cuda graphs are enabled.
    """
47
48
49
50
51
52
53
54
55
    run_equality_correctness_test(vllm_runner,
                                  common_llm_kwargs,
                                  per_test_common_llm_kwargs,
                                  baseline_llm_kwargs,
                                  test_llm_kwargs,
                                  batch_size,
                                  max_output_len=output_len,
                                  seed=seed,
                                  temperature=0.0)
56
57
58
59
60


@pytest.mark.parametrize(
    "common_llm_kwargs",
    [{
61
        "model_name": "JackFram/llama-160m",
62
63
64

        # Skip cuda graph recording for fast test.
        "enforce_eager": True,
65
66
67

        # The original model is float32, keep it for numerical stability.
        "dtype": "float32",
68
    }])
69
@pytest.mark.parametrize("per_test_common_llm_kwargs", [])
70
71
72
73
74
@pytest.mark.parametrize(
    "test_llm_kwargs",
    [
        # Explicitly specify draft model quantization
        {
75
76
77
78
79
            "speculative_config": {
                "model": "LnL-AI/TinyLlama-1.1B-Chat-v1.0-GPTQ-4bit",
                "num_speculative_tokens": 5,
                "quantization": "gptq",
            },
80
81
82
        },
        # Explicitly specify GPTQ-based draft model to use marlin quantization
        {
83
84
85
86
87
            "speculative_config": {
                "model": "LnL-AI/TinyLlama-1.1B-Chat-v1.0-GPTQ-4bit",
                "num_speculative_tokens": 5,
                "quantization": "marlin",
            },
88
89
90
        },
        # Not explicitly specify draft model quantization
        {
91
92
93
94
95
            "speculative_config": {
                "model": "LnL-AI/TinyLlama-1.1B-Chat-v1.0-GPTQ-4bit",
                "num_speculative_tokens": 5,
                "quantization": None,
            },
96
97
98
99
100
        },
    ])
@pytest.mark.parametrize("baseline_llm_kwargs", [{}])
@pytest.mark.parametrize("batch_size", [2])
@pytest.mark.parametrize("seed", [1])
101
102
103
104
105
def test_speculative_model_quantization_config(vllm_runner, common_llm_kwargs,
                                               per_test_common_llm_kwargs,
                                               baseline_llm_kwargs,
                                               test_llm_kwargs,
                                               batch_size: int, seed: int):
106
107
    """Verify spec decode works well with draft model quantization configs.
    """
108
109
110
111
112
113
114
115
116
    run_equality_correctness_test(vllm_runner,
                                  common_llm_kwargs,
                                  per_test_common_llm_kwargs,
                                  baseline_llm_kwargs,
                                  test_llm_kwargs,
                                  batch_size,
                                  max_output_len=32,
                                  seed=seed,
                                  temperature=0.0)
117
118
119
120
121
122
123
124
125


@pytest.mark.parametrize(
    "common_llm_kwargs",
    [{
        "model_name": MAIN_MODEL,

        # Skip cuda graph recording for fast test.
        "enforce_eager": True,
126
127
128

        # The original model is float32, keep it for numerical stability.
        "dtype": "float32",
129
130
131
    }])
@pytest.mark.parametrize("per_test_common_llm_kwargs", [{}])
@pytest.mark.parametrize("baseline_llm_kwargs", [{}])
132
133
134
135
136
137
138
@pytest.mark.parametrize("test_llm_kwargs", [{
    "speculative_config": {
        "model": "JackFram/llama-68m",
        "num_speculative_tokens": 3,
        "disable_mqa_scorer": True,
    },
}])
139
140
141
142
143
144
145
146
147
148
149
@pytest.mark.parametrize("batch_size", [1, 5])
@pytest.mark.parametrize(
    "output_len",
    [
        # Use smaller output len for fast test.
        32,
    ])
@pytest.mark.parametrize("seed", [1])
def test_mqa_scorer(vllm_runner, common_llm_kwargs, per_test_common_llm_kwargs,
                    baseline_llm_kwargs, test_llm_kwargs, batch_size: int,
                    output_len: int, seed: int):
150
    """Verify that speculative decoding generates the same output
151
152
153
154
155
156
157
158
159
160
161
    with batch expansion scorer and mqa scorer.
    """
    run_equality_correctness_test(vllm_runner,
                                  common_llm_kwargs,
                                  per_test_common_llm_kwargs,
                                  baseline_llm_kwargs,
                                  test_llm_kwargs,
                                  batch_size,
                                  max_output_len=output_len,
                                  seed=seed,
                                  temperature=0.0)