test_pipeline_parallel.py 3.24 KB
Newer Older
1
2
3
4
5
6
7
"""
WARNING: This test runs in both single-node (4 GPUs) and multi-node
 (2 node with 2 GPUs each) modes. If the test only uses 2 GPUs, it is
 important to set the distributed backend to "mp" to avoid Ray scheduling
 all workers in a node other than the head node, which can cause the test
 to fail.
"""
8
9
import os

10
11
import pytest

12
from ..utils import compare_two_settings, fork_new_process_for_each_test
13

14
15
VLLM_MULTI_NODE = os.getenv("VLLM_MULTI_NODE", "0") == "1"

16

17
@pytest.mark.parametrize(
18
19
20
21
22
23
24
25
26
27
28
29
    "TP_SIZE, PP_SIZE, EAGER_MODE, CHUNKED_PREFILL, MODEL_NAME, DIST_BACKEND",
    [
        (2, 2, 0, 1, "meta-llama/Meta-Llama-3-8B", "ray"),
        (2, 2, 1, 0, "meta-llama/Meta-Llama-3-8B", "ray"),
        (1, 3, 0, 0, "meta-llama/Meta-Llama-3-8B", "ray"),
        (1, 4, 0, 1, "meta-llama/Meta-Llama-3-8B", "ray"),
        (1, 4, 1, 0, "meta-llama/Meta-Llama-3-8B", "ray"),
        (2, 2, 0, 1, "meta-llama/Meta-Llama-3-8B", "mp"),
        (2, 2, 1, 0, "meta-llama/Meta-Llama-3-8B", "mp"),
        (1, 3, 0, 0, "meta-llama/Meta-Llama-3-8B", "mp"),
        (1, 4, 0, 1, "meta-llama/Meta-Llama-3-8B", "mp"),
        (1, 4, 1, 0, "meta-llama/Meta-Llama-3-8B", "mp"),
30
    ])
31
@fork_new_process_for_each_test
32
33
34
35
36
def test_compare_tp(TP_SIZE, PP_SIZE, EAGER_MODE, CHUNKED_PREFILL, MODEL_NAME,
                    DIST_BACKEND):
    if VLLM_MULTI_NODE and DIST_BACKEND == "mp":
        pytest.skip("Skipping multi-node pipeline parallel test for "
                    "multiprocessing distributed backend")
37

38
    pp_args = [
39
40
        # use half precision for speed and memory savings in CI environment
        "--dtype",
41
        "float16",
42
43
44
45
46
        "--pipeline-parallel-size",
        str(PP_SIZE),
        "--tensor-parallel-size",
        str(TP_SIZE),
        "--distributed-executor-backend",
47
        DIST_BACKEND,
48
    ]
49
50
51
52
53
54
55
56
57
58
59

    # compare without pipeline parallelism
    # NOTE: use mp backend for TP
    # PP tests might involve multiple nodes, and ray might
    #  schedule all workers in a node other than the head node,
    #  which can cause the test to fail.
    tp_args = [
        # use half precision for speed and memory savings in CI environment
        "--dtype",
        "bfloat16",
        "--tensor-parallel-size",
60
        str(max(TP_SIZE, 2)),  # We only use 2 GPUs in the CI.
61
62
63
        "--distributed-executor-backend",
        "mp",
    ]
64
    if CHUNKED_PREFILL:
65
66
        pp_args.append("--enable-chunked-prefill")
        tp_args.append("--enable-chunked-prefill")
67
    if EAGER_MODE:
68
69
70
        pp_args.append("--enforce-eager")
        tp_args.append("--enforce-eager")

71
    compare_two_settings(MODEL_NAME, pp_args, tp_args)
72
73
74
75
76
77
78
79
80


@pytest.mark.parametrize("PP_SIZE, MODEL_NAME", [
    (2, "JackFram/llama-160m"),
])
@pytest.mark.parametrize("ATTN_BACKEND", [
    "FLASH_ATTN",
    "FLASHINFER",
])
81
@fork_new_process_for_each_test
82
83
84
85
86
87
88
89
def test_pp_cudagraph(PP_SIZE, MODEL_NAME, ATTN_BACKEND):
    cudagraph_args = [
        # use half precision for speed and memory savings in CI environment
        "--dtype",
        "float16",
        "--pipeline-parallel-size",
        str(PP_SIZE),
        "--distributed-executor-backend",
90
        "mp",
91
92
93
94
95
96
    ]
    os.environ["VLLM_ATTENTION_BACKEND"] = ATTN_BACKEND

    eager_args = cudagraph_args + ["--enforce-eager"]

    compare_two_settings(MODEL_NAME, eager_args, cudagraph_args)