untest_gptq_marlin_24.py 2.88 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
zhuwenwen's avatar
zhuwenwen committed
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5
6
7
8
"""Compare the outputs of a GPTQ model to a Marlin_24 model.

Note: GPTQ and Marlin_24 do not have bitwise correctness.
As a result, in this test, we just confirm that the top selected tokens of the
Marlin/GPTQ models are in the top 3 selections of each other.
"""
9

10
11
12
from dataclasses import dataclass

import pytest
13
import os
14

15
from tests.quantization.utils import is_quant_method_supported
zhuwenwen's avatar
zhuwenwen committed
16
from vllm.platforms import current_platform
17

zhuwenwen's avatar
zhuwenwen committed
18
19
from ..utils import check_logprobs_close
from ...utils import models_path_prefix
20

21
22
23
24
25
26
27
28
29

@dataclass
class ModelPair:
    model_marlin: str
    model_gptq: str


model_pairs = [
    # 4-bit, group_size == 128
30
    ModelPair(
31
32
        model_marlin=os.path.join(models_path_prefix, "alexm-nm/tinyllama-24-marlin24-4bit-g128"),
        model_gptq=os.path.join(models_path_prefix, "alexm-nm/tinyllama-24-gptq-4bit-g128"),
33
    ),
34
35
36
    # # 4-bit, group_size == channelwise
    # ModelPair(model_marlin="alexm-nm/tinyllama-24-marlin24-4bit-channelwise",
    #           model_gptq="alexm-nm/tinyllama-24-gptq-4bit-channelwise"),
37
    # 8-bit, group_size == 128
38
    ModelPair(
39
40
        model_marlin=os.path.join(models_path_prefix, "alexm-nm/tinyllama-24-marlin24-8bit-g128"),
        model_gptq=os.path.join(models_path_prefix, "alexm-nm/tinyllama-24-gptq-8bit-g128"),
41
    ),
42
    # # 8-bit, group_size == channelwise
zhuwenwen's avatar
zhuwenwen committed
43
44
    # ModelPair(model_marlin=os.path.join(models_path_prefix, "alexm-nm/tinyllama-24-marlin24-8bit-channelwise"),
    #           model_gptq=os.path.join(models_path_prefix, "alexm-nm/tinyllama-24-gptq-8bit-channelwise")),
45
46
47
48
]


@pytest.mark.flaky(reruns=2)
49
50
51
52
53
54
@pytest.mark.skipif(
    not is_quant_method_supported("gptq_marlin_24")
    or current_platform.is_rocm()
    or not current_platform.is_cuda(),
    reason="Marlin24 is not supported on this GPU type.",
)
55
56
57
58
59
60
61
62
63
64
65
66
@pytest.mark.parametrize("model_pair", model_pairs)
@pytest.mark.parametrize("dtype", ["half"])
@pytest.mark.parametrize("max_tokens", [8])
@pytest.mark.parametrize("num_logprobs", [5])
def test_models(
    vllm_runner,
    example_prompts,
    model_pair: ModelPair,
    dtype: str,
    max_tokens: int,
    num_logprobs: int,
) -> None:
67
    with vllm_runner(
68
69
70
71
        model_pair.model_marlin,
        dtype=dtype,
        quantization="gptq_marlin_24",
        allow_deprecated_quantization=True,
72
    ) as marlin_24_model:
73
        marlin_24_outputs = marlin_24_model.generate_greedy_logprobs(
74
75
            example_prompts, max_tokens, num_logprobs
        )
76

77
78
79
    with vllm_runner(
        model_pair.model_gptq, dtype=dtype, quantization="gptq"
    ) as gptq_model:
80
        gptq_outputs = gptq_model.generate_greedy_logprobs(
81
82
            example_prompts, max_tokens, num_logprobs
        )
83
84
85
86
87
88
89

    check_logprobs_close(
        outputs_0_lst=gptq_outputs,
        outputs_1_lst=marlin_24_outputs,
        name_0="gptq",
        name_1="marlin_24",
    )