"vscode:/vscode.git/clone" did not exist on "aa42561e4054f43f41bf0ea564369f5ea3147316"
test_arg_utils.py 3.95 KB
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0

3
4
from argparse import ArgumentTypeError

5
6
import pytest

7
from vllm.config import PoolerConfig
8
from vllm.engine.arg_utils import EngineArgs, nullable_kvs
9
10
11
12
13
14
15
16
17
18
19
20
from vllm.utils import FlexibleArgumentParser


@pytest.mark.parametrize(("arg", "expected"), [
    (None, None),
    ("image=16", {
        "image": 16
    }),
    ("image=16,video=2", {
        "image": 16,
        "video": 2
    }),
21
22
23
24
    ("Image=16, Video=2", {
        "image": 16,
        "video": 2
    }),
25
26
27
28
29
30
31
32
33
])
def test_limit_mm_per_prompt_parser(arg, expected):
    parser = EngineArgs.add_cli_args(FlexibleArgumentParser())
    if arg is None:
        args = parser.parse_args([])
    else:
        args = parser.parse_args(["--limit-mm-per-prompt", arg])

    assert args.limit_mm_per_prompt == expected
34
35


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def test_compilation_config():
    parser = EngineArgs.add_cli_args(FlexibleArgumentParser())

    # default value
    args = parser.parse_args([])
    assert args.compilation_config is None

    # set to O3
    args = parser.parse_args(["-O3"])
    assert args.compilation_config.level == 3

    # set to O 3 (space)
    args = parser.parse_args(["-O", "3"])
    assert args.compilation_config.level == 3

    # set to O 3 (equals)
    args = parser.parse_args(["-O=3"])
    assert args.compilation_config.level == 3

55
56
    # set to string form of a dict
    args = parser.parse_args(["--compilation-config", "{'level': 3}"])
57
58
    assert args.compilation_config.level == 3

59
60
    # set to string form of a dict
    args = parser.parse_args(["--compilation-config={'level': 3}"])
61
62
63
    assert args.compilation_config.level == 3


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def test_prefix_cache_default():
    parser = EngineArgs.add_cli_args(FlexibleArgumentParser())
    args = parser.parse_args([])

    engine_args = EngineArgs.from_cli_args(args=args)
    assert (not engine_args.enable_prefix_caching
            ), "prefix caching defaults to off."

    # with flag to turn it on.
    args = parser.parse_args(["--enable-prefix-caching"])
    engine_args = EngineArgs.from_cli_args(args=args)
    assert engine_args.enable_prefix_caching

    # with disable flag to turn it off.
    args = parser.parse_args(["--no-enable-prefix-caching"])
    engine_args = EngineArgs.from_cli_args(args=args)
    assert not engine_args.enable_prefix_caching


83
84
def test_valid_pooling_config():
    parser = EngineArgs.add_cli_args(FlexibleArgumentParser())
85
86
87
88
    args = parser.parse_args([
        '--override-pooler-config',
        '{"pooling_type": "MEAN"}',
    ])
89
    engine_args = EngineArgs.from_cli_args(args=args)
90
91
    assert engine_args.override_pooler_config == PoolerConfig(
        pooling_type="MEAN", )
92
93


94
95
96
97
98
99
100
101
102
103
@pytest.mark.parametrize(
    ("arg"),
    [
        "image",  # Missing =
        "image=4,image=5",  # Conflicting values
        "image=video=4"  # Too many = in tokenized arg
    ])
def test_bad_nullable_kvs(arg):
    with pytest.raises(ArgumentTypeError):
        nullable_kvs(arg)
104
105


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# yapf: disable
@pytest.mark.parametrize(("arg", "expected", "option"), [
    (None, None, "mm-processor-kwargs"),
    ("{}", {}, "mm-processor-kwargs"),
    (
        '{"num_crops": 4}',
        {
            "num_crops": 4
        },
        "mm-processor-kwargs"
    ),
    (
        '{"foo": {"bar": "baz"}}',
        {
            "foo":
            {
                "bar": "baz"
            }
        },
        "mm-processor-kwargs"
    ),
    (
        '{"cast_logits_dtype":"bfloat16","sequence_parallel_norm":true,"sequence_parallel_norm_threshold":2048}',
        {
            "cast_logits_dtype": "bfloat16",
            "sequence_parallel_norm": True,
            "sequence_parallel_norm_threshold": 2048,
        },
        "override-neuron-config"
    ),
136
])
137
138
# yapf: enable
def test_composite_arg_parser(arg, expected, option):
139
140
141
142
    parser = EngineArgs.add_cli_args(FlexibleArgumentParser())
    if arg is None:
        args = parser.parse_args([])
    else:
143
144
        args = parser.parse_args([f"--{option}", arg])
    assert getattr(args, option.replace("-", "_")) == expected