test_cpu_offload.py 3.87 KB
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0

3
4
5
6
# Expanded quantized model tests for CPU offloading
# Base tests: tests/basic_correctness/test_cpu_offload.py

import pytest
7
import os
8
9
10

from tests.quantization.utils import is_quant_method_supported

11
from ..utils import compare_two_settings, models_path_prefix
zhuwenwen's avatar
zhuwenwen committed
12
from vllm.platforms import current_platform
13
14


zhuwenwen's avatar
zhuwenwen committed
15
@pytest.mark.skipif(not is_quant_method_supported("fp8") or current_platform.is_rocm(),
16
17
18
                    reason="fp8 is not supported on this GPU type.")
def test_cpu_offload_fp8():
    # Test quantization of an unquantized checkpoint
zhuwenwen's avatar
zhuwenwen committed
19
    compare_two_settings(os.path.join(models_path_prefix, "meta-llama/Llama-3.2-1B-Instruct"),
20
                         ["--quantization", "fp8"],
21
                         ["--quantization", "fp8", "--cpu-offload-gb", "1"],
22
                         max_wait_seconds=480)
23
    # Test loading a quantized checkpoint
zhuwenwen's avatar
zhuwenwen committed
24
25
26
    # compare_two_settings(os.path.join(models_path_prefix, "neuralmagic/Qwen2-1.5B-Instruct-FP8"), [],
    #                      ["--cpu-offload-gb", "1"],
    #                      max_wait_seconds=480)
27
28


zhuwenwen's avatar
zhuwenwen committed
29
@pytest.mark.skipif(not is_quant_method_supported("gptq_marlin") or current_platform.is_rocm(),
30
                    reason="gptq_marlin is not supported on this GPU type.")
31
32
33
def test_cpu_offload_gptq(monkeypatch):
    # This quant method is sensitive to dummy weights, so we force real weights
    monkeypatch.setenv('VLLM_TEST_FORCE_LOAD_FORMAT', 'auto')
34
    # Test GPTQ Marlin
35
    compare_two_settings(os.path.join(models_path_prefix, "Qwen/Qwen2-1.5B-Instruct-GPTQ-Int4"), [],
36
37
                         ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
38
    # Test GPTQ
39
    compare_two_settings(os.path.join(models_path_prefix, "Qwen/Qwen2-1.5B-Instruct-GPTQ-Int4"),
40
                         ["--quantization", "gptq"],
41
42
                         ["--quantization", "gptq", "--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
43
44


zhuwenwen's avatar
zhuwenwen committed
45
@pytest.mark.skipif(not is_quant_method_supported("awq_marlin") or current_platform.is_rocm(),
46
                    reason="awq_marlin is not supported on this GPU type.")
47
48
49
def test_cpu_offload_awq(monkeypatch):
    # This quant method is sensitive to dummy weights, so we force real weights
    monkeypatch.setenv('VLLM_TEST_FORCE_LOAD_FORMAT', 'auto')
50
    # Test AWQ Marlin
51
    compare_two_settings(os.path.join(models_path_prefix, "Qwen/Qwen2-1.5B-Instruct-AWQ"), [],
52
53
                         ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
54
    # Test AWQ
55
    compare_two_settings(os.path.join(models_path_prefix, "Qwen/Qwen2-1.5B-Instruct-AWQ"),
56
                         ["--quantization", "awq"],
57
58
                         ["--quantization", "awq", "--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
59
60


zhuwenwen's avatar
zhuwenwen committed
61
@pytest.mark.skipif(not is_quant_method_supported("gptq_marlin") or current_platform.is_rocm(),
62
                    reason="gptq_marlin is not supported on this GPU type.")
63
64
65
def test_cpu_offload_compressed_tensors(monkeypatch):
    # This quant method is sensitive to dummy weights, so we force real weights
    monkeypatch.setenv('VLLM_TEST_FORCE_LOAD_FORMAT', 'auto')
66
    # Test wNa16
67
    compare_two_settings(os.path.join(models_path_prefix, "nm-testing/tinyllama-oneshot-w4a16-channel-v2"), [],
68
69
                         ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
70
    # Test w4a16_marlin24
71
    compare_two_settings(os.path.join(models_path_prefix, "nm-testing/llama7b-one-shot-2_4-w4a16-marlin24-t"),
72
73
                         [], ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
74
75
    # Test w8a8
    compare_two_settings(
76
        os.path.join(models_path_prefix, "nm-testing/tinyllama-oneshot-w8w8-test-static-shape-change"), [],
77
78
        ["--cpu-offload-gb", "1"],
        max_wait_seconds=480)