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

3
4
5
6
7
8
9
10
11
12
# Expanded quantized model tests for CPU offloading
# Base tests: tests/basic_correctness/test_cpu_offload.py

import pytest

from tests.quantization.utils import is_quant_method_supported

from ..utils import compare_two_settings


13
14
15
16
17
18
19
@pytest.fixture(scope="function", autouse=True)
def use_v0_only(monkeypatch):
    # Fall back to V0 if cpu offloading is enabled.
    # Fixture is required to that baseline uses V0.
    monkeypatch.setenv('VLLM_USE_V1', '0')


20
21
22
23
@pytest.mark.skipif(not is_quant_method_supported("fp8"),
                    reason="fp8 is not supported on this GPU type.")
def test_cpu_offload_fp8():
    # Test quantization of an unquantized checkpoint
24
    compare_two_settings("meta-llama/Llama-3.2-1B-Instruct",
25
                         ["--quantization", "fp8"],
26
                         ["--quantization", "fp8", "--cpu-offload-gb", "1"],
27
                         max_wait_seconds=480)
28
    # Test loading a quantized checkpoint
29
30
    compare_two_settings("neuralmagic/Qwen2-1.5B-Instruct-FP8", [],
                         ["--cpu-offload-gb", "1"],
31
                         max_wait_seconds=480)
32
33
34
35


@pytest.mark.skipif(not is_quant_method_supported("gptq_marlin"),
                    reason="gptq_marlin is not supported on this GPU type.")
36
37
38
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')
39
40
    # Test GPTQ Marlin
    compare_two_settings("Qwen/Qwen2-1.5B-Instruct-GPTQ-Int4", [],
41
42
                         ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
43
44
45
    # Test GPTQ
    compare_two_settings("Qwen/Qwen2-1.5B-Instruct-GPTQ-Int4",
                         ["--quantization", "gptq"],
46
47
                         ["--quantization", "gptq", "--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
48
49
50
51


@pytest.mark.skipif(not is_quant_method_supported("awq_marlin"),
                    reason="awq_marlin is not supported on this GPU type.")
52
53
54
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')
55
56
    # Test AWQ Marlin
    compare_two_settings("Qwen/Qwen2-1.5B-Instruct-AWQ", [],
57
58
                         ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
59
60
61
    # Test AWQ
    compare_two_settings("Qwen/Qwen2-1.5B-Instruct-AWQ",
                         ["--quantization", "awq"],
62
63
                         ["--quantization", "awq", "--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
64
65
66
67


@pytest.mark.skipif(not is_quant_method_supported("gptq_marlin"),
                    reason="gptq_marlin is not supported on this GPU type.")
68
69
70
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')
71
72
    # Test wNa16
    compare_two_settings("nm-testing/tinyllama-oneshot-w4a16-channel-v2", [],
73
74
                         ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
75
76
    # Test w4a16_marlin24
    compare_two_settings("nm-testing/llama7b-one-shot-2_4-w4a16-marlin24-t",
77
78
                         [], ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
79
80
81
    # Test w8a8
    compare_two_settings(
        "nm-testing/tinyllama-oneshot-w8w8-test-static-shape-change", [],
82
83
        ["--cpu-offload-gb", "1"],
        max_wait_seconds=480)