[Bugfix] Reject negative token ids as out-of-vocabulary (#51795)

Signed-off-by: Junhao Shen <junshen@nvidia.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Vadim Gimpelson <156319763+vadiklyutiy@users.noreply.github.com>
This commit is contained in:
Junhao Shen
2026-08-14 01:07:29 +00:00
committed by GitHub
co-authored by Claude Opus 4.8 Vadim Gimpelson
parent 827a2af806
commit b216db3ed0
2 changed files with 21 additions and 0 deletions
@@ -89,6 +89,17 @@ def hf_model(hf_runner):
yield hf_model
@pytest.mark.asyncio
@pytest.mark.parametrize("model_name", [MODEL_NAME])
async def test_negative_token_ids(client: openai.AsyncOpenAI, model_name: str):
# A negative token id is out of vocabulary just like an over-large one, but
# is not caught by the upper-bound check. Unlike the OpenAI completion
# schema, the pooling schema does not constrain token ids to be
# non-negative, so the request reaches the shared engine-level validation.
with pytest.raises(openai.BadRequestError, match=".*out of vocabulary.*"):
await client.embeddings.create(model=model_name, input=[-1])
@pytest.mark.asyncio
@pytest.mark.parametrize("model_name", [MODEL_NAME])
async def test_basic(