Skip to content

Refactor codegen model to use @capture_outputs and @can_return_tuple decorators#44046

Closed
ManasVardhan wants to merge 1 commit into
huggingface:mainfrom
ManasVardhan:refactor-codegen-output-tracing
Closed

Refactor codegen model to use @capture_outputs and @can_return_tuple decorators#44046
ManasVardhan wants to merge 1 commit into
huggingface:mainfrom
ManasVardhan:refactor-codegen-output-tracing

Conversation

@ManasVardhan

Copy link
Copy Markdown

What does this PR do?

Refactors the codegen model to use the @capture_outputs and @can_return_tuple decorators, replacing manual output_attentions/output_hidden_states/return_dict handling.

Changes:

  • Add _can_record_outputs dict to CodeGenPreTrainedModel mapping output types to their source modules (hidden_statesCodeGenBlock, attentionsCodeGenAttention)
  • Add @capture_outputs decorator to CodeGenModel.forward
  • Add @can_return_tuple decorator to CodeGenForCausalLM.forward
  • Remove manual output_attentions, output_hidden_states, return_dict parameter handling from forward methods
  • Simplify CodeGenBlock.forward to return only hidden_states (tensor)
  • Remove output_attentions parameter from CodeGenAttention.forward and CodeGenBlock.forward signatures

All 107 codegen model tests pass.

Fixes part of #43979

…decorators

Replace manual output_attentions/output_hidden_states/return_dict handling in
CodeGen model with the @capture_outputs and @can_return_tuple decorators,
following the pattern established in llama and other refactored models.

Changes:
- Add _can_record_outputs dict to CodeGenPreTrainedModel mapping output types
  to their source modules (hidden_states -> CodeGenBlock, attentions -> CodeGenAttention)
- Add @capture_outputs decorator to CodeGenModel.forward
- Add @can_return_tuple decorator to CodeGenForCausalLM.forward
- Remove manual output_attentions, output_hidden_states, return_dict parameter
  handling from forward methods
- Simplify CodeGenBlock.forward to return only hidden_states (tensor)
- Remove output_attentions parameter from CodeGenAttention.forward and
  CodeGenBlock.forward signatures

Part of huggingface#43979
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: codegen

@ManasVardhan

ManasVardhan commented Feb 17, 2026

Copy link
Copy Markdown
Author

Superseded by #44094

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant