[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>
This commit is contained in:
Jung Jiyu
2026-09-29 12:53:20 -04:00
committed by GitHub
co-authored by Misha Goin
parent cd94b21264
commit cb4f016c5d
2 changed files with 49 additions and 1 deletions
+48
View File
@@ -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,
)
+1 -1
View File
@@ -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
)