Refactor GPT-J to use standardized output tracing (#43979)#44066
Open
jayavelubalaji-ai wants to merge 3 commits intohuggingface:mainfrom
Open
Refactor GPT-J to use standardized output tracing (#43979)#44066jayavelubalaji-ai wants to merge 3 commits intohuggingface:mainfrom
jayavelubalaji-ai wants to merge 3 commits intohuggingface:mainfrom
Conversation
Migrate GPT-J from manual boilerplate output collection to the new decorator-based output tracing system: - Add _can_record_outputs to GPTJPreTrainedModel - Add @capture_outputs and @merge_with_config_defaults to GPTJModel.forward - Add @can_return_tuple to GPTJForCausalLM, GPTJForSequenceClassification, and GPTJForQuestionAnswering forwards - Simplify GPTJBlock.forward to return hidden_states directly - Remove output_attentions, output_hidden_states, return_dict params from signatures (now handled by decorators) - Propagate changes to CodeGen via Copied from annotation Net reduction of ~70 lines of boilerplate code.
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: codegen, gptj |
Author
|
Hi @ArthurZucker , Can you please review this |
This was referenced Apr 21, 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.
Migrate GPT-J from manual boilerplate output collection to the new decorator-based output tracing system:
_can_record_outputstoGPTJPreTrainedModel@capture_outputsand@merge_with_config_defaultstoGPTJModel.forward@can_return_tupletoGPTJForCausalLM,GPTJForSequenceClassification, andGPTJForQuestionAnsweringforwardsGPTJBlock.forwardto returnhidden_statesdirectlyoutput_attentions,output_hidden_states,return_dictparams from signatures (now handled by decorators)# Copied fromannotationNet reduction of ~70 lines of boilerplate code.
What does this PR do?
This PR migrates the GPT-J model from manual boilerplate output collection to the new standardized decorator-based output tracing system introduced in #43979.
Before: Each forward method manually resolved
output_attentions,output_hidden_states, andreturn_dictfrom config defaults, maintained accumulator lists (all_hidden_states,all_self_attentions), and conditionally appended outputs in the decoder loop.After: Decorators (
@capture_outputs,@can_return_tuple,@merge_with_config_defaults) and PyTorch forward hooks handle all output collection automatically.GPTJBlock.forwardreturns onlyhidden_states(a single tensor) instead of a tuple, and wrapper model forwards use attribute access on the output object.Changes to
CodeGenBlockwere auto-propagated viamake fix-repothrough the existing# Copied from transformers.models.gptj.modeling_gptj.GPTJBlockannotation.Tests: All 107 GPT-J model tests pass (139 skipped — GPU/Hub dependent, expected on CPU-only).
Fixes #43979 (partial — GPT-J model only)