2025-02-02 14:58:18 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-11-21 00:44:57 -05:00
|
|
|
import pickle
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import torch
|
|
|
|
|
2025-03-19 19:06:49 -07:00
|
|
|
from vllm.compilation.inductor_pass import CallableInductorPass, InductorPass
|
2024-11-21 00:44:57 -05:00
|
|
|
from vllm.compilation.pass_manager import PostGradPassManager
|
2025-03-19 19:06:49 -07:00
|
|
|
from vllm.config import CompilationConfig
|
2024-11-21 00:44:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
def simple_callable(graph: torch.fx.Graph):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2025-03-19 19:06:49 -07:00
|
|
|
callable_uuid = CallableInductorPass(simple_callable,
|
|
|
|
InductorPass.hash_source(__file__))
|
2024-11-21 00:44:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"works, callable",
|
2025-03-19 19:06:49 -07:00
|
|
|
[
|
|
|
|
(False, simple_callable),
|
|
|
|
(True, callable_uuid),
|
|
|
|
(True, CallableInductorPass(simple_callable)),
|
|
|
|
],
|
|
|
|
)
|
2024-11-21 00:44:57 -05:00
|
|
|
def test_pass_manager(works: bool, callable):
|
|
|
|
config = CompilationConfig().pass_config
|
|
|
|
|
2025-03-19 19:06:49 -07:00
|
|
|
pass_manager = PostGradPassManager()
|
|
|
|
pass_manager.configure(config)
|
|
|
|
|
|
|
|
# Try to add the callable to the pass manager
|
2024-11-21 00:44:57 -05:00
|
|
|
if works:
|
2025-03-19 19:06:49 -07:00
|
|
|
pass_manager.add(callable)
|
2024-11-21 00:44:57 -05:00
|
|
|
pickle.dumps(pass_manager)
|
|
|
|
else:
|
2025-03-19 19:06:49 -07:00
|
|
|
with pytest.raises(AssertionError):
|
|
|
|
pass_manager.add(callable)
|