fix(frontend): return HTTP 400 for out-of-vocabulary token_ids_logprob (#28088)
Signed-off-by: Ting Sun <suntcrick@gmail.com>
This commit is contained in:
@@ -985,8 +985,9 @@ class TokenizerManager(TokenizerControlMixin, TokenizerManagerScoreMixin):
|
||||
if isinstance(obj, EmbeddingReqInput):
|
||||
self._validate_for_matryoshka_dim(obj)
|
||||
|
||||
# Validate custom logit processor
|
||||
# Validate generation-specific fields
|
||||
if isinstance(obj, GenerateReqInput):
|
||||
self._validate_token_ids_logprob(obj)
|
||||
if (
|
||||
obj.return_hidden_states
|
||||
and not self.server_args.enable_return_hidden_states
|
||||
@@ -1047,6 +1048,26 @@ class TokenizerManager(TokenizerControlMixin, TokenizerManagerScoreMixin):
|
||||
f"Provided dimensions are greater than max embedding dimension: {self.model_config.hidden_size}"
|
||||
)
|
||||
|
||||
def _validate_token_ids_logprob(self, obj: GenerateReqInput) -> None:
|
||||
# Batch requests are split into per-request sub-objects before this
|
||||
# runs (normalize_batch_and_arguments + __getitem__), so the only
|
||||
# legal shape here is the per-request contract of
|
||||
# TokenizedGenerateReqInput.token_ids_logprob: a flat list of ints.
|
||||
token_ids_logprob = obj.token_ids_logprob
|
||||
if not token_ids_logprob:
|
||||
return
|
||||
if not isinstance(token_ids_logprob, list):
|
||||
raise ValueError("token_ids_logprob must be a flat list of integers.")
|
||||
vocab_size = self.model_config.vocab_size
|
||||
for token_id in token_ids_logprob:
|
||||
if not isinstance(token_id, int):
|
||||
raise ValueError("token_ids_logprob must be a flat list of integers.")
|
||||
if token_id < 0 or token_id >= vocab_size:
|
||||
raise ValueError(
|
||||
f"token_ids_logprob contains out-of-vocabulary token id "
|
||||
f"{token_id}; valid range is [0, {vocab_size})."
|
||||
)
|
||||
|
||||
def _validate_input_ids_in_vocab(
|
||||
self, input_ids: Union[List[int], List[List[int]]], vocab_size: int
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user