Skip to content

how to return hidden_states? #4414

Open

Description

@lss15151161

use gather_context_logits and gather_generation_logits can help to return logits. but how to return hidden_states? plz help, thx

Activity

  1. brb-nv commented on May 29, 2025

    @brb-nv
    Collaborator

    I don't think there's a way to return intermediate hidden_states right now. @hchings, can you please confirm?

  2. added
    triagedIssue has been triaged by maintainers
    on May 29, 2025
  3. hchings commented on May 29, 2025

    @hchings
    Collaborator

    I don't think we have flags for that as @brb-nv mentioned in either TRT or PyTorch backend.

    @lss15151161 you could share more context on use cases for our team's awareness. Thanks. cc @laikhtewari

  4. github-actions commented on Jun 18, 2025

    @github-actions

    Issue has not received an update in over 14 days. Adding stale label.

  5. xxchauncey commented on Jun 26, 2025

    @xxchauncey

    same problem, hidden_states for additional lm_head needed.

  6. FateForever0222 commented on Dec 15, 2025

    @FateForever0222

    same problem, do we now support returning hidden states? 🙏 @hchings

  7. hchings commented on Jan 9, 2026

    @hchings
    Collaborator

    Currently, we don't. @FateForever0222 @xxchauncey - is the ask to be able to get the hidden state of any modules/layer, or just the llm_haed?

  8. CASHADEr commented on Feb 24, 2026

    @CASHADEr

    same problem, I need the last hidden states before logits since I don't need the generate stage

  9. hous-lab commented on Aug 7, 2026

    @hous-lab

    Hi all — I've been working on deploying a VLA model (Orion, ICCV'25 autonomous driving) with TensorRT-LLM and encountered the same need for full hidden_states export.

    I've opened PR #17420 with a complete example showing two solutions:

    Solution A (TRT backend, v0.7–v0.21): Insert hidden_states.mark_output('full_hidden_states', ...) before gather_last_token_logits. Verified in production: hidden_states CosSim=0.9994 (INT8), end-to-end plan_L2=0.686.

    Solution B (PyTorch backend, v1.x): In DecoderModelForCausalLM.forward, attach the raw 3D tensor from self.model() before LogitsProcessor compresses it — works with additional_model_outputs=["hidden_states"].

    The key insight is that VLA models need the complete 3D [batch, seq_len, hidden_dim] tensor (at a specific token position like a "waypoint" token), not just the last token. This is different from standard LLM interpretability use cases.

    Would love feedback from @hchings and the team on the preferred integration approach!

  10. added 4 commits that reference this issue on Aug 8, 2026
    329ffd2
    94421d4
    7ecfc46
    d5deab9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions