[Bugfix][Compile] Replace Transformers AOT caching with graph caching (#58918)
Signed-off-by: fangyao fan <2281693949@qq.com> Signed-off-by: Taimys <ffy2281693949@gmail.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Taimys <ffy2281693949@gmail.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
co-authored by
Taimys
Harry Mellor
parent
3f550129e8
commit
c068db0e1d
@@ -18,7 +18,7 @@ def test_inductor_standalone_load_uses_current_cache_dir(
|
||||
new_cache_dir = tmp_path / "new"
|
||||
key = "artifact_shape_None_subgraph_0"
|
||||
|
||||
adaptor = InductorStandaloneAdaptor(save_format=save_format)
|
||||
adaptor = InductorStandaloneAdaptor(use_aot_compile=True, save_format=save_format)
|
||||
adaptor.initialize_cache(str(new_cache_dir))
|
||||
|
||||
# Simulate a handle persisted before the cache directory was relocated.
|
||||
@@ -46,3 +46,86 @@ def test_inductor_standalone_load_uses_current_cache_dir(
|
||||
path=str(new_cache_dir / key),
|
||||
format=save_format,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("raises", [False, True])
|
||||
def test_opt_out_functorch_config_is_scoped(monkeypatch, raises):
|
||||
from contextlib import nullcontext
|
||||
|
||||
import torch
|
||||
|
||||
from vllm.compilation.compiler_interface import (
|
||||
get_inductor_factors,
|
||||
set_functorch_config,
|
||||
)
|
||||
|
||||
config = torch._functorch.config
|
||||
monkeypatch.setenv("VLLM_USE_MEGA_AOT_ARTIFACT", "1")
|
||||
from vllm.envs import disable_envs_cache
|
||||
|
||||
disable_envs_cache()
|
||||
with config.patch(bundled_autograd_cache=True):
|
||||
error = pytest.raises(RuntimeError, match="probe") if raises else nullcontext()
|
||||
with error, set_functorch_config(use_aot_compile=False):
|
||||
assert config.bundled_autograd_cache is False
|
||||
if raises:
|
||||
raise RuntimeError("probe")
|
||||
assert config.bundled_autograd_cache is True
|
||||
original = type(config).save_config_portable
|
||||
observed = []
|
||||
|
||||
def observe(module):
|
||||
if module is config:
|
||||
observed.append(config.bundled_autograd_cache)
|
||||
return original(module)
|
||||
|
||||
with patch.object(type(config), "save_config_portable", new=observe):
|
||||
get_inductor_factors(use_aot_compile=False)
|
||||
assert observed == [False]
|
||||
assert config.bundled_autograd_cache is True
|
||||
|
||||
|
||||
def test_opt_out_ignores_existing_direct_cache_index(tmp_path, monkeypatch):
|
||||
import builtins
|
||||
|
||||
from vllm.compilation.backends import CompilerManager
|
||||
from vllm.config import CompilationConfig, CompilationMode
|
||||
from vllm.config.utils import Range
|
||||
from vllm.envs import disable_envs_cache
|
||||
|
||||
monkeypatch.setenv("VLLM_USE_STANDALONE_COMPILE", "1")
|
||||
disable_envs_cache()
|
||||
cache = tmp_path / "rank_0_0" / "decoder"
|
||||
cache.mkdir(parents=True)
|
||||
index = cache / "vllm_compile_cache.py"
|
||||
index.write_text("old index must not be read")
|
||||
manager = CompilerManager(
|
||||
CompilationConfig(mode=CompilationMode.VLLM_COMPILE), use_aot_compile=False
|
||||
)
|
||||
real_open = builtins.open
|
||||
reads = []
|
||||
|
||||
def check_open(path, *args, **kwargs):
|
||||
if str(path) == str(index):
|
||||
reads.append(path)
|
||||
raise AssertionError("read old index")
|
||||
return real_open(path, *args, **kwargs)
|
||||
|
||||
with (
|
||||
patch.object(manager.compiler, "initialize_cache"),
|
||||
patch("builtins.open", side_effect=check_open),
|
||||
):
|
||||
manager.initialize_cache(str(cache), prefix="decoder")
|
||||
assert Path(manager.cache_file_path) == index
|
||||
assert reads == []
|
||||
compile_range = Range(1, 8)
|
||||
manager.cache[(compile_range, 0, manager.compiler.name)] = {
|
||||
"graph_handle": ("old", "unused"),
|
||||
"cache_key": "old",
|
||||
}
|
||||
with patch.object(
|
||||
manager.compiler, "load", side_effect=AssertionError("direct load")
|
||||
) as load:
|
||||
assert manager.load(MagicMock(), [], 0, compile_range) is None
|
||||
load.assert_not_called()
|
||||
assert index.read_text() == "old index must not be read"
|
||||
|
||||
Reference in New Issue
Block a user