test_eagle3.py 2.38 KB
Newer Older
1
2
3
4
5
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest
import torch

6
from vllm.config import SpeculativeConfig
7
8
from vllm.model_executor.models.interfaces import supports_eagle3

9

10
11
12
13
14
15
16
@pytest.mark.parametrize("model_path", [
    pytest.param(
        "nm-testing/SpeculatorLlama3-1-8B-Eagle3-converted-0717-quantized",
        id="llama3-eagle3-speculator"),
    pytest.param(
        "nm-testing/Speculator-Qwen3-8B-Eagle3-converted-071-quantized",
        id="qwen3-eagle3-speculator"),
17
18
19
    pytest.param(
        "nm-testing/Speculator-Qwen3-8B-Eagle3-converted-071-quantized-w4a16",
        id="qwen3-eagle3-speculator-w4a16-verifier"),
20
21
22
23
24
25
26
27
28
29
30
31
32
])
def test_eagle3_speculators_model(vllm_runner, example_prompts, model_path,
                                  monkeypatch):
    """
    Test Eagle3 speculators models properly initialize speculative decoding.

    This test verifies:
    1. Eagle3 support is detected for the model
    2. Speculative config is automatically initialized from embedded config
    3. The draft model path is correctly set to the speculators model
    4. Speculative tokens count is valid
    5. Text generation works with speculative decoding enabled
    """
33
34
35
    # Set environment variable for V1 engine serialization
    monkeypatch.setenv("VLLM_ALLOW_INSECURE_SERIALIZATION", "1")

36
    with vllm_runner(model_path, dtype=torch.bfloat16) as vllm_model:
37
        # Verify Eagle3 support is detected
38
        eagle3_supported = vllm_model.apply_model(supports_eagle3)
39
        assert eagle3_supported, f"Eagle3 should be supported for {model_path}"
40

41
        vllm_config = vllm_model.llm.llm_engine.vllm_config
42

43
44
        assert isinstance(vllm_config.speculative_config, SpeculativeConfig), \
            "Speculative config should be initialized for speculators model"
45

46
47
48
49
        spec_config = vllm_config.speculative_config
        assert spec_config.num_speculative_tokens > 0, \
            (f"Expected positive speculative tokens, "
             f"got {spec_config.num_speculative_tokens}")
50

51
52
        assert spec_config.model == model_path, \
            f"Draft model should be {model_path}, got {spec_config.model}"
53

54
55
        vllm_outputs = vllm_model.generate_greedy(example_prompts,
                                                  max_tokens=20)
56
57
        assert vllm_outputs, \
            f"No outputs generated for speculators model {model_path}"