test_gptq_marlin.py 3.75 KB
Newer Older
1
2
3
"""Compares the outputs of gptq vs gptq_marlin 
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
4
Marlin/GPTQ models are in the top 5 selections of each other.
5
6
7
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.
8

9
10
11
12
13
14
15
16
Run `pytest tests/models/test_gptq_marlin.py`.
"""
import os

import pytest
import torch

from vllm.model_executor.layers.quantization import QUANTIZATION_METHODS
17
from vllm.model_executor.layers.rotary_embedding import _ROPE_DICT
18

19
20
from .utils import check_logprobs_close

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
os.environ["TOKENIZERS_PARALLELISM"] = "true"

MAX_MODEL_LEN = 1024

capability = torch.cuda.get_device_capability()
capability = capability[0] * 10 + capability[1]
gptq_marlin_not_supported = (
    capability < QUANTIZATION_METHODS["gptq_marlin"].get_min_capability())

MODELS = [
    # act_order==False, group_size=channelwise
    ("robertgshaw2/zephyr-7b-beta-channelwise-gptq", "main"),
    # act_order==False, group_size=128
    ("TheBloke/Llama-2-7B-GPTQ", "main"),

    # act_order==True, group_size=128
    ("TheBloke/TinyLlama-1.1B-Chat-v1.0-GPTQ", "main"),
    # act_order==True, group_size=64
    ("TheBloke/TinyLlama-1.1B-Chat-v1.0-GPTQ", "gptq-4bit-64g-actorder_True"),
    # act_order==True, group_size=32
    ("TheBloke/TinyLlama-1.1B-Chat-v1.0-GPTQ", "gptq-4bit-32g-actorder_True"),
42
43
44
45
46
47
48

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


52
@pytest.mark.flaky(reruns=3)
53
54
55
@pytest.mark.skipif(gptq_marlin_not_supported,
                    reason="gptq_marlin is not supported on this GPU type.")
@pytest.mark.parametrize("model", MODELS)
56
@pytest.mark.parametrize("dtype", ["half", "bfloat16"])
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@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.
    gptq_marlin_model = vllm_runner(model_name=model_name,
                                    revision=revision,
                                    dtype=dtype,
                                    quantization="marlin",
                                    max_model_len=MAX_MODEL_LEN,
75
                                    tensor_parallel_size=1)
76
77

    gptq_marlin_outputs = gptq_marlin_model.generate_greedy_logprobs(
78
        example_prompts[:-1], max_tokens, num_logprobs)
79
    del gptq_marlin_model
80
    _ROPE_DICT.clear()  # clear rope cache to avoid rope dtype error
81
82

    # Run gptq.
83
84
85
    # The naive gptq kernel doesn't support bf16 yet.
    # Here we always compare fp16/bf16 gpt marlin kernel
    # to fp16 gptq kernel.
86
87
    gptq_model = vllm_runner(model_name=model_name,
                             revision=revision,
88
                             dtype="half",
89
90
                             quantization="gptq",
                             max_model_len=MAX_MODEL_LEN,
91
                             tensor_parallel_size=1)
92
    gptq_outputs = gptq_model.generate_greedy_logprobs(example_prompts[:-1],
93
94
95
96
97
98
99
100
101
102
                                                       max_tokens,
                                                       num_logprobs)
    del gptq_model

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