test_marlin.py 2.52 KB
Newer Older
1
2
"""Compare the outputs of a GPTQ model to a Marlin model.

3
4
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
5
6
7
8
9
10
Marlin/GPTQ models are in the top 3 selections of each other.

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.

11
Run `pytest tests/models/test_marlin.py`.
12
"""
13
14
from dataclasses import dataclass

15
import pytest
16
import os
17

18
from tests.quantization.utils import is_quant_method_supported
19

20
from ...utils import check_logprobs_close
21
from ....utils import models_path_prefix
22

23
24
25
26
27
28
29
30

@dataclass
class ModelPair:
    model_marlin: str
    model_gptq: str


model_pairs = [
31
32
33
34
35
36
    ModelPair(model_marlin=os.path.join(models_path_prefix, "nm-testing/zephyr-beta-7b-marlin-g128"),
              model_gptq=os.path.join(models_path_prefix, "nm-testing/zephyr-beta-7b-gptq-g128")),
    ModelPair(model_marlin=os.path.join(models_path_prefix, "robertgshaw2/zephyr-7b-beta-channelwise-marlin"),
              model_gptq=os.path.join(models_path_prefix, "robertgshaw2/zephyr-7b-beta-channelwise-gptq")),
    ModelPair(model_marlin=os.path.join(models_path_prefix, "robertgshaw2/TinyLlama-1.1B-Chat-v1.0-g128-marlin"),
              model_gptq=os.path.join(models_path_prefix, "robertgshaw2/TinyLlama-1.1B-Chat-v1.0-g128-gptq"))
37
38
39
40
]


@pytest.mark.flaky(reruns=2)
41
@pytest.mark.skipif(not is_quant_method_supported("marlin"),
42
43
44
45
                    reason="Marlin is not supported on this GPU type.")
@pytest.mark.parametrize("model_pair", model_pairs)
@pytest.mark.parametrize("dtype", ["half"])
@pytest.mark.parametrize("max_tokens", [32])
46
@pytest.mark.parametrize("num_logprobs", [5])
47
48
49
50
51
52
53
54
def test_models(
    vllm_runner,
    example_prompts,
    model_pair: ModelPair,
    dtype: str,
    max_tokens: int,
    num_logprobs: int,
) -> None:
55
56
57
58
59
60
61
62
63
64
    with vllm_runner(model_pair.model_marlin,
                     dtype=dtype,
                     quantization="marlin") as marlin_model:
        marlin_outputs = marlin_model.generate_greedy_logprobs(
            example_prompts, max_tokens, num_logprobs)

    with vllm_runner(model_pair.model_gptq, dtype=dtype,
                     quantization="gptq") as gptq_model:
        gptq_outputs = gptq_model.generate_greedy_logprobs(
            example_prompts, max_tokens, num_logprobs)
65

66
67
68
69
70
71
    check_logprobs_close(
        outputs_0_lst=gptq_outputs,
        outputs_1_lst=marlin_outputs,
        name_0="gptq",
        name_1="marlin",
    )