Refactor resnet to use @capture_outputs / @can_return_tuple output tracing#44019
Open
Sid-V5 wants to merge 1 commit intohuggingface:mainfrom
Open
Refactor resnet to use @capture_outputs / @can_return_tuple output tracing#44019Sid-V5 wants to merge 1 commit intohuggingface:mainfrom
resnet to use @capture_outputs / @can_return_tuple output tracing#44019Sid-V5 wants to merge 1 commit intohuggingface:mainfrom
Conversation
Replace manual `output_hidden_states` / `return_dict` boilerplate with
`@capture_outputs` on the base model and `@can_return_tuple` on wrapper
forwards, following the pattern established in llama/mistral/qwen2.
- Add `_can_record_outputs = {"hidden_states": ResNetStage}` to
`ResNetPreTrainedModel`
- Simplify `ResNetEncoder.forward()` to return a single tensor
- Decorate `ResNetModel.forward()` with `@capture_outputs`
- Decorate `ResNetForImageClassification.forward()` and
`ResNetBackbone.forward()` with `@can_return_tuple`
- Remove explicit `output_hidden_states`, `return_dict` parameter
resolution and manual collection loops
Closes huggingface#43979 (resnet portion)
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: resnet |
This was referenced Apr 23, 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.
Refactored the
resnetmodel to use the standardized output tracing decorators (@capture_outputsand@can_return_tuple) as part of the migrationChanges
modeling_resnet.py@capture_outputs/@can_return_tupleSpecifically:
_can_record_outputs = {"hidden_states": ResNetStage}toResNetPreTrainedModelhooks onResNetStagesubmodules automatically collect hidden states.ResNetModel.forward()with@capture_outputsremoves manualoutput_hidden_states/return_dictparameter resolution and collection loops.ResNetForImageClassification.forward()andResNetBackbone.forward()with@can_return_tuplehandlesreturn_dictconversion without hook installation.ResNetEncoder.forward()now returns a singlehidden_statetensor instead of manually building output tuples/dicts.output_hidden_states,return_dictparameters from internal signatures where they are no longer needed.can_return_tupleandcapture_outputs.Reference implementations
Follows the pattern established in
llama,mistral, andqwen2models as described in #43979.Notes
_can_record_outputsonly maps"hidden_states"(no"attentions"entry needed).ResNetBackboneclass usesBackboneMixinwhich has its own output handling the@can_return_tupledecorator is applied for consistency.Fixes (resnet portion)