Support output_logits='generation' and output_last_hidden_state in PyTorch backend#4534
Draft
Support output_logits='generation' and output_last_hidden_state in PyTorch backend#4534
output_logits='generation' and output_last_hidden_state in PyTorch backend#4534Conversation
3 tasks
…Torch engine Agent-Logs-Url: https://github.com/InternLM/lmdeploy/sessions/84914fd8-47c1-4c72-80f4-88255925953e Co-authored-by: CUHKSZzxy <46674730+CUHKSZzxy@users.noreply.github.com>
…rity Agent-Logs-Url: https://github.com/InternLM/lmdeploy/sessions/84914fd8-47c1-4c72-80f4-88255925953e Co-authored-by: CUHKSZzxy <46674730+CUHKSZzxy@users.noreply.github.com>
Agent-Logs-Url: https://github.com/InternLM/lmdeploy/sessions/84914fd8-47c1-4c72-80f4-88255925953e Co-authored-by: CUHKSZzxy <46674730+CUHKSZzxy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix logits and last_hidden_state returns for qwen3VL
Support Apr 17, 2026
output_logits='generation' and output_last_hidden_state in PyTorch backend
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 PyTorch engine silently discarded
output_logits='generation'andoutput_last_hidden_staterequests, returningNoneregardless. Onlyoutput_logits='all'withmax_new_tokens=0was supported. This PR enables per-step logit and hidden-state collection during generation.Modification
messages.py: Addout_logits_mode/out_last_hidden_states_modetoSamplingParam; updatefrom_gen_configto pass'generation'mode through (keep'all'restricted tomax_new_tokens=0). AddHistoryHiddenStatesclass (same int16 bit-reinterpretation storage asHistoryLogits) plusall_hidden_states,return_hidden_states,hidden_states_generation_mode,hidden_states, andappend_hidden_statesonSchedulerSequence.engine.py: Addlast_hidden_statefield toInferOutput.model_agent/agent.py: Addhidden_statestoBatchedOutputs; update_async_model_forwardto extract last-position hidden states ('generation') or full-sequence hidden states ('all'); threadreturn_hidden_states/hidden_states_all_modethrough_async_stepand_step_postprocess_with_output.inputs_maker.py: Computereturn_hidden_statesandhidden_states_all_modeflags per batch.engine_loop.py: In_make_infer_outputs, accumulate last-position logits/hidden-states at each step for'generation'mode and emit on finish; handle'all'mode split by sequence length. Includelast_hidden_statein_send_resp.engine_instance.py: Readlast_hidden_statefrom response data and forward toEngineOutput.Use cases (Optional)
Checklist