main
py 48 lines 1.33 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 from pathlib import Path
5 from unittest.mock import MagicMock, patch
6
7 import pytest
8
9 from vllm.compilation.compiler_interface import InductorStandaloneAdaptor
10
11
12 @pytest.mark.parametrize("save_format", ["binary", "unpacked"])
13 def test_inductor_standalone_load_uses_current_cache_dir(
14 tmp_path: Path,
15 save_format: str,
16 ):
17 old_cache_dir = tmp_path / "old"
18 new_cache_dir = tmp_path / "new"
19 key = "artifact_shape_None_subgraph_0"
20
21 adaptor = InductorStandaloneAdaptor(save_format=save_format)
22 adaptor.initialize_cache(str(new_cache_dir))
23
24 # Simulate a handle persisted before the cache directory was relocated.
25 handle = (key, str(old_cache_dir / key))
26
27 with (
28 patch(
29 "torch._inductor.CompiledArtifact.load",
30 return_value=MagicMock(),
31 ) as load_mock,
32 patch(
33 "torch._inductor.compile_fx.graph_returns_tuple",
34 return_value=True,
35 ),
36 ):
37 adaptor.load(
38 handle=handle,
39 graph=MagicMock(),
40 example_inputs=[],
41 graph_index=0,
42 compile_range=MagicMock(),
43 )
44
45 load_mock.assert_called_once_with(
46 path=str(new_cache_dir / key),
47 format=save_format,
48 )