[Bugfix] Fix standalone torch.compile cache loading after relocation (#52142)

Signed-off-by: jungjiyu <libraryofjiyu@gmail.com> Co-authored-by: Misha Goin <mgoin64@gmail.com>

Jung Jiyu committed Sep 30, 2026 at 01:53 UTC cb4f016c5d02c9d483e6e3f1702d51da239b1a9b
2 files changed +49 -1
tests/compile/test_compiler_interface.py new
+48
@@ -0,0 +1,48 @@
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 + )
vllm/compilation/compiler_interface.py
+1 -1
@@ -418,7 +418,7 @@ class InductorStandaloneAdaptor(CompilerInterface):
418 assert isinstance(handle, tuple)
419 assert isinstance(handle[0], str)
420 assert isinstance(handle[1], str)
421 - path = handle[1]
421 + path = os.path.join(self.cache_dir, handle[0])
422 inductor_compiled_graph = torch._inductor.CompiledArtifact.load(
423 path=path, format=self.save_format
424 )