[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:
@@ -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,
|
||||
)
|
||||
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user