test_cpu_offload.py 3.64 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


15
16
17
18
19
20
21
@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')


zhuwenwen's avatar
zhuwenwen committed
22
@pytest.mark.skipif(not is_quant_method_supported("fp8") or current_platform.is_rocm(),
23
24
25
                    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
26
    compare_two_settings(os.path.join(models_path_prefix, "meta-llama/Llama-3.2-1B-Instruct"),
27
                         ["--quantization", "fp8"],
28
                         ["--quantization", "fp8", "--cpu-offload-gb", "1"],
29
                         max_wait_seconds=480)
30
    # Test loading a quantized checkpoint
zhuwenwen's avatar
zhuwenwen committed
31
32
33
    # compare_two_settings(os.path.join(models_path_prefix, "neuralmagic/Qwen2-1.5B-Instruct-FP8"), [],
    #                      ["--cpu-offload-gb", "1"],
    #                      max_wait_seconds=480)
34
35


zhuwenwen's avatar
zhuwenwen committed
36
@pytest.mark.skipif(not is_quant_method_supported("gptq_marlin") or current_platform.is_rocm(),
37
38
39
                    reason="gptq_marlin is not supported on this GPU type.")
def test_cpu_offload_gptq():
    # Test GPTQ Marlin
40
    compare_two_settings(os.path.join(models_path_prefix, "Qwen/Qwen2-1.5B-Instruct-GPTQ-Int4"), [],
41
42
                         ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
43
    # Test GPTQ
44
    compare_two_settings(os.path.join(models_path_prefix, "Qwen/Qwen2-1.5B-Instruct-GPTQ-Int4"),
45
                         ["--quantization", "gptq"],
46
47
                         ["--quantization", "gptq", "--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
48
49


zhuwenwen's avatar
zhuwenwen committed
50
@pytest.mark.skipif(not is_quant_method_supported("awq_marlin") or current_platform.is_rocm(),
51
52
53
                    reason="awq_marlin is not supported on this GPU type.")
def test_cpu_offload_awq():
    # Test AWQ Marlin
54
    compare_two_settings(os.path.join(models_path_prefix, "Qwen/Qwen2-1.5B-Instruct-AWQ"), [],
55
56
                         ["--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
57
    # Test AWQ
58
    compare_two_settings(os.path.join(models_path_prefix, "Qwen/Qwen2-1.5B-Instruct-AWQ"),
59
                         ["--quantization", "awq"],
60
61
                         ["--quantization", "awq", "--cpu-offload-gb", "1"],
                         max_wait_seconds=480)
62
63


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