|
| 1 | +"""This docstring details important information on the testing methodology. |
| 2 | +
|
| 3 | +Most of the tests rely on "greedy equality", where we expect the output of |
| 4 | +speculative decoding on a sequence to exactly match the output of normal non- |
| 5 | +speculative decoding. |
| 6 | +
|
| 7 | +Since speculative decoding with rejection sampling guarantees that the output |
| 8 | +distribution matches the target model's output distribution (up to hardware |
| 9 | +numerics, see https://arxiv.org/pdf/2302.01318.pdf), we can expect greedy |
| 10 | +equality. |
| 11 | +
|
| 12 | +However, we still need to verify below scenario could be passed: |
| 13 | + * Batch size 1 greedy equality |
| 14 | + * Batch size >1 greedy equality |
| 15 | + * Test greedy equality under preemption |
| 16 | + * Test greedy equality under various number of speculative tokens. |
| 17 | +
|
| 18 | +With those tests, we can say at least, EAGLE would not break the |
| 19 | +correctess for the target model outputs. |
| 20 | +""" |
| 21 | + |
| 22 | +import pytest |
| 23 | + |
| 24 | +from .conftest import run_greedy_equality_correctness_test |
| 25 | + |
| 26 | +# main model |
| 27 | +MAIN_MODEL = "JackFram/llama-68m" |
| 28 | + |
| 29 | +# speculative model |
| 30 | +SPEC_MODEL = "abhigoyal/vllm-eagle-llama-68m-random" |
| 31 | + |
| 32 | +# max. number of speculative tokens: this corresponds to |
| 33 | +# num_heads in the config.json of the speculator model. |
| 34 | +MAX_SPEC_TOKENS = 4 |
| 35 | + |
| 36 | +# precision |
| 37 | +PRECISION = "float32" |
| 38 | + |
| 39 | + |
| 40 | +@pytest.mark.parametrize( |
| 41 | + "common_llm_kwargs", |
| 42 | + [{ |
| 43 | + # Skip cuda graph recording for fast test. |
| 44 | + "enforce_eager": True, |
| 45 | +
|
| 46 | + # Required for spec decode. |
| 47 | + "use_v2_block_manager": True, |
| 48 | +
|
| 49 | + # Print spec metrics. |
| 50 | + "disable_log_stats": False, |
| 51 | +
|
| 52 | + # Precision |
| 53 | + "dtype": PRECISION, |
| 54 | +
|
| 55 | + # Main model |
| 56 | + "model": MAIN_MODEL, |
| 57 | + }]) |
| 58 | +@pytest.mark.parametrize("per_test_common_llm_kwargs", [{}]) |
| 59 | +@pytest.mark.parametrize("baseline_llm_kwargs", [{}]) |
| 60 | +@pytest.mark.parametrize("test_llm_kwargs", [ |
| 61 | + { |
| 62 | + "speculative_model": SPEC_MODEL, |
| 63 | + "num_speculative_tokens": MAX_SPEC_TOKENS, |
| 64 | + }, |
| 65 | +]) |
| 66 | +@pytest.mark.parametrize("output_len", [ |
| 67 | + 128, |
| 68 | +]) |
| 69 | +@pytest.mark.parametrize("batch_size", [1, 32]) |
| 70 | +@pytest.mark.parametrize("seed", [1]) |
| 71 | +def test_eagle_e2e_greedy_correctness(baseline_llm_generator, |
| 72 | + test_llm_generator, batch_size: int, |
| 73 | + output_len: int): |
| 74 | + """Verify greedy equality with different batch size.""" |
| 75 | + run_greedy_equality_correctness_test(baseline_llm_generator, |
| 76 | + test_llm_generator, |
| 77 | + batch_size, |
| 78 | + max_output_len=output_len, |
| 79 | + force_output_len=True) |
| 80 | + |
| 81 | + |
| 82 | +@pytest.mark.parametrize( |
| 83 | + "common_llm_kwargs", |
| 84 | + [{ |
| 85 | + "enforce_eager": False, |
| 86 | +
|
| 87 | + # Required for spec decode. |
| 88 | + "use_v2_block_manager": True, |
| 89 | +
|
| 90 | + # Print spec metrics. |
| 91 | + "disable_log_stats": False, |
| 92 | +
|
| 93 | + # Precision |
| 94 | + "dtype": PRECISION, |
| 95 | +
|
| 96 | + # Main model |
| 97 | + "model": MAIN_MODEL, |
| 98 | + }]) |
| 99 | +@pytest.mark.parametrize("per_test_common_llm_kwargs", [{}]) |
| 100 | +@pytest.mark.parametrize("baseline_llm_kwargs", [{}]) |
| 101 | +@pytest.mark.parametrize("test_llm_kwargs", [ |
| 102 | + { |
| 103 | + "speculative_model": SPEC_MODEL, |
| 104 | + "num_speculative_tokens": MAX_SPEC_TOKENS, |
| 105 | + }, |
| 106 | +]) |
| 107 | +@pytest.mark.parametrize("output_len", [ |
| 108 | + 128, |
| 109 | +]) |
| 110 | +@pytest.mark.parametrize("batch_size", [1, 32]) |
| 111 | +@pytest.mark.parametrize("seed", [1]) |
| 112 | +def test_eagle_e2e_greedy_correctness_cuda_graph(baseline_llm_generator, |
| 113 | + test_llm_generator, |
| 114 | + batch_size: int, |
| 115 | + output_len: int): |
| 116 | + """Verify greedy equality with cuda graph enabled and different |
| 117 | + batch sizes.""" |
| 118 | + run_greedy_equality_correctness_test(baseline_llm_generator, |
| 119 | + test_llm_generator, |
| 120 | + batch_size, |
| 121 | + max_output_len=output_len, |
| 122 | + force_output_len=True) |
| 123 | + |
| 124 | + |
| 125 | +@pytest.mark.parametrize( |
| 126 | + "common_llm_kwargs", |
| 127 | + [{ |
| 128 | + "block_size": 8, |
| 129 | + # 2 for small prompt, 256//8 for generated. |
| 130 | + "num_gpu_blocks_override": 2 + 256 // 8, |
| 131 | + "max_model_len": (2 + 256 // 8) * 8, |
| 132 | +
|
| 133 | + # Skip cuda graph recording for fast test. |
| 134 | + "enforce_eager": True, |
| 135 | +
|
| 136 | + # Required for spec decode. |
| 137 | + "use_v2_block_manager": True, |
| 138 | +
|
| 139 | + # Precision |
| 140 | + "dtype": PRECISION, |
| 141 | +
|
| 142 | + # Main model |
| 143 | + "model": MAIN_MODEL, |
| 144 | + }]) |
| 145 | +@pytest.mark.parametrize("per_test_common_llm_kwargs", [{}]) |
| 146 | +@pytest.mark.parametrize("baseline_llm_kwargs", [{}]) |
| 147 | +@pytest.mark.parametrize("test_llm_kwargs", [ |
| 148 | + { |
| 149 | + "speculative_model": SPEC_MODEL, |
| 150 | + "num_speculative_tokens": MAX_SPEC_TOKENS, |
| 151 | + }, |
| 152 | +]) |
| 153 | +@pytest.mark.parametrize( |
| 154 | + "output_len", |
| 155 | + [ |
| 156 | + # Use small output len for fast test. |
| 157 | + 128, |
| 158 | + ]) |
| 159 | +@pytest.mark.parametrize("batch_size", [4]) |
| 160 | +@pytest.mark.parametrize("seed", [1]) |
| 161 | +def test_eagle_e2e_greedy_correctness_with_preemption(baseline_llm_generator, |
| 162 | + test_llm_generator, |
| 163 | + batch_size: int, |
| 164 | + output_len: int): |
| 165 | + """Verify greedy equality, even when some sequences are preempted mid- |
| 166 | + generation. |
| 167 | + """ |
| 168 | + run_greedy_equality_correctness_test(baseline_llm_generator, |
| 169 | + test_llm_generator, |
| 170 | + batch_size, |
| 171 | + max_output_len=output_len, |
| 172 | + force_output_len=True) |
| 173 | + |
| 174 | + |
| 175 | +@pytest.mark.parametrize( |
| 176 | + "common_llm_kwargs", |
| 177 | + [{ |
| 178 | + # Skip cuda graph recording for fast test. |
| 179 | + "enforce_eager": True, |
| 180 | +
|
| 181 | + # Required for spec decode. |
| 182 | + "use_v2_block_manager": True, |
| 183 | +
|
| 184 | + # Precision |
| 185 | + "dtype": PRECISION, |
| 186 | +
|
| 187 | + # Main model |
| 188 | + "model": MAIN_MODEL, |
| 189 | + }]) |
| 190 | +@pytest.mark.parametrize("per_test_common_llm_kwargs", [{}]) |
| 191 | +@pytest.mark.parametrize("baseline_llm_kwargs", [{}]) |
| 192 | +@pytest.mark.parametrize( |
| 193 | + "test_llm_kwargs", |
| 194 | + [ |
| 195 | + { |
| 196 | + "speculative_model": SPEC_MODEL, |
| 197 | + "num_speculative_tokens": k, |
| 198 | + } |
| 199 | + # Try a range of num. speculative tokens |
| 200 | + for k in range(1, 1 + MAX_SPEC_TOKENS) |
| 201 | + ]) |
| 202 | +@pytest.mark.parametrize("batch_size", [2]) |
| 203 | +@pytest.mark.parametrize( |
| 204 | + "output_len", |
| 205 | + [ |
| 206 | + # Use smaller output len for fast test. |
| 207 | + 32, |
| 208 | + ]) |
| 209 | +@pytest.mark.parametrize("seed", [1]) |
| 210 | +def test_eagle_different_k(baseline_llm_generator, test_llm_generator, |
| 211 | + batch_size: int, output_len: int): |
| 212 | + """Verify that eagle speculative decoding produces exact equality |
| 213 | + to without spec decode with different values of num_speculative_tokens. |
| 214 | + """ |
| 215 | + run_greedy_equality_correctness_test(baseline_llm_generator, |
| 216 | + test_llm_generator, |
| 217 | + batch_size, |
| 218 | + max_output_len=output_len, |
| 219 | + force_output_len=True) |
| 220 | + |
| 221 | + |
| 222 | +@pytest.mark.parametrize( |
| 223 | + "common_llm_kwargs", |
| 224 | + [{ |
| 225 | + # Skip cuda graph recording for fast test. |
| 226 | + "enforce_eager": True, |
| 227 | +
|
| 228 | + # Required for spec decode. |
| 229 | + "use_v2_block_manager": True, |
| 230 | +
|
| 231 | + # Precision |
| 232 | + "dtype": PRECISION, |
| 233 | +
|
| 234 | + # Main model |
| 235 | + "model": MAIN_MODEL, |
| 236 | + }]) |
| 237 | +@pytest.mark.parametrize("per_test_common_llm_kwargs", [{}]) |
| 238 | +@pytest.mark.parametrize("baseline_llm_kwargs", [{}]) |
| 239 | +@pytest.mark.parametrize("test_llm_kwargs", |
| 240 | + [{ |
| 241 | + "speculative_model": SPEC_MODEL, |
| 242 | + "num_speculative_tokens": MAX_SPEC_TOKENS, |
| 243 | + "speculative_disable_by_batch_size": 4 |
| 244 | + }]) |
| 245 | +@pytest.mark.parametrize("batch_size", [1, 5]) |
| 246 | +@pytest.mark.parametrize( |
| 247 | + "output_len", |
| 248 | + [ |
| 249 | + # Use smaller output len for fast test. |
| 250 | + 32, |
| 251 | + ]) |
| 252 | +@pytest.mark.parametrize("seed", [1]) |
| 253 | +def test_eagle_disable_queue(baseline_llm_generator, test_llm_generator, |
| 254 | + batch_size: int, output_len: int): |
| 255 | + """Verify that eagle speculative decoding produces exact equality |
| 256 | + to without spec decode when speculation is disabled for large |
| 257 | + batch sizes. |
| 258 | + """ |
| 259 | + run_greedy_equality_correctness_test(baseline_llm_generator, |
| 260 | + test_llm_generator, |
| 261 | + batch_size, |
| 262 | + max_output_len=output_len, |
| 263 | + force_output_len=True) |
| 264 | + |
| 265 | + |
| 266 | +if __name__ == "__main__": |
| 267 | + import pytest |
| 268 | + pytest.main([__file__]) |
0 commit comments