test_gptq_marlin.py 2.75 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
3
"""Compares the outputs of gptq vs gptq_marlin.

4
5
Note: GPTQ and Marlin do not have bitwise correctness.
As a result, in this test, we just confirm that the top selected tokens of the
6
Marlin/GPTQ models are in the top 5 selections of each other.
7
8
9
10
11
12
13
14
Note: Marlin internally uses locks to synchronize the threads. This can
result in very slight nondeterminism for Marlin. As a result, we re-run the test
up to 3 times to see if we pass.
"""
import os

import pytest

15
from tests.quantization.utils import is_quant_method_supported
16
from vllm.model_executor.layers.rotary_embedding import _ROPE_DICT
17

18
from ..utils import check_logprobs_close
19

20
21
22
23
24
25
26
os.environ["TOKENIZERS_PARALLELISM"] = "true"

MAX_MODEL_LEN = 1024

MODELS = [
    # act_order==True, group_size=128
    ("TheBloke/TinyLlama-1.1B-Chat-v1.0-GPTQ", "main"),
27
28
29

    # 8-bit, act_order==True, group_size=channelwise
    ("TheBloke/TinyLlama-1.1B-Chat-v1.0-GPTQ", "gptq-8bit--1g-actorder_True"),
30
31
32

    # 4-bit, act_order==True, group_size=128
    ("TechxGenus/gemma-1.1-2b-it-GPTQ", "main")
33
34
35
]


36
@pytest.mark.flaky(reruns=3)
37
@pytest.mark.skipif(not is_quant_method_supported("gptq_marlin"),
38
39
                    reason="gptq_marlin is not supported on this GPU type.")
@pytest.mark.parametrize("model", MODELS)
40
@pytest.mark.parametrize("dtype", ["half", "bfloat16"])
41
42
43
44
45
46
47
48
49
50
51
52
53
@pytest.mark.parametrize("max_tokens", [32])
@pytest.mark.parametrize("num_logprobs", [5])
def test_models(
    vllm_runner,
    example_prompts,
    model,
    dtype: str,
    max_tokens: int,
    num_logprobs: int,
) -> None:
    model_name, revision = model

    # Run marlin.
54
55
56
57
58
59
60
61
62
    with vllm_runner(model_name=model_name,
                     revision=revision,
                     dtype=dtype,
                     quantization="marlin",
                     max_model_len=MAX_MODEL_LEN,
                     tensor_parallel_size=1) as gptq_marlin_model:

        gptq_marlin_outputs = gptq_marlin_model.generate_greedy_logprobs(
            example_prompts[:-1], max_tokens, num_logprobs)
63
    _ROPE_DICT.clear()  # clear rope cache to avoid rope dtype error
64
65

    # Run gptq.
66
67
68
    # The naive gptq kernel doesn't support bf16 yet.
    # Here we always compare fp16/bf16 gpt marlin kernel
    # to fp16 gptq kernel.
69
70
71
72
73
74
75
76
    with vllm_runner(model_name=model_name,
                     revision=revision,
                     dtype="half",
                     quantization="gptq",
                     max_model_len=MAX_MODEL_LEN,
                     tensor_parallel_size=1) as gptq_model:
        gptq_outputs = gptq_model.generate_greedy_logprobs(
            example_prompts[:-1], max_tokens, num_logprobs)
77
78
79
80
81
82
83

    check_logprobs_close(
        outputs_0_lst=gptq_outputs,
        outputs_1_lst=gptq_marlin_outputs,
        name_0="gptq",
        name_1="gptq_marlin",
    )