[Frontend] Move warmup into Renderer (#36482)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
Cyrus Leung
2026-03-09 06:03:21 -07:00
committed by GitHub
parent b0906d8b02
commit 3ec2115015
4 changed files with 60 additions and 158 deletions
+50
View File
@@ -158,6 +158,56 @@ class BaseRenderer(ABC, Generic[_T]):
if self._mm_cache_stats is not None:
self._mm_cache_stats.reset = True
def warmup(self, chat_params: ChatParams) -> None:
"""
Warm up this renderer to avoid first-request latency.
For chat requests:
- Jinja2 template compilation
For multi-modal requests:
- Importing libraries such as librosa triggers JIT compilation.
"""
try:
logger.info("Warming up chat template processing...")
start_time = time.perf_counter()
self.render_chat([[{"role": "user", "content": "warmup"}]], chat_params)
elapsed = time.perf_counter() - start_time
logger.info("Chat template warmup completed in %.3fs", elapsed)
except Exception:
logger.exception("Chat template warmup failed")
if self.mm_processor:
from vllm.multimodal.processing import TimingContext
model_config = self.model_config
mm_config = model_config.get_multimodal_config()
processor = self.mm_processor
mm_limits = processor.info.allowed_mm_limits
try:
logger.info("Warming up multi-modal processing...")
start_time = time.perf_counter()
processor_inputs = processor.dummy_inputs.get_dummy_processor_inputs(
seq_len=model_config.max_model_len,
mm_counts=dict.fromkeys(mm_limits, 1),
mm_options=mm_config.limit_per_prompt,
)
_ = processor.apply(
processor_inputs,
timing_ctx=TimingContext(enabled=False),
)
elapsed = time.perf_counter() - start_time
logger.info("Multi-modal warmup completed in %.3fs", elapsed)
except Exception:
logger.exception("Multi-modal warmup failed")
finally:
self.clear_mm_cache()
def shutdown(self) -> None:
mm_processor_cache = self.mm_processor_cache
if mm_processor_cache is not None: