@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / fe3b9372ad
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 14, 05:30 UTC

[Core] Change `execute_model_with_error_logging()` to be a ctx manager (#27060)

Signed-off-by: Nick Hill <nhill@redhat.com>

Nick Hill committed Oct 16, 2025 at 20:45 UTC fe3b9372adfe968360c6754c15058380ab5e87f1
1 file changed +11 -15
vllm/v1/engine/core.py
+11 -15
@@ -290,14 +290,11 @@ class EngineCore:
290 # (i.e. client-aborted vs stop criteria met).
291 self.scheduler.finish_requests(request_ids, RequestStatus.FINISHED_ABORTED)
292
293 - def execute_model_with_error_logging(
294 - self,
295 - model_fn: Callable[[SchedulerOutput], ModelRunnerOutput],
296 - scheduler_output: SchedulerOutput,
297 - ) -> ModelRunnerOutput:
293 + @contextmanager
294 + def log_error_detail(self, scheduler_output: SchedulerOutput):
295 """Execute the model and log detailed info on failure."""
296 try:
300 - return model_fn(scheduler_output)
297 + yield
298 except Exception as err:
299 # We do not want to catch BaseException here since we're only
300 # interested in dumping info when the exception is due to an
@@ -321,15 +318,16 @@ class EngineCore:
318 if not self.scheduler.has_requests():
319 return {}, False
320 scheduler_output = self.scheduler.schedule()
324 - model_output = self.execute_model_with_error_logging(
325 - self.model_executor.execute_model, # type: ignore
326 - scheduler_output,
327 - )
321 +
322 + with self.log_error_detail(scheduler_output):
323 + model_output = self.model_executor.execute_model(scheduler_output)
324 +
325 + assert isinstance(model_output, ModelRunnerOutput)
326 engine_core_outputs = self.scheduler.update_from_output(
327 scheduler_output, model_output
328 )
329
332 - return (engine_core_outputs, scheduler_output.total_num_scheduled_tokens > 0)
330 + return engine_core_outputs, scheduler_output.total_num_scheduled_tokens > 0
331
332 def post_step(self, model_executed: bool) -> None:
333 if self.use_spec_decode and model_executed:
@@ -386,14 +384,12 @@ class EngineCore:
384
385 # Block until the next result is available.
386 future, scheduler_output = batch_queue.pop()
389 - model_output = self.execute_model_with_error_logging(
390 - lambda _: future.result(), scheduler_output
391 - )
387 + with self.log_error_detail(scheduler_output):
388 + model_output = future.result()
389
390 engine_core_outputs = self.scheduler.update_from_output(
391 scheduler_output, model_output
392 )
396 -
393 return engine_core_outputs, model_executed
394
395 def shutdown(self):