(self)
| 452 | return list(zip(stop_reasons, stop_words)) |
| 453 | |
| 454 | def _get_sampling_config(self) -> tllme.SamplingConfig: |
| 455 | # A map from the SamplingConfig fields of the LLM API to their |
| 456 | # corresponding field names of the Executor of TRT-LLM C++ runtime. |
| 457 | # In sampling, there is no parameter that directly matches 'best_of', |
| 458 | # so outputs must be trimmed during postprocessing. |
| 459 | # | LLM API | TRT-LLM Executor | |
| 460 | # --------------|-----------------|------------------------| |
| 461 | # | Beam search | use_beam_search | beam_width > 1 | |
| 462 | # | Beam search | n | num_return_sequences | |
| 463 | # | Beam search | best_of | beam_width | |
| 464 | # |-------------|-----------------|------------------------| |
| 465 | # | Sampling | use_beam_search | beam_width == 1 | |
| 466 | # | Sampling | n | num_return_sequences | |
| 467 | # | Sampling | best_of | no corresponding param | |
| 468 | fields = {f for f in dir(tllme.SamplingConfig) if not f.startswith("__")} |
| 469 | unmatched_params = [ |
| 470 | "num_return_sequences", |
| 471 | "beam_width", |
| 472 | "n", |
| 473 | "best_of", |
| 474 | "use_beam_search", |
| 475 | ] |
| 476 | llmapi_to_rt_param_map = {f: getattr(self, f) for f in fields if f not in unmatched_params} |
| 477 | if self.use_beam_search: |
| 478 | llmapi_to_rt_param_map["num_return_sequences"] = self.n |
| 479 | llmapi_to_rt_param_map["beam_width"] = self.best_of |
| 480 | else: |
| 481 | llmapi_to_rt_param_map["num_return_sequences"] = self.best_of |
| 482 | llmapi_to_rt_param_map["beam_width"] = 1 |
| 483 | |
| 484 | return tllme.SamplingConfig(**llmapi_to_rt_param_map) |
| 485 | |
| 486 | def _get_output_config(self, is_pytorch_backend: bool = False) -> tllme.OutputConfig: |
| 487 | sampling_param_fields = set(dir(SamplingParams)) |
no outgoing calls