vllm-engine-step
vllm/vllm/v1/engine/core.py · ef9339e · L710–740 · 固定 commit 上游
这是固定版本源码的只读摘录;可在线阅读,也可通过上游链接查看原文件。
710 def step(self) -> tuple[dict[int, EngineCoreOutputs], bool]:
711 """Schedule, execute, and make output.
712
713 Returns tuple of outputs and a flag indicating whether the model
714 was executed.
715 """
716 # Check for any requests remaining in the scheduler - unfinished,
717 # or finished and not yet removed from the batch.
718 if not self.scheduler.has_requests():
719 return {}, False
720 scheduler_output = self.scheduler.schedule(self._should_throttle_prefills())
721 future = self.model_executor.execute_model(scheduler_output, non_block=True)
722 grammar_output = self.scheduler.get_grammar_bitmask(scheduler_output)
723 with (
724 self.capture_iteration_details(scheduler_output) as iteration_details,
725 self.log_error_detail(scheduler_output),
726 ):
727 model_output = self._wait_for_output(future)
728 if model_output is None:
729 model_output = self.model_executor.sample_tokens(grammar_output)
730
731 # Before processing the model output, process any aborts that happened
732 # during the model execution.
733 self._process_aborts_queue()
734 engine_core_outputs = self.scheduler.update_from_output(
735 scheduler_output, model_output
736 )
737 self._attach_iteration_details(engine_core_outputs, iteration_details)
738 self._attach_weight_version(engine_core_outputs)
739
740 return engine_core_outputs, scheduler_output.total_num_scheduled_tokens > 0