MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / _run_engine

Method _run_engine

fastdeploy/entrypoints/llm.py:519–596  ·  view source on GitHub ↗

运行引擎,并返回结果列表。 Args: use_tqdm (bool, optional): 是否使用tqdm进度条,默认为False。 Returns: list[Dict[str, Any]]: 包含每个请求的结果字典的列表,字典中包含以下键值对: - "text": str, 生成的文本; - "score": float, 得分(可选)。 Raises: 无

(
        self,
        req_ids: list[str],
        use_tqdm: bool,
        topk_logprobs: Optional[int] = None,
        num_prompt_logprobs: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

517 }
518
519 def _run_engine(
520 self,
521 req_ids: list[str],
522 use_tqdm: bool,
523 topk_logprobs: Optional[int] = None,
524 num_prompt_logprobs: Optional[int] = None,
525 ):
526 """
527 运行引擎,并返回结果列表。
528
529 Args:
530 use_tqdm (bool, optional): 是否使用tqdm进度条,默认为False。
531
532 Returns:
533 list[Dict[str, Any]]: 包含每个请求的结果字典的列表,字典中包含以下键值对:
534 - "text": str, 生成的文本;
535 - "score": float, 得分(可选)。
536
537 Raises:
538 无。
539 """
540 # Initialize tqdm.
541
542 if use_tqdm:
543 num_requests = len(req_ids)
544 pbar = tqdm(
545 total=num_requests,
546 desc="Processed prompts",
547 dynamic_ncols=True,
548 postfix=(f"est. speed input: {0:.2f} toks/s, " f"output: {0:.2f} toks/s"),
549 )
550
551 output = [None] * num_requests
552 req_ids = [(pos, req_id) for pos, req_id in enumerate(req_ids)]
553 while num_requests:
554 finished = []
555 for i, (pos, req_id) in enumerate(req_ids):
556 with self.mutex:
557 if req_id not in self.req_output:
558 time.sleep(0.01)
559 continue
560
561 if not self.req_output[req_id].finished:
562 time.sleep(0.01)
563 continue
564
565 result = self.req_output.pop(req_id)
566 result = self.llm_engine.data_processor.process_response(result)
567
568 # filter logprobs
569 if result.outputs.top_logprobs is not None and topk_logprobs is not None:
570 if topk_logprobs == -1:
571 topk_logprobs = self.llm_engine.cfg.model_config.ori_vocab_size
572 result.outputs.logprobs = self._build_sample_logprobs(
573 result.outputs.top_logprobs, topk_logprobs
574 )
575 if result.prompt_logprobs is not None and num_prompt_logprobs is not None:
576 if num_prompt_logprobs == -1:

Callers 3

generateMethod · 0.95
chatMethod · 0.95

Calls 8

popMethod · 0.80
debugMethod · 0.80
sleepMethod · 0.45
process_responseMethod · 0.45
updateMethod · 0.45
closeMethod · 0.45

Tested by 1