Add a request to the engine's request pool. The request is added to the request pool and will be processed by the scheduler as `engine.step()` is called. The exact scheduling policy is determined by the scheduler. Args: request_id: The unique ID of the r
(
self,
request_id: str,
prompt: Optional[str],
sampling_params: SamplingParams,
prompt_token_ids: Optional[List[int]] = None,
arrival_time: Optional[float] = None,
predict_output_len: int = 0,
)
| 324 | return engine |
| 325 | |
| 326 | def add_request( |
| 327 | self, |
| 328 | request_id: str, |
| 329 | prompt: Optional[str], |
| 330 | sampling_params: SamplingParams, |
| 331 | prompt_token_ids: Optional[List[int]] = None, |
| 332 | arrival_time: Optional[float] = None, |
| 333 | predict_output_len: int = 0, |
| 334 | ) -> None: |
| 335 | """Add a request to the engine's request pool. |
| 336 | |
| 337 | The request is added to the request pool and will be processed by the |
| 338 | scheduler as `engine.step()` is called. The exact scheduling policy is |
| 339 | determined by the scheduler. |
| 340 | |
| 341 | Args: |
| 342 | request_id: The unique ID of the request. |
| 343 | prompt: The prompt string. Can be None if prompt_token_ids is |
| 344 | provided. |
| 345 | sampling_params: The sampling parameters for text generation. |
| 346 | prompt_token_ids: The token IDs of the prompt. If None, we |
| 347 | use the tokenizer to convert the prompts to token IDs. |
| 348 | arrival_time: The arrival time of the request. If None, we use |
| 349 | the current monotonic time. |
| 350 | """ |
| 351 | |
| 352 | if arrival_time is None: |
| 353 | arrival_time = time.monotonic() |
| 354 | if prompt_token_ids is None: |
| 355 | assert prompt is not None |
| 356 | prompt_token_ids = self.tokenizer.encode(prompt) |
| 357 | |
| 358 | # Create the sequences. |
| 359 | block_size = self.cache_config.block_size |
| 360 | seq_id = next(self.seq_counter) |
| 361 | seq = Sequence(seq_id, prompt, prompt_token_ids, block_size, |
| 362 | predict_output_len) |
| 363 | |
| 364 | # Create the sequence group. |
| 365 | seq_group = SequenceGroup(request_id, [seq], sampling_params, |
| 366 | arrival_time, predict_output_len) |
| 367 | |
| 368 | # Add the sequence group to the scheduler. |
| 369 | self.scheduler.add_seq_group(seq_group) |
| 370 | |
| 371 | def abort_request(self, request_id: Union[str, Iterable[str]]) -> None: |
| 372 | """Aborts a request(s) with the given ID. |
no test coverage detected