test_pass_manager.py 2.54 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
import copy
4
5
6
7

import pytest
import torch

8
9
10
11
12
from vllm.compilation.inductor_pass import (
    CallableInductorPass,
    InductorPass,
    pass_context,
)
13
from vllm.compilation.pass_manager import PostGradPassManager
14
from vllm.config import ModelConfig, VllmConfig
15
from vllm.config.utils import Range
16
17


18
# dummy custom pass that doesn't inherit
19
20
21
22
def simple_callable(graph: torch.fx.Graph):
    pass


23
24
# Should fail to add directly to the pass manager
def test_bad_callable():
25
    config = VllmConfig()
26
27
28
29
30

    pass_manager = PostGradPassManager()
    pass_manager.configure(config)

    with pytest.raises(AssertionError):
31
        pass_manager.add(simple_callable)
32
33
34
35
36
37


# Pass that inherits from InductorPass
class ProperPass(InductorPass):
    def __call__(self, graph: torch.fx.graph.Graph) -> None:
        pass
38
39
40


@pytest.mark.parametrize(
41
    "callable",
Jovan Sardinha's avatar
Jovan Sardinha committed
42
    [
43
44
45
        ProperPass(),
        # Can also wrap callables in CallableInductorPass for compliance
        CallableInductorPass(simple_callable),
46
        CallableInductorPass(simple_callable, InductorPass.hash_source(__file__)),
Jovan Sardinha's avatar
Jovan Sardinha committed
47
48
    ],
)
49
def test_pass_manager_uuid(callable):
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    # Set the pass context as PassManager uuid uses it
    with pass_context(Range(start=1, end=8)):
        # Some passes need dtype to be set
        config = VllmConfig(model_config=ModelConfig(dtype=torch.bfloat16))

        pass_manager = PostGradPassManager()
        pass_manager.configure(config)

        # Check that UUID is different if the same pass is added 2x
        pass_manager.add(callable)
        uuid1 = pass_manager.uuid()
        pass_manager.add(callable)
        uuid2 = pass_manager.uuid()
        assert uuid1 != uuid2

        # UUID should be the same as the original one,
        # as we constructed in the same way.
        pass_manager2 = PostGradPassManager()
        pass_manager2.configure(config)
        pass_manager2.add(callable)
        assert uuid1 == pass_manager2.uuid()

        # UUID should be different due to config change
        config2 = copy.deepcopy(config)
        config2.compilation_config.pass_config.fuse_norm_quant = (
            not config2.compilation_config.pass_config.fuse_norm_quant
        )
        config2.compilation_config.pass_config.fuse_act_quant = (
            not config2.compilation_config.pass_config.fuse_act_quant
        )
        pass_manager3 = PostGradPassManager()
        pass_manager3.configure(config2)
        pass_manager3.add(callable)
        assert uuid1 != pass_manager3.uuid()