[Frontend][torch.compile] CompilationConfig Overhaul (#20283): name change compilation level to compilation mode, deprecation compilation level (#26355)

Signed-off-by: morrison-turnansky <mturnans@redhat.com>
Signed-off-by: Morrison Turnansky <mturnans@redhat.com>
Co-authored-by: Luka Govedič <ProExpertProg@users.noreply.github.com>
This commit is contained in:
Morrison Turnansky
2025-10-15 02:51:16 +00:00
committed by GitHub
co-authored by Luka Govedič
parent e66d787bce
commit 96b9aa5aa0
42 changed files with 270 additions and 248 deletions
+2 -2
View File
@@ -56,7 +56,7 @@ def make_compiler(compilation_config: CompilationConfig) -> CompilerInterface:
return InductorAdaptor()
else:
assert compilation_config.backend == "eager", (
"Custom backends not supported with CompilationLevel.PIECEWISE"
"Custom backends not supported with CompilationMode.VLLM_COMPILE"
)
logger.debug("Using EagerAdaptor")
@@ -481,7 +481,7 @@ def set_model_tag(tag: str):
class VllmBackend:
"""The compilation backend for `torch.compile` with vLLM.
It is used for compilation level of `CompilationLevel.PIECEWISE`,
It is used for compilation mode of `CompilationMode.VLLM_COMPILE`,
where we customize the compilation.
The major work of this backend is to split the graph into
+1 -1
View File
@@ -575,7 +575,7 @@ class InductorAdaptor(CompilerInterface):
Because it is re-entrant, we always set it (even if entering via Dynamo
and the context was already entered). We might want to revisit if it
should be set at a different level of compilation.
should be set at a different mode of compilation.
This is likely a bug in PyTorch: public APIs should not rely on
manually setting up internal contexts. But we also rely on non-public
+2 -2
View File
@@ -27,8 +27,8 @@ class CompilationCounter:
num_cache_entries_updated: int = 0
# The number of standalone_compile compiled artifacts saved
num_compiled_artifacts_saved: int = 0
# Number of times a model was loaded with CompilationLevel.DYNAMO_AS_IS
dynamo_as_is_count: int = 0
# Number of times a model was loaded with CompilationMode.STOCK_TORCH_COMPILE
stock_torch_compile_count: int = 0
def clone(self) -> "CompilationCounter":
return copy.deepcopy(self)
+5 -5
View File
@@ -18,7 +18,7 @@ from torch._dynamo.symbolic_convert import InliningInstructionTranslator
import vllm.envs as envs
from vllm.compilation.counter import compilation_counter
from vllm.compilation.wrapper import TorchCompileWrapperWithCustomDispatcher
from vllm.config import CompilationLevel, VllmConfig, set_current_vllm_config
from vllm.config import CompilationMode, VllmConfig, set_current_vllm_config
from vllm.logger import init_logger
from vllm.sequence import IntermediateTensors
from vllm.utils import resolve_obj_by_qualname, supports_dynamo
@@ -233,11 +233,11 @@ def _support_torch_compile(
old_init(self, vllm_config=vllm_config, prefix=prefix, **kwargs)
self.vllm_config = vllm_config
enable_compile = enable_if is None or enable_if(vllm_config)
# for CompilationLevel.DYNAMO_AS_IS , the upper level model runner
# for CompilationMode.STOCK_TORCH_COMPILE , the upper level model runner
# will handle the compilation, so we don't need to do anything here.
self.do_not_compile = (
vllm_config.compilation_config.level
in [CompilationLevel.NO_COMPILATION, CompilationLevel.DYNAMO_AS_IS]
vllm_config.compilation_config.mode
in [CompilationMode.NONE, CompilationMode.STOCK_TORCH_COMPILE]
or not supports_dynamo()
or _should_ignore_torch_compile(self.__class__)
or not enable_compile
@@ -247,7 +247,7 @@ def _support_torch_compile(
compilation_counter.num_models_seen += 1
TorchCompileWrapperWithCustomDispatcher.__init__(
self, compilation_level=vllm_config.compilation_config.level
self, compilation_mode=vllm_config.compilation_config.mode
)
cls.__init__ = __init__
+3 -3
View File
@@ -3,7 +3,7 @@
import time
from vllm.config import CompilationConfig, CompilationLevel, VllmConfig
from vllm.config import CompilationConfig, CompilationMode, VllmConfig
from vllm.logger import init_logger
logger = init_logger(__name__)
@@ -18,7 +18,7 @@ def start_monitoring_torch_compile(vllm_config: VllmConfig):
compilation_config: CompilationConfig = vllm_config.compilation_config
path = vllm_config.compile_debug_dump_path()
if compilation_config.level == CompilationLevel.PIECEWISE and path:
if compilation_config.mode == CompilationMode.VLLM_COMPILE and path:
import depyf
path.mkdir(parents=True, exist_ok=True)
@@ -29,7 +29,7 @@ def start_monitoring_torch_compile(vllm_config: VllmConfig):
def end_monitoring_torch_compile(vllm_config: VllmConfig):
compilation_config: CompilationConfig = vllm_config.compilation_config
if compilation_config.level == CompilationLevel.PIECEWISE:
if compilation_config.mode == CompilationMode.VLLM_COMPILE:
logger.info(
"torch.compile takes %.2f s in total", compilation_config.compilation_time
)
+4 -4
View File
@@ -11,7 +11,7 @@ from types import CodeType
import torch
import vllm.envs as envs
from vllm.config import CompilationLevel, CUDAGraphMode, get_current_vllm_config
from vllm.config import CompilationMode, CUDAGraphMode, get_current_vllm_config
from vllm.logger import init_logger
logger = init_logger(__name__)
@@ -31,7 +31,7 @@ class TorchCompileWrapperWithCustomDispatcher:
"""
def __init__(
self, compiled_callable: Callable | None = None, compilation_level: int = 0
self, compiled_callable: Callable | None = None, compilation_mode: int = 0
):
vllm_config = get_current_vllm_config()
self.vllm_config = vllm_config
@@ -72,7 +72,7 @@ class TorchCompileWrapperWithCustomDispatcher:
# subclasses can use this to switch between the custom dispatcher
# and the default Dynamo guard mechanism.
self.use_custom_dispatcher: bool = (
compilation_level >= CompilationLevel.DYNAMO_ONCE
compilation_mode >= CompilationMode.DYNAMO_TRACE_ONCE
)
def aot_compile(self, *args, **kwargs):
@@ -85,7 +85,7 @@ class TorchCompileWrapperWithCustomDispatcher:
return self.compiled_callable.aot_compile((args, kwargs))
def __call__(self, *args, **kwargs):
"""Implement the dispatch logic here, beyond the torch.compile level.
"""Implement the dispatch logic here, beyond the torch.compile mode.
NOTE: this function can have additional arguments beyond the forward
method, for directly dispatching to the compiled code.
"""