[UX] Tag torch.compile log lines with the component being compiled (#48133)

Signed-off-by: Francesco Fusco <ffu@zurich.ibm.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Luka Govedič <ProExpertProg@users.noreply.github.com>
This commit is contained in:
Francesco Fusco
2026-09-30 10:34:31 +00:00
committed by GitHub
co-authored by Claude Luka Govedič
parent d71f662606
commit d5ee309314
3 changed files with 79 additions and 27 deletions
+38 -10
View File
@@ -292,7 +292,12 @@ def _try_load_aot_compiled_fn(
Re-raises on failure when ``VLLM_FORCE_AOT_LOAD`` is set.
"""
try:
with monitor_torch_compile(model.vllm_config, is_encoder=model._is_encoder):
with monitor_torch_compile(
model.vllm_config,
is_encoder=model._is_encoder,
tag=getattr(model, "_compile_tag", ""),
announce_start=False,
):
with (
set_current_vllm_config(model.vllm_config),
open(aot_compilation_path, "rb") as f,
@@ -309,8 +314,12 @@ def _try_load_aot_compiled_fn(
with maybe_use_cudagraph_partition_wrapper(model.vllm_config):
loaded_fn._artifacts.compiled_fn.finalize_loading(model.vllm_config)
compilation_counter.num_aot_artifacts_loaded += 1
tag = getattr(model, "_compile_tag", "")
log_prefix = f"[{tag}] " if tag else ""
logger.info(
"Directly load AOT compilation from path %s", aot_compilation_path
"%sDirectly load AOT compilation from path %s",
log_prefix,
aot_compilation_path,
)
return loaded_fn
except Exception as e:
@@ -319,8 +328,11 @@ def _try_load_aot_compiled_fn(
message = "Compile cache file corrupted."
else:
message = str(e)
tag = getattr(model, "_compile_tag", "")
log_prefix = f"[{tag}] " if tag else ""
logger.warning(
"Compiling model again due to a load failure from %s, reason: %s",
"%sCompiling model again due to a load failure from %s, reason: %s",
log_prefix,
aot_compilation_path,
message,
)
@@ -402,6 +414,16 @@ def _support_torch_compile(
compilation_counter.num_models_seen += 1
self.compiled = False
# Capture the active model tag (e.g. "backbone", "eagle_head") so
# later compilation/warmup log lines can identify which component
# they belong to. Mirror VllmBackend's precedence rule
# (`compile_prefix or model_tag`) so log tags line up with the
# cache-dir tag: encoders use the class name, everything else
# falls through to `model_tag`.
from vllm.compilation.backends import model_tag as _current_model_tag
self._compile_tag = (cls.__name__ if is_encoder else "") or _current_model_tag
# Handled by monkeypatching `TorchCompileWithNoGuardsWrapper` into base class
TorchCompileWithNoGuardsWrapper.__init__(
self,
@@ -567,7 +589,7 @@ def _support_torch_compile(
self.aot_compiled_fn = loaded_fn
self.was_aot_compile_fn_loaded_from_disk = True
with (
monitor_profiling_run(),
monitor_profiling_run(tag=self._compile_tag),
maybe_use_cudagraph_partition_wrapper(self.vllm_config),
):
output = self.aot_compiled_fn(self, *args, **kwargs)
@@ -667,7 +689,9 @@ def _support_torch_compile(
self._aot_compilation_path = aot_compilation_path
self._aot_cache_dir = cache_dir
with monitor_torch_compile(
self.vllm_config, is_encoder=self._is_encoder
self.vllm_config,
is_encoder=self._is_encoder,
tag=self._compile_tag,
):
self.aot_compiled_fn = self.aot_compile(*args, **kwargs)
compilation_counter.num_aot_compiles += 1
@@ -675,14 +699,15 @@ def _support_torch_compile(
# AOT artifact.
self.save_aot_compiled_function()
with monitor_profiling_run():
with monitor_profiling_run(tag=self._compile_tag):
output = self.aot_compiled_fn(self, *args, **kwargs)
else:
with monitor_torch_compile(
self.vllm_config,
"torch.compile and initial profiling/warmup "
"%storch.compile and initial profiling/warmup "
"run together took %.2f s in total",
is_encoder=self._is_encoder,
tag=self._compile_tag,
):
output = TorchCompileWithNoGuardsWrapper.__call__(
self, # type: ignore[arg-type]
@@ -706,6 +731,7 @@ def _support_torch_compile(
self.aot_compiled_fn and self._aot_compilation_path and self._aot_cache_dir
)
log_prefix = f"[{self._compile_tag}] " if self._compile_tag else ""
try:
os.makedirs(self._aot_cache_dir, exist_ok=True)
# File saving should be atomic, so we will save to a temporary location
@@ -714,13 +740,15 @@ def _support_torch_compile(
self.aot_compiled_fn.save_compiled_function(tmp_file)
os.replace(tmp_file, self._aot_compilation_path)
compilation_counter.num_aot_artifacts_saved += 1
logger.info_once(
"saved AOT compiled function to %s",
logger.info(
"%ssaved AOT compiled function to %s",
log_prefix,
self._aot_compilation_path,
)
except Exception as e:
logger.warning(
"unable to save AOT compiled function to %s: %s",
"%sunable to save AOT compiled function to %s: %s",
log_prefix,
self._aot_compilation_path,
e,
)