test_lm_head.py 1.78 KB
Newer Older
1
2
3
4
5
6
7
8
"""Tests whether gptq models with quantized lm_head can be loaded.

Run `pytest tests/quantization/test_quant_lm_head_true.py --forked`.
"""
from typing import Tuple

import pytest
import torch
9
import os
10
11
12
13
14

from vllm.model_executor.layers.quantization.gptq import GPTQLinearMethod
from vllm.model_executor.layers.quantization.gptq_marlin import (
    GPTQMarlinLinearMethod)
from vllm.model_executor.layers.quantization.marlin import MarlinLinearMethod
15
16
from vllm.model_executor.layers.vocab_parallel_embedding import (
    UnquantizedEmbeddingMethod)
17
from ..utils import models_path_prefix
18
19
20
21

PROMPT = "On the surface of Mars, we found"

MODELS_QUANT = [(
22
    os.path.join(models_path_prefix, "LnL-AI/TinyLlama-1.1B-intermediate-step-1341k-3T-autoround-lm_head-symFalse"),
zhuwenwen's avatar
zhuwenwen committed
23
24
    True), (os.path.join(models_path_prefix, "TheBloke/TinyLlama-1.1B-Chat-v1.0-GPTQ"), False)]
                # (os.path.join(models_path_prefix, "neuralmagic/Meta-Llama-3-8B-Instruct-FP8"), False)]
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


@pytest.mark.parametrize("model_lm_head_quant", MODELS_QUANT)
def test_lm_head(
    vllm_runner,
    model_lm_head_quant: Tuple[str, bool],
) -> None:
    model, lm_head_quantized = model_lm_head_quant
    vllm_model = vllm_runner(model, dtype=torch.float16, max_model_len=2048)

    lm_head_layer = (vllm_model.model.llm_engine.model_executor.driver_worker.
                     model_runner.model.lm_head)

    if lm_head_quantized:
        assert isinstance(
            lm_head_layer.linear_method,
            (GPTQLinearMethod, GPTQMarlinLinearMethod, MarlinLinearMethod))
    else:
43
44
        assert isinstance(lm_head_layer.linear_method,
                          UnquantizedEmbeddingMethod)
45
46
47
48
49

    print(
        vllm_model.generate_greedy(prompts=["Hello my name is"],
                                   max_tokens=10)[0][1])
    del vllm_model