[WIP] [Flaubert] Refactor output tracing to decorator-based interface#44116
Open
dtiourine wants to merge 1 commit intohuggingface:mainfrom
Open
[WIP] [Flaubert] Refactor output tracing to decorator-based interface#44116dtiourine wants to merge 1 commit intohuggingface:mainfrom
dtiourine wants to merge 1 commit intohuggingface:mainfrom
Conversation
- Add @capture_outputs to FlaubertModel and @can_return_tuple to wrapper models - Remove manual output_attentions/output_hidden_states/return_dict handling - Always return (attn_output, attn_weights) from MultiHeadAttention - Only record attentions via _can_record_outputs (hidden_states needs FlaubertLayer)
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: flaubert |
This was referenced Apr 29, 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 Flaubert to the @capture_outputs and @can_return_tuple decorator pattern for output handling, as part of #43979.
What does this PR do?
_can_record_outputs = {"attentions": MultiHeadAttention}onFlaubertPreTrainedModel@capture_outputstoFlaubertModel.forward@can_return_tupleto all 6 wrapper model forwardsoutput_attentions,output_hidden_states, andreturn_dictfrom all forward signatureshidden_states/attentionscollection loopsMultiHeadAttention.forwardto always return(attn_output, attn_weights)return_dict=Truetoself.transformer()to ensure the backbone always returns a dict internallyNotes
# Copied fromXLM markers: Several classes/methods are marked as copied from XLM. This PR modifies them but does not update XLM (since I believe this is being migrated separately).Known test failures
3 tests fail due to
output_hidden_statesnot being supported:test_attention_outputstest_hidden_states_outputtest_retain_grad_hidden_states_attentionsFlaubert doesn't have a unified layer class (e.g.
FlaubertLayer). Instead it seems that the layer logic is inline inFlaubertModel.forward, using separateModuleLists for attention, FFN, and layer norms. I couldn't find a single module to hook forhidden_statesin_can_record_outputs.For now I only included
{"attentions": MultiHeadAttention}. Would appreciate feedback on the best approach here. For example, I was considering introducing aFlaubertLayerbut wasn't sure if that was out of scope for this refactor or if there is another preferred pattern.Contributes to #43979 (Flaubert portion)