Repository navigation
Remove many output_attentions and other traced outputs on 100+ models - #43590
Merged
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
2 of 4 tasks
eustlb
pushed a commit
that referenced
this pull request
May 12, 2026
…#43590) * first batch, let's see * propagate changes * fixup broken tests * simplify more models * hack * fix attentions * I'm bullied by the new fix-repo * this one too * fix-repo * ...fix-repo? * change up * propagate changes again * more changes * fixes * revert CLAP to the back burner * more changes * some broken clap stuff * New batch of models * something forgotten? * biiig batch + handle explicit None values for output_attentions in generic.py * make fixup * remove dummy record outputs * batch, with some difficult ones (dpt) * ugly fix * update * fix * propagate changes * some more modifs * fixup * be careful about this stuff * style * fix repo * fix more * loose booleans * missing docstring * fix import * fixing fixing * hacky kosmos2.5... * upgrade * simplifyyy * and another one * propagate many changes * upgraaade * fix * ay * fixes, many * fiiix * more more updates * might slow things down? * fix fix * fiix * fix * fiiix meeeerge confliiiicts * style * modular * modular * small update... * tests broken * remapping a bunch of kwargs to encoder_kwargs to avoid contamination * style * modular mess up * more fixes * fix more things * more fixes * style * address comments 1 * argh * fiiix * broken kosmos2 why * decorators * done * fixup docs, * last fixes? * bring back typing! * modularities * modulaaar * style * fix compile * autodocstringss * The greatest decorator upgrade the great 2026 decorator upheaval update everything fixes? style * fix modular * few fixes * fixup wrong decorators * fix gemma * fix align * revert numba changes * fixup pp v2 modular * remove unnecessary merge with defaults and return tuple + refactor kosmos models * oops * fixup repo * pass kwargs on idefics properly * new should have beens * dang copy pasting is not my strong suite * ... no comment * fixup some pretrained stuff * refactor zamba models properly + fixup gradient ckpting within merged defaults * style * several fixups - gradient ckpting - missing merge defaults - input shape stuff - probably even more * style + fixup * fix repo * interesting * small fixes * fix align and other small fixes * fix repo * this time * p1 * p2 * fix encoder got cache during generate * let's try this * fix * revert higgs * fixup models * fix * that copy is bad * new round of fixes * fixup some backbones * style * fix xlstm training inplace op * fix repo * revert the kwargs renames * wrong decorator application * style * fix defaults for vision args * fix concistency * remove the user requested workaround, always return * style * some type annotations * p1 * p2 * fix repo * readd the workaround * fix git * fix vitpose backbone * fixup * quick fixes * repo * fix * fix these * x clip was implemented so wrong ICANT * clipseg fixups * fix repo * fixup weird hidden states treatment, backbones are inherently already tested --> only need backbone mixin tests * style * fix last tests * change backbones mixin instead with a wrapper always applied to the subclasses * style * force dict * cleanup * missed this one * wow this was nasty * refactor a few models * fixups * readd backbones to common tests * revert gc changes * fix repo * explicit decorators * revert zamba * fixup the unrelated renaming in dino 3 vit * fixup some modular stuff * fixup weird zamba2 workaround * fixup dino stuff * idefics simplifications * small fixes * fix kosmos 2.5 * fixup * fix clvp, same failure as main when fixing the return dict stuff * same fix as in the other pr * fixup some ci stuff * style * revert pr to capturing --------- Co-authored-by: vasqu <[email protected]> Co-authored-by: Anton Vlasjuk <[email protected]>
This was referenced Oct 20, 2026
This was referenced Oct 24, 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.
What does this PR do?
In model additions, we often see old standards not using
check_model_inputs,can_return_tupleand it's often a first review comment/something that can slip through. Doing a wide scan to try to remove all occurrences systematically.Background
Every model used to manually resolve
output_attentions,output_hidden_states, andreturn_dictin eachforward, then collect intermediate outputs in a loop, then convert to tuple at the end. That's ~30 lines of boilerplate per model, reimplemented everywhere with subtle inconsistencies.Two decorators now handle this:
@capture_outputsgoes on the base model forward (the one with the layer loop). It readsoutput_attentions/output_hidden_statesfrom kwargs or config, installs hooks on modules listed in_can_record_outputs, collects intermediate outputs automatically, injects them into theModelOutput, and handlesreturn_dict. The model just needs to declare which module classes produce which outputs (e.g._can_record_outputs = {"hidden_states": DecoderLayer, "attentions": Attention}).@can_return_tuplegoes on wrapper forwards (ForCausalLM,ForSequenceClassification, VLM wrappers) that only needreturn_dictconversion. Wrapper models should not use@capture_outputsto avoid nested hook chains.What changes per model
output_attentions,output_hidden_states,return_dictdropped from forward signatures, replaced by**kwargs: Unpack[TransformersKwargs]all_hidden_states += (hidden_states,)collection loops removed(attn_output, attn_weights)— theif not output_attentions: attn_weights = Noneguard is removed since hooks capture directly from the module output