[Bugfix] Raise VLLMValidationError for non-integer logit_bias keys (#46612)

Signed-off-by: muhammadfawaz1 <135441198+muhammadfawaz1@users.noreply.github.com>
Co-authored-by: Mahad Durrani <114791389+mahadrehmann@users.noreply.github.com>
This commit is contained in:
Muhammad Fawaz
2026-06-30 06:18:59 +00:00
committed by GitHub
co-authored by Mahad Durrani
parent 4236514098
commit 97b5ce5c39
2 changed files with 82 additions and 6 deletions
+25 -6
View File
@@ -385,12 +385,31 @@ class SamplingParams(
repetition_detection: RepetitionDetectionParams | None = None,
) -> "SamplingParams":
if logit_bias is not None:
# Convert token_id to integer
# Clamp the bias between -100 and 100 per OpenAI API spec
logit_bias = {
int(token): min(100.0, max(-100.0, bias))
for token, bias in logit_bias.items()
}
# Fast path uses a dict comprehension; on failure we iterate once
# to identify the exact offending entry for the error message.
try:
logit_bias = {
int(token): min(100.0, max(-100.0, bias))
for token, bias in logit_bias.items()
}
except (ValueError, TypeError):
invalid_keys = []
converted_logit_bias = {}
for token, bias in logit_bias.items():
try:
token_id = int(token)
except (ValueError, TypeError):
invalid_keys.append(token)
continue
converted_logit_bias[token_id] = min(100.0, max(-100.0, bias))
if invalid_keys:
raise VLLMValidationError(
f"logit_bias contains key(s) that cannot be "
f"converted to integer token IDs: {invalid_keys!r}",
parameter="logit_bias",
value=invalid_keys,
) from None
logit_bias = converted_logit_bias
return SamplingParams(
n=1 if n is None else n,