Skip to content

Add CB API tests on the correct use of max_tokens #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions tests/e2e/test_spyre_cb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"""

import pytest
from spyre_util import (generate_spyre_vllm_output, get_chicken_soup_prompts,
get_spyre_model_list)
from openai import BadRequestError
from spyre_util import (RemoteOpenAIServer, generate_spyre_vllm_output,
get_chicken_soup_prompts, get_spyre_model_list)
from vllm import SamplingParams


Expand Down Expand Up @@ -44,6 +45,64 @@ def test_cb_max_tokens(
monkeypatch=monkeypatch)


@pytest.mark.cb
@pytest.mark.parametrize("cb", [True])
@pytest.mark.parametrize("model", get_spyre_model_list())
@pytest.mark.parametrize("max_model_len", [256])
@pytest.mark.parametrize("max_num_seqs", [2])
@pytest.mark.parametrize(
"backend", [pytest.param("eager", marks=pytest.mark.cpu, id="eager")])
def test__api_cb_rejects_oversized_request(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that an extra _ between test and api?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, does that prevent it from running?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remote_openai_server: RemoteOpenAIServer,
model: str,
backend: str,
cb: bool,
max_model_len: int,
max_num_seqs: int,
):
"""Verify API rejects request that exceed max_model_len with CB enabled"""

client = remote_openai_server.get_client()
overflow_prompt = " ".join(["hi"] * max_model_len)
max_tokens = 10

with pytest.raises(BadRequestError,
match="This model's maximum context length is"):
client.completions.create(
model=model,
prompt=overflow_prompt,
max_tokens=max_tokens,
)


@pytest.mark.cb
@pytest.mark.parametrize("cb", [True])
@pytest.mark.parametrize("model", get_spyre_model_list())
@pytest.mark.parametrize("max_model_len", [256])
@pytest.mark.parametrize("max_num_seqs", [2])
@pytest.mark.parametrize(
"backend", [pytest.param("eager", marks=pytest.mark.cpu, id="eager")])
def test_api_cb_generates_correct_max_tokens(
remote_openai_server: RemoteOpenAIServer,
model: str,
backend: str,
cb: bool,
max_model_len: int,
max_num_seqs: int,
):
"""Verify API generates the correct numbers of tokens with CB enabled"""

client = remote_openai_server.get_client()
max_tokens = 10

response = client.completions.create(model=model,
prompt=get_chicken_soup_prompts(1),
max_tokens=max_tokens,
temperature=0)

assert response.usage.completion_tokens == max_tokens


@pytest.mark.cb
@pytest.mark.spyre
@pytest.mark.xfail # TODO: remove once a spyre-base image supports this
Expand Down
Loading