Skip to content

Call to contributions: refactor output tracing in transformers #43979

Closed

Description

@molbap

Following #43590 that updates 112 models, we want to finish migrating all models to the standardized output collection interface. So, this is a call to contributors to open PRs to link to this meta-issue and learn about the codebase!

Two decorators replace the old manual boilerplate:

  • @capture_outputs: goes on the base model forward. Automatically collects hidden_states/attentions via hooks on submodules declared in _can_record_outputs. Removes the need for explicit output_attentions/output_hidden_states/return_dict handling.
  • @can_return_tuple: goes on wrapper forwards (ForCausalLM, etc.). Handles return_dict only without hook installation.

How to refactor a model

  1. Add _can_record_outputs = {"hidden_states": DecoderLayer, "attentions": Attention} on the PreTrainedModel subclass. Use class references, not strings
  2. Add @capture_outputs on the base model forward (the one with the layer loop)
  3. Add @can_return_tuple on higher-level forwards
  4. Drop output_attentions, output_hidden_states, return_dict from signatures
  5. Remove parameter resolution lines and manual collection loops
  6. Decoder layers return hidden_states directly; attention always returns (attn_output, attn_weights)

You can use llama, mistral, or qwen2 as reference implementations. Modern agents are of some help in this issue, but correctly placing the decorators can be tricky.

Models to update

Please claim one or several models by commenting before starting. One PR per model (or small group of related models) could be ideal, for instance!

As of today here's the remaining list of models:

  • bark
  • beit
  • bit
  • blip_2
  • bloom
  • canine
  • codegen
  • colqwen2
  • cpmant
  • ctrl
  • cvt
  • dab_detr
  • dac
  • data2vec
  • deberta
  • deberta_v2
  • decision_transformer
  • depth_anything
  • depth_pro
  • dinat
  • donut
  • dpr
  • efficientnet
  • encodec
  • falcon
  • falcon_mamba
  • fastspeech2_conformer
  • flaubert
  • flava
  • fnet
  • focalnet
  • fsmt
  • funnel
  • glpn
  • gpt2
  • gpt_neo
  • gpt_neox_japanese
  • gptj
  • granite_speech
  • grounding_dino
  • hgnet_v2
  • hiera
  • hubert
  • ibert
  • imagegpt
  • kyutai_speech_to_text
  • led
  • levit
  • lilt
  • llama4
  • longformer
  • longt5
  • luke
  • lxmert
  • mamba
  • mamba2
  • mask2former
  • maskformer
  • megatron_bert
  • mgp_str
  • mimi
  • mm_grounding_dino
  • mobilenet_v1
  • mobilenet_v2
  • mobilevit
  • mobilevitv2
  • moshi
  • mpnet
  • mpt
  • mra
  • mt5
  • mvp
  • nystromformer
  • omdet_turbo
  • oneformer
  • openai
  • patchtsmixer
  • patchtst
  • perceiver
  • pix2struct
  • poolformer
  • pop2piano
  • prophetnet
  • pvt
  • pvt_v2
  • rag
  • recurrent_gemma
  • reformer
  • regnet
  • rembert
  • resnet
  • roformer
  • rt_detr
  • rwkv
  • seamless_m4t
  • seamless_m4t_v2
  • segformer
  • seggpt
  • sew
  • sew_d
  • speech_encoder_decoder
  • speecht5
  • squeezebert
  • superglue
  • superpoint
  • swiftformer
  • swin
  • swin2sr
  • swinv2
  • t5
  • table_transformer
  • tapas
  • textnet
  • timesformer
  • timm_backbone
  • trocr
  • tvp
  • udop
  • umt5
  • unispeech
  • unispeech_sat
  • univnet
  • upernet
  • vilt
  • vision_encoder_decoder
  • vision_text_dual_encoder
  • visual_bert
  • vitdet
  • vitmatte
  • vits
  • wav2vec2
  • wav2vec2_bert
  • wav2vec2_conformer
  • wavlm
  • xcodec
  • xlm
  • xlnet
  • yoso
  • zamba
  • zoedepth

Activity

  1. Aki-07 commented on Feb 13, 2026

    @Aki-07
    Contributor

    I woud like to claim gpt2

  2. 11happy commented on Feb 13, 2026

    @11happy

    I will work on llama4.
    Thank you : )

  3. akeemlh commented on Feb 13, 2026

    @akeemlh

    I'll work on falcon

  4. beelapranay commented on Feb 14, 2026

    @beelapranay

    i would like to work on fnet and cvt

  5. Aatman09 commented on Feb 14, 2026

    @Aatman09

    I would like to work on vits

  6. nexiouscaliver commented on Feb 14, 2026

    @nexiouscaliver

    I'd like to work on segformer.

  7. nexiouscaliver commented on Feb 14, 2026

    @nexiouscaliver

    I'll work on segformer. Refactoring to use the new @capture_outputs and @can_return_tuple decorators for standardized output collection.

  8. preetam1407 commented on Feb 14, 2026

    @preetam1407
    Contributor

    I'd like to pick squeezebert, T5, speecht5

  9. 83 remaining items

  10. RohanPatil2 commented on Feb 17, 2026

    @RohanPatil2

    Hi @molbap, I would like to claim the rag and grounding_dino model. I see no active PRs for this specific model in the comments. I will submit a PR shortly. Thanks!

  11. 23atharvaS commented on Feb 18, 2026

    @23atharvaS

    Completed and opened PR #44114 for this task (wav2vec2/wav2vec2_conformer/wav2vec2_bert output-collection decorator migration); CI checks are passing.

  12. TaherTadpatri commented on Feb 18, 2026

    @TaherTadpatri

    Hi @molbap I will claim visual_bert.

  13. aman-coder03 commented on Feb 18, 2026

    @aman-coder03

    @TaherTadpatri i have already opened the visual_bert PR, kindly check before claiming

  14. cogniera commented on Feb 18, 2026

    @cogniera

    hi @ArthurZucker I was working on the longt5 model , could you please reopen the issue so I can contribute

  15. Aatman09 commented on Feb 19, 2026

    @Aatman09

    @ArthurZucker could you open the issue , i was working on vit and was going to raise pr today

  16. mmahjoub5 commented on Feb 26, 2026

    @mmahjoub5

    Are these PRs going to be reviewed? @molbap

  17. kulkarni-rohan commented on Mar 14, 2026

    @kulkarni-rohan

    I would like to claim colqwen2 model.

  18. raunakb-stack commented on Mar 15, 2026

    @raunakb-stack

    Hi! I'd like to work on refactoring output tracing for the albert model.
    Is this model still available to claim?

  19. chandan11248 commented on Mar 15, 2026

    @chandan11248

    Hi, I'd like to claim gptj for this refactor. Will open a PR once ready.

  20. added a commit that references this issue on Mar 15, 2026
    af28f25
  21. codybarrett108-pixel commented on Mar 17, 2026

    @codybarrett108-pixel
  22. AbdulAhad1189 commented on Oct 29, 2026

    @AbdulAhad1189

    Hi! I'd like to work on refactoring output tracing for gpt_neo using @capture_outputs and @can_return_tuple. I couldn't find an active claim/PR for it. I'd like to take this one. Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions