| 384 | return |
| 385 | |
| 386 | async def _encode( |
| 387 | self, prompt: Union[str, List[int]], multimodal_params: MultimodalParams, sampling_params: SamplingParams |
| 388 | ): |
| 389 | if isinstance(prompt, str): |
| 390 | if self.enable_multimodal: |
| 391 | assert ( |
| 392 | len(multimodal_params.images + multimodal_params.audios) <= self.args.cache_capacity |
| 393 | ), "too many multimodal items!" |
| 394 | if multimodal_params.audios: |
| 395 | assert self.args.enable_multimodal_audio, "audio multimodal not enabled" |
| 396 | await self._alloc_multimodal_resources(multimodal_params, sampling_params) |
| 397 | prompt_ids = self.tokenizer.encode( |
| 398 | prompt, multimodal_params, add_special_tokens=sampling_params.add_special_tokens |
| 399 | ) |
| 400 | else: |
| 401 | prompt_ids = self.tokenizer.encode(prompt, add_special_tokens=sampling_params.add_special_tokens) |
| 402 | return prompt_ids |
| 403 | |
| 404 | # 这里的校验对多模态不是很充分, to do |
| 405 | if all(isinstance(e, int) for e in prompt): |
| 406 | if not self.enable_multimodal and not self.pd_mode.is_D(): |
| 407 | if all(e < self.vocab_size for e in prompt): |
| 408 | return prompt |
| 409 | else: |
| 410 | raise ValueError("prompt List[int] format contain id > vocab_size") |
| 411 | else: |
| 412 | return prompt |
| 413 | else: |
| 414 | raise ValueError(f"prompt format error, get type{type(prompt)}") |
| 415 | return |
| 416 | |
| 417 | async def _check_and_repair_length(self, prompt_ids: List[int], sampling_params: SamplingParams): |
| 418 | if not prompt_ids: |