|
| 1 | +import pytest |
| 2 | + |
| 3 | +from vllm import SamplingParams |
| 4 | + |
| 5 | +from .conftest import get_output_from_llm_generator |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.parametrize( |
| 9 | + "common_llm_kwargs", |
| 10 | + [{ |
| 11 | + "model": "JackFram/llama-68m", |
| 12 | + "speculative_model": "JackFram/llama-68m", |
| 13 | + "num_speculative_tokens": 5, |
| 14 | +
|
| 15 | + # Required for spec decode. |
| 16 | + "use_v2_block_manager": True |
| 17 | + }]) |
| 18 | +@pytest.mark.parametrize( |
| 19 | + "per_test_common_llm_kwargs", |
| 20 | + [ |
| 21 | + { |
| 22 | + # Expect failure as spec decode not supported by |
| 23 | + # Ray backend. |
| 24 | + "worker_use_ray": True, |
| 25 | + }, |
| 26 | + ]) |
| 27 | +@pytest.mark.parametrize("test_llm_kwargs", [{}]) |
| 28 | +@pytest.mark.parametrize("seed", [1]) |
| 29 | +def test_spec_decode_xfail_ray(test_llm_generator): |
| 30 | + """Verify that speculative decoding with Ray fails. |
| 31 | + """ |
| 32 | + output_len = 128 |
| 33 | + temperature = 0.0 |
| 34 | + |
| 35 | + prompts = [ |
| 36 | + "Hello, my name is", |
| 37 | + ] |
| 38 | + |
| 39 | + sampling_params = SamplingParams( |
| 40 | + max_tokens=output_len, |
| 41 | + ignore_eos=True, |
| 42 | + temperature=temperature, |
| 43 | + ) |
| 44 | + |
| 45 | + with pytest.raises(AssertionError, |
| 46 | + match="Speculative decoding not yet supported for "): |
| 47 | + get_output_from_llm_generator(test_llm_generator, prompts, |
| 48 | + sampling_params) |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.parametrize( |
| 52 | + "common_llm_kwargs", |
| 53 | + [{ |
| 54 | + "model": "JackFram/llama-68m", |
| 55 | + "speculative_model": "JackFram/llama-68m", |
| 56 | + "num_speculative_tokens": 5, |
| 57 | +
|
| 58 | + # Required for spec decode. |
| 59 | + "use_v2_block_manager": True |
| 60 | + }]) |
| 61 | +@pytest.mark.parametrize("per_test_common_llm_kwargs", [ |
| 62 | + { |
| 63 | + "enable_chunked_prefill": True, |
| 64 | + }, |
| 65 | +]) |
| 66 | +@pytest.mark.parametrize("test_llm_kwargs", [{}]) |
| 67 | +@pytest.mark.parametrize("seed", [1]) |
| 68 | +def test_spec_decode_xfail_chunked_prefill(test_llm_generator): |
| 69 | + """Verify that speculative decoding with chunked prefill fails. |
| 70 | + """ |
| 71 | + output_len = 128 |
| 72 | + temperature = 0.0 |
| 73 | + |
| 74 | + prompts = [ |
| 75 | + "Hello, my name is", |
| 76 | + ] |
| 77 | + |
| 78 | + sampling_params = SamplingParams( |
| 79 | + max_tokens=output_len, |
| 80 | + ignore_eos=True, |
| 81 | + temperature=temperature, |
| 82 | + ) |
| 83 | + |
| 84 | + with pytest.raises(ValueError, |
| 85 | + match="Speculative decoding and chunked prefill"): |
| 86 | + get_output_from_llm_generator(test_llm_generator, prompts, |
| 87 | + sampling_params) |
| 88 | + |
| 89 | + |
| 90 | +@pytest.mark.parametrize( |
| 91 | + "common_llm_kwargs", |
| 92 | + [{ |
| 93 | + "model": "meta-llama/Llama-2-7b-chat-hf", |
| 94 | + "speculative_model": "JackFram/llama-68m", |
| 95 | + "num_speculative_tokens": 5, |
| 96 | +
|
| 97 | + # Required for spec decode. |
| 98 | + "use_v2_block_manager": True |
| 99 | + }]) |
| 100 | +@pytest.mark.parametrize( |
| 101 | + "per_test_common_llm_kwargs", |
| 102 | + [ |
| 103 | + { |
| 104 | + # Speculative max model len > overridden max model len should raise. |
| 105 | + "max_model_len": 128, |
| 106 | + "speculative_max_model_len": 129, |
| 107 | + }, |
| 108 | + { |
| 109 | + # Speculative max model len > draft max model len should raise. |
| 110 | + # https://huggingface.co/JackFram/llama-68m/blob/3b606af5198a0b26762d589a3ee3d26ee6fa6c85/config.json#L12 |
| 111 | + "speculative_max_model_len": 2048 + 1, |
| 112 | + }, |
| 113 | + { |
| 114 | + # Speculative max model len > target max model len should raise. |
| 115 | + # https://huggingface.co/meta-llama/Llama-2-7b-chat-hf/blob/f5db02db724555f92da89c216ac04704f23d4590/config.json#L12 |
| 116 | + "speculative_max_model_len": 4096 + 1, |
| 117 | + }, |
| 118 | + ]) |
| 119 | +@pytest.mark.parametrize("test_llm_kwargs", [{}]) |
| 120 | +@pytest.mark.parametrize("seed", [1]) |
| 121 | +def test_spec_decode_xfail_spec_max_model_len(test_llm_generator): |
| 122 | + """Verify that speculative decoding validates speculative_max_model_len. |
| 123 | + """ |
| 124 | + output_len = 128 |
| 125 | + temperature = 0.0 |
| 126 | + |
| 127 | + prompts = [ |
| 128 | + "Hello, my name is", |
| 129 | + ] |
| 130 | + |
| 131 | + sampling_params = SamplingParams( |
| 132 | + max_tokens=output_len, |
| 133 | + ignore_eos=True, |
| 134 | + temperature=temperature, |
| 135 | + ) |
| 136 | + |
| 137 | + with pytest.raises(ValueError, match="cannot be larger than"): |
| 138 | + get_output_from_llm_generator(test_llm_generator, prompts, |
| 139 | + sampling_params) |
| 140 | + |
| 141 | + |
| 142 | +@pytest.mark.parametrize("common_llm_kwargs", [{ |
| 143 | + "model": "JackFram/llama-68m", |
| 144 | + "speculative_model": "JackFram/llama-68m", |
| 145 | + "num_speculative_tokens": 5, |
| 146 | +}]) |
| 147 | +@pytest.mark.parametrize("per_test_common_llm_kwargs", [{}]) |
| 148 | +@pytest.mark.parametrize("test_llm_kwargs", [{}]) |
| 149 | +@pytest.mark.parametrize("seed", [1]) |
| 150 | +def test_spec_decode_xfail_block_manager_v1(test_llm_generator): |
| 151 | + """Verify that speculative decoding with block manager v1 fails. |
| 152 | + """ |
| 153 | + output_len = 128 |
| 154 | + temperature = 0.0 |
| 155 | + |
| 156 | + prompts = [ |
| 157 | + "Hello, my name is", |
| 158 | + ] |
| 159 | + |
| 160 | + sampling_params = SamplingParams( |
| 161 | + max_tokens=output_len, |
| 162 | + ignore_eos=True, |
| 163 | + temperature=temperature, |
| 164 | + ) |
| 165 | + |
| 166 | + with pytest.raises(ValueError, |
| 167 | + match="Speculative decoding requires usage of the V2"): |
| 168 | + get_output_from_llm_generator(test_llm_generator, prompts, |
| 169 | + sampling_params) |
0 commit comments