diff --git a/tests/compile/test_compiler_interface.py b/tests/compile/test_compiler_interface.py new file mode 100644 index 0000000000..a54f2a1056 --- /dev/null +++ b/tests/compile/test_compiler_interface.py @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project + +from pathlib import Path +from unittest.mock import MagicMock, patch + +import pytest + +from vllm.compilation.compiler_interface import InductorStandaloneAdaptor + + +@pytest.mark.parametrize("save_format", ["binary", "unpacked"]) +def test_inductor_standalone_load_uses_current_cache_dir( + tmp_path: Path, + save_format: str, +): + old_cache_dir = tmp_path / "old" + new_cache_dir = tmp_path / "new" + key = "artifact_shape_None_subgraph_0" + + adaptor = InductorStandaloneAdaptor(save_format=save_format) + adaptor.initialize_cache(str(new_cache_dir)) + + # Simulate a handle persisted before the cache directory was relocated. + handle = (key, str(old_cache_dir / key)) + + with ( + patch( + "torch._inductor.CompiledArtifact.load", + return_value=MagicMock(), + ) as load_mock, + patch( + "torch._inductor.compile_fx.graph_returns_tuple", + return_value=True, + ), + ): + adaptor.load( + handle=handle, + graph=MagicMock(), + example_inputs=[], + graph_index=0, + compile_range=MagicMock(), + ) + + load_mock.assert_called_once_with( + path=str(new_cache_dir / key), + format=save_format, + ) diff --git a/vllm/compilation/compiler_interface.py b/vllm/compilation/compiler_interface.py index 394799ab87..a297b0ed95 100644 --- a/vllm/compilation/compiler_interface.py +++ b/vllm/compilation/compiler_interface.py @@ -418,7 +418,7 @@ class InductorStandaloneAdaptor(CompilerInterface): assert isinstance(handle, tuple) assert isinstance(handle[0], str) assert isinstance(handle[1], str) - path = handle[1] + path = os.path.join(self.cache_dir, handle[0]) inductor_compiled_graph = torch._inductor.CompiledArtifact.load( path=path, format=self.save_format )