Thanks to visit codestin.com
Credit goes to github.com

Skip to content

🚨 Refactor ViT to updated standards#41693

Merged
yonigozlan merged 62 commits into
huggingface:mainfrom
yonigozlan:refactor-vit
May 8, 2026
Merged

🚨 Refactor ViT to updated standards#41693
yonigozlan merged 62 commits into
huggingface:mainfrom
yonigozlan:refactor-vit

Conversation

@yonigozlan

@yonigozlan yonigozlan commented Oct 17, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR aims at refactoring ViT as part of an effort to standardize vision models in the library, similarly to #41549

Vision Models Refactoring - Chronological Todo List

Total: 74 vision models

Additional multimodal/other modalities refactor:

@yonigozlan yonigozlan requested a review from molbap October 17, 2025 15:05
@yonigozlan

Copy link
Copy Markdown
Contributor Author

Cc @vasqu for attention mask!

@yonigozlan yonigozlan requested a review from vasqu October 17, 2025 15:06
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@vasqu vasqu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking already pretty good to me, I'm just really unsure if we want to have the conversion mapping; would wait for the others on their opinion here

self.q_proj = nn.Linear(config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.qkv_bias)
self.k_proj = nn.Linear(config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.qkv_bias)
self.v_proj = nn.Linear(config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.qkv_bias)
self.o_proj = nn.Linear(config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.qkv_bias)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of renaming here (+ the additional o_proj). Are you sure that we are not breaking already existing models with this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just seen the conversion below, a bit unsure if we want to do this

return context_layer, attention_probs
attn_output = attn_output.reshape(*input_shape, -1).contiguous()
attn_output = self.o_proj(attn_output)
attn_output = nn.functional.dropout(attn_output, p=self.hidden_dropout, training=self.training)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dropout is new no? Shouldnt exist imo

@vasqu vasqu Oct 17, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah looks like it's from the separated module before, nvm - would maybe move this outside the attention tho 🤔 more of a nit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's kind of unusual to have a dropout here, I would prefer to just get rid of it tbh 😅. I saw that SeedOssAttention also use a dropout here in the attention module, but I'm happy to move it outside if we think it makes more sense

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on models that could inherit from ViT then. I don't mind it too much but it might be easier to have the dropout outside; maybe something to look out for later when you work on other models that are dependent on it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pro-setting it outside!

Comment thread src/transformers/models/vit/modeling_vit.py Outdated
Comment on lines 335 to 342
_checkpoint_conversion_mapping = {
"attention.query": "q_proj",
"attention.key": "k_proj",
"attention.value": "v_proj",
"attention.output.dense": "attention.o_proj",
"intermediate.dense": "mlp.fc1",
"output.dense": "mlp.fc2",
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see so we rename stuff on the fly. I'm unsure about this would like an opinion from @zucchini-nlp or @molbap here

@zucchini-nlp zucchini-nlp Oct 20, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, I don't think we should be using key-mapping unless there is a strong reason for it. It usually can cause weird side-effects iwith 3rd party libraries, adapters, trainer classes.

If some frameworks do not use our weight loading, and overwrite it, it'll also raise issues. It was the case for vLLM but we copied the same conversion mapping so the models can still be loaded correctly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, that's annoying. I still think this would be worth it in the long run, we have too many disparities in our vision models implementation, it's hard to understand which models/modules are different or the same as each other. + this would be the occasion to standardize how we write models in transformers between modalities. Right now it seems that vision models have their separate way of implementing attention, mlp, positional embeddings etc. when we could use the same or similar implementations as in language models.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both sides make sense. Changing the keys here creates a difference between the json (external API) and the signatures (internal API), which breaks the Consistent Public Surface we want (and can create issues with external adapters). However, as Yoni says the current implementation is very far from being Standard across the lib, so there's a tension between these two principles.

What I suggest is we go the other way around: I DO want to standardize these keys, but the reason is that the implementations are so wildly different and hard to read. Hence, let's first map the implementations to what exists in language models, and then we have a stronger motive to do on-the-fly conversion.

TL;DR let's move that to another PR and update implementations, then we can change the keys.

@yonigozlan

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

Looking already pretty good to me, I'm just really unsure if we want to have the conversion mapping; would wait for the others on their opinion here

It seems reasonable for v5 imo, and will be well worth the cost in the long run. + @ArthurZucker and @Cyrilvallez are working on a way to make weights conversion on the fly much faster

@vasqu

vasqu commented Oct 17, 2025

Copy link
Copy Markdown
Collaborator

Gotcha, I'd still wait for the opinion of others here but it would indeed make things much easier!

@molbap molbap left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

daang I had published my review yesterday but it disappeared 😩

Comment on lines +64 to +83
class BeitPatchEmbeddings(ViTPatchEmbeddings):
def __init__(self, config):
super().__init__()
image_size, patch_size = config.image_size, config.patch_size

image_size = image_size if isinstance(image_size, collections.abc.Iterable) else (image_size, image_size)
patch_size = patch_size if isinstance(patch_size, collections.abc.Iterable) else (patch_size, patch_size)
patch_shape = (image_size[0] // patch_size[0], image_size[1] // patch_size[1])
self.patch_shape = patch_shape

def forward(self, pixel_values: torch.Tensor) -> torch.Tensor:
num_channels = pixel_values.shape[1]
if num_channels != self.num_channels:
raise ValueError(
"Make sure that the channel dimension of the pixel values match with the one set in the configuration."
)

embeddings = self.projection(pixel_values).flatten(2).transpose(1, 2)

return embeddings

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's like 10 other models with almost identical PatchEmbeddings, that's good, but could we inherit directly the ViT one? It's too bad to have to redefine because of a raise, I'd be in favor of removing it

Comment on lines +73 to +78
if not interpolate_pos_encoding:
if height != self.image_size[0] or width != self.image_size[1]:
raise ValueError(
f"Input image size ({height}*{width}) doesn't match model"
f" ({self.image_size[0]}*{self.image_size[1]})."
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this goes away or is under an Optional and not a hard check, it's easier to inherit

return context_layer, attention_probs
attn_output = attn_output.reshape(*input_shape, -1).contiguous()
attn_output = self.o_proj(attn_output)
attn_output = nn.functional.dropout(attn_output, p=self.hidden_dropout, training=self.training)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pro-setting it outside!

Comment on lines 335 to 342
_checkpoint_conversion_mapping = {
"attention.query": "q_proj",
"attention.key": "k_proj",
"attention.value": "v_proj",
"attention.output.dense": "attention.o_proj",
"intermediate.dense": "mlp.fc1",
"output.dense": "mlp.fc2",
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both sides make sense. Changing the keys here creates a difference between the json (external API) and the signatures (internal API), which breaks the Consistent Public Surface we want (and can create issues with external adapters). However, as Yoni says the current implementation is very far from being Standard across the lib, so there's a tension between these two principles.

What I suggest is we go the other way around: I DO want to standardize these keys, but the reason is that the implementations are so wildly different and hard to read. Hence, let's first map the implementations to what exists in language models, and then we have a stronger motive to do on-the-fly conversion.

TL;DR let's move that to another PR and update implementations, then we can change the keys.

@vasqu

vasqu commented Nov 18, 2025

Copy link
Copy Markdown
Collaborator

I think we can revisit this now @yonigozlan (given the weight converter is now merged into main), oh and #41549 as well

@yonigozlan

Copy link
Copy Markdown
Contributor Author

run-slow: aimv2, audio_spectrogram_transformer, beit, bit, clap, conditional_detr, convnext, convnextv2, cvt, d_fine, dab_detr, data2vec, deit, dinat, dinov2, dinov2_with_registers, dinov3_convnext, dinov3_vit, donut, dpt, eomt, eomt_dinov3, flava, florence2, focalnet, glpn, grounding_dino, hiera, ijepa, lw_detr, maskformer, mgp_str, mm_grounding_dino, pixio, poolformer, pp_doclayout_v2, pp_doclayout_v3, pp_lcnet, pp_lcnet_v3, pp_ocrv5_mobile_rec, pp_ocrv5_server_rec, pvt, pvt_v2, qianfan_ocr, resnet, rt_detr, rt_detr_v2, segformer, seggpt, slanet, swiftformer, swin, swin2sr, swinv2, timesformer, uvdoc, videomae, videomt, vilt, vit, vit_mae, vit_msn, vitdet, vitpose_backbone, vivit, vjepa2, x_clip, yolos

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/aimv2", "models/audio_spectrogram_transformer", "models/beit", "models/bit", "models/clap", "models/conditional_detr", "models/convnext", "models/convnextv2", "models/cvt", "models/d_fine", "models/dab_detr", "models/data2vec", "models/deit", "models/dinat", "models/dinov2", "models/dinov2_with_registers", "models/dinov3_convnext", "models/dinov3_vit", "models/donut", "models/dpt", "models/eomt", "models/eomt_dinov3", "models/flava", "models/florence2", "models/focalnet", "models/glpn", "models/grounding_dino", "models/hiera", "models/ijepa", "models/lw_detr", "models/maskformer", "models/mgp_str", "models/mm_grounding_dino", "models/pixio", "models/poolformer", "models/pp_doclayout_v2", "models/pp_doclayout_v3", "models/pp_lcnet", "models/pp_lcnet_v3", "models/pp_ocrv5_mobile_rec", "models/pp_ocrv5_server_rec", "models/pvt", "models/pvt_v2", "models/qianfan_ocr", "models/resnet", "models/rt_detr", "models/rt_detr_v2", "models/segformer", "models/seggpt", "models/slanet", "models/swiftformer", "models/swin", "models/swin2sr", "models/swinv2", "models/timesformer", "models/uvdoc", "models/videomae", "models/videomt", "models/vilt", "models/vit", "models/vit_mae", "models/vit_msn", "models/vitdet", "models/vitpose_backbone", "models/vivit", "models/vjepa2", "models/x_clip", "models/yolos"]
quantizations: []

@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN df99b36f workflow commit (merge commit)
PR 06d6b8c7 branch commit (from PR)
main 57f9936a base commit (on main)

Model CI Report

181 new failed tests from this PR 😭

  • dpt:
    tests/models/dpt/test_modeling_dpt_auto_backbone.py::DPTModelIntegrationTest::test_inference_depth_estimation_beit (✅ ⟹ ❌)

  • grounding_dino:
    tests/models/grounding_dino/test_modeling_grounding_dino.py::GroundingDinoModelIntegrationTests::test_cross_attention_mask (❌ ⟹ ❌)

  • maskformer:
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_can_load_with_global_device_set (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_can_load_with_global_device_set (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_all_tensors_are_parameter_or_buffer (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_attention_outputs (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_batching_equivalence (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_bc_torch_dtype (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_can_be_initialized_on_meta (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_can_load_from_already_mapped_keys (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_can_load_with_device_context_manager (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_can_set_attention_dynamically (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_can_use_safetensors (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_cannot_load_with_meta_device_context_manager (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_capture_outputs_decorator (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_determinism (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_enable_input_require_grads (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_feed_forward_chunking (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_flex_attention_with_grads (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_forward_auxiliary_loss (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_from_pretrained_no_checkpoint (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_hidden_states_output (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_init_weights_can_init_buffers (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_inputs_embeds_matches_input_ids (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_internal_model_config_and_subconfig_are_same (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_keep_in_fp32_modules (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_keep_in_fp32_modules_exist (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_load_contiguous_weights (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_load_save_without_tied_weights (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_maskformer_instance_segmentation_head_model (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_maskformer_model (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_model_forward_default_config_values (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_model_from_pretrained (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_model_is_small (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_model_outputs_equivalence (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_model_weights_reload_no_missing_tied_weights (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_model_with_labels (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_resize_embeddings_untied (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_resize_embeddings_untied_no_reinit_on_post_init (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_retain_grad_hidden_states_attentions (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_save_load (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_save_load_keys_to_ignore_on_save (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_tied_weights_keys (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_torch_export (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_torch_save_load (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelTest::test_training (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelIntegrationTest::test_inference_instance_segmentation_head (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelIntegrationTest::test_inference_no_head (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer.py::MaskFormerModelIntegrationTest::test_with_segmentation_maps_and_loss (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_all_tensors_are_parameter_or_buffer (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_backbone (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_batching_equivalence (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_bc_torch_dtype (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_can_be_initialized_on_meta (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_can_load_from_already_mapped_keys (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_can_load_with_device_context_manager (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_can_use_safetensors (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_cannot_load_with_meta_device_context_manager (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_capture_outputs_decorator (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_correct_missing_keys (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_cpu_offload (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_determinism (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_disk_offload_bin (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_disk_offload_safetensors (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_enable_input_require_grads (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_enable_input_require_grads_with_gradient_checkpointing (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_flex_attention_with_grads (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_from_pretrained_no_checkpoint (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_gradient_checkpointing_enable_disable (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_hidden_states_output (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_hidden_states_output_with_padding (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_init_weights_can_init_buffers (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_inputs_embeds_matches_input_ids (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_keep_in_fp32_modules (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_keep_in_fp32_modules_exist (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_load_contiguous_weights (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_load_save_without_tied_weights (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_model (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_model_forward_default_config_values (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_model_get_set_embeddings (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_model_is_small (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_model_outputs_equivalence (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_model_weights_reload_no_missing_tied_weights (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_peft_gradient_checkpointing_enable_disable (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_retain_grad_hidden_states_attentions (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_reverse_loading_mapping (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_save_load (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_save_load_keys_to_ignore_on_save (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_tied_weights_keys (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_torch_export (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinModelTest::test_torch_save_load (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinBackboneTest::test_backbone_common_attributes (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinBackboneTest::test_backbone_outputs (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinBackboneTest::test_backbone_stage_selection (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinBackboneTest::test_channels (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinBackboneTest::test_create_from_modified_config (✅ ⟹ ❌)
    tests/models/maskformer/test_modeling_maskformer_swin.py::MaskFormerSwinBackboneTest::test_forward_signature (✅ ⟹ ❌)

  • vivit:
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_can_load_with_global_device_set (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_all_tensors_are_parameter_or_buffer (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_attention_outputs (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_batching_equivalence (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_bc_torch_dtype (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_can_be_initialized_on_meta (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_can_init_all_missing_weights (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_can_load_from_already_mapped_keys (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_can_load_ignoring_mismatched_shapes (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_can_load_with_device_context_manager (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_can_set_attention_dynamically (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_can_use_safetensors (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_cannot_load_with_meta_device_context_manager (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_capture_outputs_decorator (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_correct_missing_keys (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_cpu_offload (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_determinism (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_disk_offload_bin (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_disk_offload_safetensors (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_00_fp16_pad_left_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_01_fp16_pad_left (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_02_fp16_pad_left_no_attn_mask_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_03_fp16_pad_left_no_attn_mask (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_04_fp16_pad_right_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_05_fp16_pad_right (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_06_fp16_pad_right_no_attn_mask_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_07_fp16_pad_right_no_attn_mask (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_08_fp32_pad_left_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_09_fp32_pad_left (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_10_fp32_pad_left_no_attn_mask_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_11_fp32_pad_left_no_attn_mask (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_12_fp32_pad_right_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_13_fp32_pad_right (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_14_fp32_pad_right_no_attn_mask_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_15_fp32_pad_right_no_attn_mask (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_16_bf16_pad_left_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_17_bf16_pad_left (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_18_bf16_pad_left_no_attn_mask_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_19_bf16_pad_left_no_attn_mask (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_20_bf16_pad_right_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_21_bf16_pad_right (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_22_bf16_pad_right_no_attn_mask_sdpa_kernels (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_23_bf16_pad_right_no_attn_mask (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_eager_matches_sdpa_inference_24_fp32_pad_left_output_attentions (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_enable_input_require_grads (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_enable_input_require_grads_with_gradient_checkpointing (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_feed_forward_chunking (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_flex_attention_with_grads (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_for_video_classification (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_forward_signature (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_from_pretrained_no_checkpoint (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_gradient_checkpointing_backward_compatibility (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_gradient_checkpointing_enable_disable (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_hidden_states_output (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_init_weights_can_init_buffers (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_inputs_embeds_matches_input_ids (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_keep_in_fp32_modules (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_keep_in_fp32_modules_exist (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_load_contiguous_weights (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_load_save_without_tied_weights (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_model (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_model_forward_default_config_values (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_model_from_pretrained (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_model_get_set_embeddings (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_model_is_small (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_model_outputs_equivalence (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_model_weights_reload_no_missing_tied_weights (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_peft_gradient_checkpointing_enable_disable (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_retain_grad_hidden_states_attentions (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_reverse_loading_mapping (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_save_load (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_save_load_keys_to_ignore_on_save (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_sdpa_can_compile_dynamic (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_sdpa_can_dispatch_non_composite_models (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_sdpa_can_dispatch_on_flash (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_tied_weights_keys (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_torch_export (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_torch_save_load (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_training (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_training_gradient_checkpointing (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_training_gradient_checkpointing_use_reentrant_false (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelTest::test_training_gradient_checkpointing_use_reentrant_true (✅ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelIntegrationTest::test_inference_for_video_classification (❌ ⟹ ❌)
    tests/models/vivit/test_modeling_vivit.py::VivitModelIntegrationTest::test_inference_interpolate_pos_encoding (✅ ⟹ ❌)

@yonigozlan

Copy link
Copy Markdown
Contributor Author

run-slow: aimv2, audio_spectrogram_transformer, beit, bit, clap, conditional_detr, convnext, convnextv2, cvt, d_fine, dab_detr, data2vec, deit, dinat, dinov2, dinov2_with_registers, dinov3_convnext, dinov3_vit, donut, dpt, eomt, eomt_dinov3, flava, florence2, focalnet, glpn, grounding_dino, hiera, ijepa, lw_detr, maskformer, mgp_str, mm_grounding_dino, pixio, poolformer, pp_doclayout_v2, pp_doclayout_v3, pp_lcnet, pp_lcnet_v3, pp_ocrv5_mobile_rec, pp_ocrv5_server_rec, pvt, pvt_v2, qianfan_ocr, resnet, rt_detr, rt_detr_v2, segformer, seggpt, slanet, swiftformer, swin, swin2sr, swinv2, timesformer, uvdoc, videomae, videomt, vilt, vit, vit_mae, vit_msn, vitdet, vitpose_backbone, vivit, vjepa2, x_clip, yolos

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/aimv2", "models/audio_spectrogram_transformer", "models/beit", "models/bit", "models/clap", "models/conditional_detr", "models/convnext", "models/convnextv2", "models/cvt", "models/d_fine", "models/dab_detr", "models/data2vec", "models/deit", "models/dinat", "models/dinov2", "models/dinov2_with_registers", "models/dinov3_convnext", "models/dinov3_vit", "models/donut", "models/dpt", "models/eomt", "models/eomt_dinov3", "models/flava", "models/florence2", "models/focalnet", "models/glpn", "models/grounding_dino", "models/hiera", "models/ijepa", "models/lw_detr", "models/maskformer", "models/mgp_str", "models/mm_grounding_dino", "models/pixio", "models/poolformer", "models/pp_doclayout_v2", "models/pp_doclayout_v3", "models/pp_lcnet", "models/pp_lcnet_v3", "models/pp_ocrv5_mobile_rec", "models/pp_ocrv5_server_rec", "models/pvt", "models/pvt_v2", "models/qianfan_ocr", "models/resnet", "models/rt_detr", "models/rt_detr_v2", "models/segformer", "models/seggpt", "models/slanet", "models/swiftformer", "models/swin", "models/swin2sr", "models/swinv2", "models/timesformer", "models/uvdoc", "models/videomae", "models/videomt", "models/vilt", "models/vit", "models/vit_mae", "models/vit_msn", "models/vitdet", "models/vitpose_backbone", "models/vivit", "models/vjepa2", "models/x_clip", "models/yolos"]
quantizations: []

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 24ab71c6 workflow commit (merge commit)
PR b8dd0a0f branch commit (from PR)
main 381032b7 base commit (on main)

Model CI Report

3 new failed tests from this PR 😭

  • grounding_dino:
    tests/models/grounding_dino/test_modeling_grounding_dino.py::GroundingDinoModelIntegrationTests::test_cross_attention_mask (❌ ⟹ ❌)

  • vit_mae:
    tests/models/vit_mae/test_modeling_vit_mae.py::ViTMAEModelIntegrationTest::test_inference_for_pretraining (✅ ⟹ ❌)

  • vit_msn:
    tests/models/vit_msn/test_modeling_vit_msn.py::ViTMSNModelIntegrationTest::test_inference_image_classification_head (✅ ⟹ ❌)

@yonigozlan yonigozlan enabled auto-merge May 8, 2026 18:45
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

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

run-slow: aimv2, audio_spectrogram_transformer, beit, bit, clap, conditional_detr, convnext, convnextv2, cvt, d_fine, dab_detr, data2vec, deimv2, deit, dinat, dinov2

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=41693&sha=2d424a

@yonigozlan yonigozlan added this pull request to the merge queue May 8, 2026
Merged via the queue into huggingface:main with commit c9de109 May 8, 2026
30 of 31 checks passed
@yonigozlan yonigozlan deleted the refactor-vit branch May 8, 2026 19:23
louzongzhi pushed a commit to louzongzhi/transformers that referenced this pull request May 11, 2026
* refactor attention

* use mlp instead of intermediate and output

* use modular for deit

* nit

* fix deit (to check) and refactor beit

* use modular for beit

* style

* refactor vit deit beit segformer

* add pos_embed_utils, refactor swin

* Fix after merge + refactor pixio

* refactor most drop_path in transformers

* refactor vit_msn

* fix modular

* refactor vivit and audio_spectrogram_transformer, remove obsolete copied from and add todos

* Fix repo

* fix nit

* Fix drop_path_schedule

* nit

* use modular for pos embed

* reverse DropPath as a util

* add conversion ijepa + fix offload vit_mae

* fix modular

* fix qkv bias in output proj + swin attention per stage

* address review comments

* fix swinn

* improve swin and beit

* last fixes after review

* standardize backbone beit

* fix beit

* fix beit

* fix repo

* changes after review

* Fix beit

* fix after review

* fix unexpected key swin

* Address review

* fix repo

* Fix after review

* fix modular

* fix depth pro

* Fix conversion mappings

* fix style

* Fix failing tests

* fix ci

* Fix two slow failing tests
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.

7 participants