utils.py 3.84 KB
Newer Older
1
2
3
4
5
6
7
8
import os

import torch

from tests.quantization.utils import is_quant_method_supported
from vllm import LLM, SamplingParams
from vllm.plugins import set_torch_compile_backend
from vllm.utils import is_hip
9
10
import os
from ..utils import models_path_prefix
11
12

TEST_MODELS_SMOKE = [
13
    (os.path.join(models_path_prefix, "nm-testing/Meta-Llama-3-8B-Instruct-W8A8-Dyn-Per-Token-2048-Samples"), {
14
15
        "quantization": "compressed-tensors"
    }),
16
    (os.path.join(models_path_prefix, "meta-llama/Meta-Llama-3-8B"), {}),
17
18
19
]

TEST_MODELS = [
20
21
    (os.path.join(models_path_prefix, "facebook/opt-125m"), {}),
    (os.path.join(models_path_prefix, "nm-testing/tinyllama-oneshot-w8w8-test-static-shape-change"), {
22
23
24
        "dtype": torch.float16,
        "quantization": "compressed-tensors"
    }),
zhuwenwen's avatar
zhuwenwen committed
25
26
27
28
    # (os.path.join(models_path_prefix, "neuralmagic/Meta-Llama-3-8B-Instruct-FP8"), {
    #     "dtype": torch.float16,
    #     "quantization": "fp8"
    # }),
29
    (os.path.join(models_path_prefix, "nm-testing/Meta-Llama-3-8B-Instruct-W8A8-Dyn-Per-Token-2048-Samples"), {
30
31
        "quantization": "compressed-tensors"
    }),
32
    (os.path.join(models_path_prefix, "meta-llama/Meta-Llama-3-8B"), {}),
33
34
35
36
]

# TODO: enable in pytorch 2.5
if False and is_quant_method_supported("aqlm"):  # noqa: SIM223
37
    TEST_MODELS.append((os.path.join(models_path_prefix, "ISTA-DASLab/Llama-2-7b-AQLM-2Bit-1x16-hf"), {
38
39
40
41
42
        "quantization": "aqlm"
    }))

# TODO: enable in pytorch 2.5
if False and is_quant_method_supported("gguf"):  # noqa: SIM223
43
    TEST_MODELS.append((os.path.join(models_path_prefix, "TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF"), {
44
45
46
47
        "quantization": "gguf"
    }))

if is_quant_method_supported("gptq"):
48
    TEST_MODELS.append((os.path.join(models_path_prefix, "TheBloke/TinyLlama-1.1B-Chat-v0.3-GPTQ"), {
49
50
51
        "quantization": "gptq"
    }))

zhuwenwen's avatar
zhuwenwen committed
52
53
54
55
# if is_quant_method_supported("gptq_marlin"):
#     TEST_MODELS.append((os.path.join(models_path_prefix, "TheBloke/TinyLlama-1.1B-Chat-v1.0-GPTQ"), {
#         "quantization": "gptq_marlin"
#     }))
56

zhuwenwen's avatar
zhuwenwen committed
57
58
59
60
# if is_quant_method_supported("gptq_marlin_24"):
#     TEST_MODELS.append((os.path.join(models_path_prefix, "alexm-nm/tinyllama-24-marlin24-4bit-g128"), {
#         "quantization": "gptq_marlin_24"
#     }))
61

zhuwenwen's avatar
zhuwenwen committed
62
63
64
65
# if is_quant_method_supported("marlin"):
#     TEST_MODELS.append((os.path.join(models_path_prefix, "robertgshaw2/TinyLlama-1.1B-Chat-v1.0-g128-marlin"), {
#         "quantization": "marlin"
#     }))
66
67

if not is_hip() and is_quant_method_supported("awq"):
68
    TEST_MODELS.append((os.path.join(models_path_prefix, "TheBloke/TinyLlama-1.1B-Chat-v0.3-AWQ"), {
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
        "quantization": "AWQ"
    }))


def check_full_graph_support(model, model_kwargs, backend, tp_size=1):
    # make sure these models can be captured in full graph mode
    if "VLLM_TEST_DYNAMO_GRAPH_CAPTURE" not in os.environ:
        os.environ["VLLM_TEST_DYNAMO_GRAPH_CAPTURE"] = "1"
        os.environ["VLLM_TEST_DYNAMO_FULLGRAPH_CAPTURE"] = "1"

    # Inductor doesn't support fp8/gptq_marlin_24 yet.
    quantization = model_kwargs.get("quantization")
    if (quantization == "fp8" or quantization == "gptq_marlin"
            or quantization == "gptq_marlin_24") and backend != "eager":
        return

    set_torch_compile_backend(backend)

    prompts = [
        "Hello, my name is",
        "The president of the United States is",
        "The capital of France is",
        "The future of AI is",
    ]
    sampling_params = SamplingParams(temperature=0)
    llm = LLM(model=model,
              enforce_eager=True,
              tensor_parallel_size=tp_size,
              disable_custom_all_reduce=True,
              **model_kwargs)

    outputs = llm.generate(prompts, sampling_params)

    # Print the outputs.
    for output in outputs:
        prompt = output.prompt
        generated_text = output.outputs[0].text
        print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")