main
py 69 lines 2.59 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 import pytest
4 import torch
5
6 from vllm.config import SpeculativeConfig
7 from vllm.model_executor.models.interfaces import supports_eagle3
8 from vllm.platforms import current_platform
9
10
11 @pytest.mark.parametrize(
12 "model_path",
13 [
14 pytest.param(
15 "nm-testing/SpeculatorLlama3-1-8B-Eagle3-converted-0717-quantized",
16 id="llama3-eagle3-speculator",
17 ),
18 pytest.param(
19 "nm-testing/Speculator-Qwen3-8B-Eagle3-converted-071-quantized",
20 id="qwen3-eagle3-speculator",
21 ),
22 pytest.param(
23 "nm-testing/Speculator-Qwen3-8B-Eagle3-converted-071-quantized-w4a16",
24 id="qwen3-eagle3-speculator-w4a16-verifier",
25 marks=pytest.mark.skipif(
26 current_platform.is_rocm(),
27 reason="The tests are skipped on rocm platform.",
28 ),
29 ),
30 ],
31 )
32 def test_eagle3_speculators_model(
33 vllm_runner, example_prompts, model_path, monkeypatch
34 ):
35 """Test Eagle3 speculators models properly initialize speculative decoding.
36
37 This test verifies:
38 1. Eagle3 support is detected for the model
39 2. Speculative config is automatically initialized from embedded config
40 3. The draft model path is correctly set to the speculators model
41 4. Speculative tokens count is valid
42 5. Text generation works with speculative decoding enabled
43 """
44 # Set environment variable for V1 engine serialization
45 monkeypatch.setenv("VLLM_ALLOW_INSECURE_SERIALIZATION", "1")
46
47 with vllm_runner(model_path, dtype=torch.bfloat16) as vllm_model:
48 # Verify Eagle3 support is detected
49 eagle3_supported = vllm_model.apply_model(supports_eagle3)
50 assert eagle3_supported, f"Eagle3 should be supported for {model_path}"
51
52 vllm_config = vllm_model.llm.llm_engine.vllm_config
53
54 assert isinstance(vllm_config.speculative_config, SpeculativeConfig), (
55 "Speculative config should be initialized for speculators model"
56 )
57
58 spec_config = vllm_config.speculative_config
59 assert spec_config.num_speculative_tokens > 0, (
60 f"Expected positive speculative tokens, "
61 f"got {spec_config.num_speculative_tokens}"
62 )
63
64 assert spec_config.model == model_path, (
65 f"Draft model should be {model_path}, got {spec_config.model}"
66 )
67
68 vllm_outputs = vllm_model.generate_greedy(example_prompts, max_tokens=20)
69 assert vllm_outputs, f"No outputs generated for speculators model {model_path}"