-
-
Notifications
You must be signed in to change notification settings - Fork 15k
[Frontend] Add sampling parameters to Responses API #32609
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
chaunceyjiang
merged 5 commits into
vllm-project:main
from
DanielMe:add-sampling-parameters-to-responses
Feb 3, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8eb2f24
[Frontend] Add core sampling parameters to Responses API
91fcfae
Merge branch 'main' into add-sampling-parameters-to-responses
DanielMe c41ee2c
Merge branch 'main' into add-sampling-parameters-to-responses
DanielMe 8be34d4
Merge branch 'main' into add-sampling-parameters-to-responses
DanielMe bb8bfaf
Merge branch 'main' into add-sampling-parameters-to-responses
DanielMe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
tests/entrypoints/openai/responses/test_sampling_params.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| """Unit tests for ResponsesRequest.to_sampling_params() parameter mapping.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from vllm.entrypoints.openai.responses.protocol import ResponsesRequest | ||
|
|
||
|
|
||
| class TestResponsesRequestSamplingParams: | ||
| """Test that ResponsesRequest correctly maps parameters to SamplingParams.""" | ||
|
|
||
| def test_basic_sampling_params(self): | ||
| """Test basic sampling parameters are correctly mapped.""" | ||
| request = ResponsesRequest( | ||
| model="test-model", | ||
| input="test input", | ||
| temperature=0.8, | ||
| top_p=0.95, | ||
| top_k=50, | ||
| max_output_tokens=100, | ||
| ) | ||
|
|
||
| sampling_params = request.to_sampling_params(default_max_tokens=1000) | ||
|
|
||
| assert sampling_params.temperature == 0.8 | ||
| assert sampling_params.top_p == 0.95 | ||
| assert sampling_params.top_k == 50 | ||
| assert sampling_params.max_tokens == 100 | ||
|
|
||
| def test_extra_sampling_params(self): | ||
| """Test extra sampling parameters are correctly mapped.""" | ||
| request = ResponsesRequest( | ||
| model="test-model", | ||
| input="test input", | ||
| repetition_penalty=1.2, | ||
| seed=42, | ||
| stop=["END", "STOP"], | ||
| ignore_eos=True, | ||
| vllm_xargs={"custom": "value"}, | ||
| ) | ||
|
|
||
| sampling_params = request.to_sampling_params(default_max_tokens=1000) | ||
|
|
||
| assert sampling_params.repetition_penalty == 1.2 | ||
| assert sampling_params.seed == 42 | ||
| assert sampling_params.stop == ["END", "STOP"] | ||
| assert sampling_params.ignore_eos is True | ||
| assert sampling_params.extra_args == {"custom": "value"} | ||
|
|
||
| def test_stop_string_conversion(self): | ||
| """Test that single stop string is converted to list.""" | ||
| request = ResponsesRequest( | ||
| model="test-model", | ||
| input="test input", | ||
| stop="STOP", | ||
| ) | ||
|
|
||
| sampling_params = request.to_sampling_params(default_max_tokens=1000) | ||
|
|
||
| assert sampling_params.stop == ["STOP"] | ||
|
|
||
| def test_default_values(self): | ||
| """Test default values for optional parameters.""" | ||
| request = ResponsesRequest( | ||
| model="test-model", | ||
| input="test input", | ||
| ) | ||
|
|
||
| sampling_params = request.to_sampling_params(default_max_tokens=1000) | ||
|
|
||
| assert sampling_params.repetition_penalty == 1.0 # None → 1.0 | ||
| assert sampling_params.stop == [] # Empty list | ||
| assert sampling_params.extra_args == {} # Empty dict | ||
|
|
||
| def test_seed_bounds_validation(self): | ||
| """Test that seed values outside torch.long bounds are rejected.""" | ||
| import torch | ||
| from pydantic import ValidationError | ||
|
|
||
| # Test seed below minimum | ||
| with pytest.raises(ValidationError) as exc_info: | ||
| ResponsesRequest( | ||
| model="test-model", | ||
| input="test input", | ||
| seed=torch.iinfo(torch.long).min - 1, | ||
| ) | ||
| assert "greater_than_equal" in str(exc_info.value).lower() | ||
|
|
||
| # Test seed above maximum | ||
| with pytest.raises(ValidationError) as exc_info: | ||
| ResponsesRequest( | ||
| model="test-model", | ||
| input="test input", | ||
| seed=torch.iinfo(torch.long).max + 1, | ||
| ) | ||
| assert "less_than_equal" in str(exc_info.value).lower() | ||
|
|
||
| # Test valid seed at boundaries | ||
| request_min = ResponsesRequest( | ||
| model="test-model", | ||
| input="test input", | ||
| seed=torch.iinfo(torch.long).min, | ||
| ) | ||
| assert request_min.seed == torch.iinfo(torch.long).min | ||
|
|
||
| request_max = ResponsesRequest( | ||
| model="test-model", | ||
| input="test input", | ||
| seed=torch.iinfo(torch.long).max, | ||
| ) | ||
| assert request_max.seed == torch.iinfo(torch.long).max |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compared to the previous version, these additions make it much more reasonable.
Let's invite others to review this.
/cc @qandrew @yeqcharlotte @DarkLight1337