main
py 88 lines 2.59 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 """Tests AutoGPTQ (GPTQ with Marlin kernels) output correctness.
4
5 Note: Marlin internally uses locks to synchronize the threads. This can
6 result in very slight nondeterminism for Marlin. As a result, we re-run the test
7 up to 3 times to see if we pass.
8 """
9
10 import os
11
12 import pytest
13
14 from tests.quantization.utils import is_quant_method_supported
15 from vllm.model_executor.layers.rotary_embedding import _ROPE_DICT
16 from vllm.platforms import current_platform
17
18 from ..utils import check_logprobs_close
19
20 os.environ["TOKENIZERS_PARALLELISM"] = "true"
21
22 MAX_MODEL_LEN = 1024
23
24 MODELS = [
25 ("LnL-AI/TinyLlama-1.1B-Chat-v1.0-GPTQ-4bit", "main"),
26 # desc_act=True is a no-op for channelwise quantization.
27 ("TheBloke/TinyLlama-1.1B-Chat-v1.0-GPTQ", "gptq-8bit--1g-actorder_True"),
28 ("TechxGenus/gemma-2b-it-GPTQ", "main"),
29 ]
30
31
32 @pytest.mark.flaky(reruns=3)
33 @pytest.mark.skipif(
34 not is_quant_method_supported("auto_gptq")
35 or current_platform.is_rocm()
36 or not current_platform.is_cuda(),
37 reason="auto_gptq is not supported on this GPU type.",
38 )
39 @pytest.mark.parametrize("model", MODELS)
40 @pytest.mark.parametrize("dtype", ["half", "bfloat16"])
41 @pytest.mark.parametrize("max_tokens", [32])
42 @pytest.mark.parametrize("num_logprobs", [5])
43 def test_models(
44 vllm_runner,
45 example_prompts,
46 model,
47 dtype: str,
48 max_tokens: int,
49 num_logprobs: int,
50 ) -> None:
51 model_name, revision = model
52
53 # Run marlin.
54 with vllm_runner(
55 model_name=model_name,
56 revision=revision,
57 dtype=dtype,
58 quantization="marlin",
59 max_model_len=MAX_MODEL_LEN,
60 tensor_parallel_size=1,
61 ) as gptq_marlin_model:
62 gptq_marlin_outputs = gptq_marlin_model.generate_greedy_logprobs(
63 example_prompts[:-1], max_tokens, num_logprobs
64 )
65 _ROPE_DICT.clear() # clear rope cache to avoid rope dtype error
66
67 # Run gptq.
68 # The naive gptq kernel doesn't support bf16 yet.
69 # Here we always compare fp16/bf16 gpt marlin kernel
70 # to fp16 gptq kernel.
71 with vllm_runner(
72 model_name=model_name,
73 revision=revision,
74 dtype="half",
75 quantization="gptq",
76 max_model_len=MAX_MODEL_LEN,
77 tensor_parallel_size=1,
78 ) as gptq_model:
79 gptq_outputs = gptq_model.generate_greedy_logprobs(
80 example_prompts[:-1], max_tokens, num_logprobs
81 )
82
83 check_logprobs_close(
84 outputs_0_lst=gptq_outputs,
85 outputs_1_lst=gptq_marlin_outputs,
86 name_0="gptq",
87 name_1="gptq_marlin",
88 )