transformers
c5bd76ec - Capture only the projected hidden states in VLM feature extraction (#49594)

Commit
3 days ago
Capture only the projected hidden states in VLM feature extraction (#49594) * Capture only the projected hidden states in VLM feature extraction Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Capture only the needed hidden states in CLIPSeg and PE audio/video Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Index selective hidden-state capture like the full hidden states `output_hidden_states` now takes indices into the hidden states as returned with `output_hidden_states=True` (embeddings at 0, negative indices allowed), so callers pass their existing layer indices and `hidden_states_to_capture` is no longer needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * comments Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Resolve hidden state indices from the config Resolve negative `output_hidden_states` indices up front from `config.num_hidden_layers` (or the recorder's new `num_layers_key`) instead of keeping a rolling window and resolving after the forward. Out of range indices are dropped, and negative indices raise when the config does not define the layer count. - Add `num_hidden_layers` attribute maps to configs that name it differently (`depth`, `num_layers`, `num_stages`, `num_encoder_blocks`) - Fix AlignVision's `num_hidden_layers` to match its block count - Use `num_layers_key="num_layers"` for LongcatFlash, whose `num_hidden_layers` counts attention sublayers - Fix the IndexError when a model captures no hidden states (Mllama) - Key `_CAN_RECORD_REGISTRY` on the model and default to `{}` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Read output_hidden_states from kwargs in Aria and regenerate Mistral Large 4 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * `num_layers_key` -> `num_hidden_layers_key` Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * `_hidden_states_selection` -> `_hidden_states_layers` Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * `_selected_hidden_states` -> `selected_hidden_states` Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> * Move hidden state append helper next to the output capturing hook Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Check for negative index support up front in the hidden states test Resolve negative indices from the hidden states `filter_output_hidden_states` already has, so it no longer depends on the config defining the layer count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Simplify the feature hidden states test check Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Add select_hidden_states decorator and drop the plural vision_feature_layers Set the hidden states a method uses with a decorator instead of in the modeling code. VipLlava now uses `vision_feature_layer` like every other model, with the old name kept as a config alias and a deprecated argument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Fail with a message when requested hidden states are missing Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep auto_docstring last and use select_hidden_states in CLIPSeg Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Narrow the select_hidden_states selection with isinstance Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Remove the None kwargs filter from get_image_features It predates image_sizes being handled explicitly. Also drop the VipLlava deprecation test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Author
Parents
Loading