Repository navigation
Implement return_hidden_states for the OpenAI API - #6137
Merged
Merged
Conversation
kyle-pena-kuzco
marked this pull request as ready for review
May 9, 2025 05:14
kyle-pena-kuzco
requested review from
ByronHsu,
CatherineSue,
Ying1123,
hnyls2002,
ispobock,
merrymercy and
zhyncs
as code owners
May 9, 2025 05:14
Contributor
Author
|
@zhyncs - let me know if you have any feedback! We'd like to get this feature merged. |
Collaborator
|
@Qiaolin-Yu qiaolin could you take a look plz? |
|
thank you @Qiaolin-Yu @zhaochenyang20 @yinfan98 <3 |
Collaborator
|
will merge it, no need to rebase |
Collaborator
|
nice work @kyle-pena-kuzco |
Contributor
|
@kyle-pena-kuzco May you help resolve the conflicts? Thanks. cc @CatherineSue @ispobock @Qiaolin-Yu |
Contributor
Author
Yes. Starting on that now. i'll comment when completed. |
Contributor
Author
@zhyncs - I've fixed the merge conflicts. |
zhyncs
added a commit
that referenced
this pull request
May 20, 2025
woodx9
pushed a commit
to woodx9/sglang
that referenced
this pull request
Jun 8, 2025
woodx9
pushed a commit
to woodx9/sglang
that referenced
this pull request
Jun 8, 2025
Layssy
pushed a commit
to Layssy/sglang-iaas
that referenced
this pull request
Jun 9, 2025
Layssy
pushed a commit
to Layssy/sglang-iaas
that referenced
this pull request
Jun 9, 2025
xwu-intel
pushed a commit
to xwu-intel/sglang
that referenced
this pull request
Jun 17, 2025
xwu-intel
pushed a commit
to xwu-intel/sglang
that referenced
this pull request
Jun 17, 2025
0826joyce
pushed a commit
to 0826joyce/sglang-perf-opt
that referenced
this pull request
May 19, 2026
0826joyce
pushed a commit
to 0826joyce/sglang-perf-opt
that referenced
this pull request
May 19, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
The native API supports returning hidden states from the model. This PR implements the same feature for OpenAI.
Returning hidden states is important for model verification and diagnostics purposes. Inference providers that use SGLang as a backend route requests that are in the OpenAI format, so if an inference provider would like to do internal diagnostics and verification, it is much more straightforward to simply include
return_hidden_states.This PR also fixes #5761 and adds appropriate test coverage for that bug.
Modifications
Changes were made to
protocol.pyto support thereturn_hidden_statesflag as well as returninghidden_stateson/v1/completionsand/v1/chat/completionsfor both streaming and non-streaming.If no hidden states are requested, the hidden states property is omitted from the response instead of including a null field. That way, the responses are completely backwards compatible.
The adapter was changed to include hidden states in responses when requested.
The dictionary
n_prev_tokenswas not being updated inv1_chat_completionsfor a streaming response, leading the same top logprobs to being repeated for every chunk. This has been fixed as well.Checklist