From 75f753e4169e89fb6bf6df290489d78d068b3a38 Mon Sep 17 00:00:00 2001 From: "serge[bot]" Date: Wed, 1 Jul 2026 00:54:59 +0000 Subject: [PATCH 1/3] [serge] Fix 10 integration tests for model `glm_ocr` failing with `output_mismatch` (list output differs (10)) --- src/transformers/models/glm_ocr/modular_glm_ocr.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/transformers/models/glm_ocr/modular_glm_ocr.py b/src/transformers/models/glm_ocr/modular_glm_ocr.py index 06f389cb8a72..0cd6f4fd2df8 100644 --- a/src/transformers/models/glm_ocr/modular_glm_ocr.py +++ b/src/transformers/models/glm_ocr/modular_glm_ocr.py @@ -299,7 +299,13 @@ class GlmOcrTextModel(Glm4vTextModel): class GlmOcrModel(Glm4vModel): - pass + def __init__(self, config): + super(Glm4vModel, self).__init__(config) + self.visual = GlmOcrVisionModel._from_config(config.vision_config) + self.language_model = GlmOcrTextModel._from_config(config.text_config) + self.rope_deltas = None + # Initialize weights and apply final processing + self.post_init() class GlmOcrForConditionalGeneration(Glm4vForConditionalGeneration): From f2335c337d775dda8235ce15bacdabf777d7492f Mon Sep 17 00:00:00 2001 From: "serge[bot]" Date: Wed, 1 Jul 2026 20:55:11 +0000 Subject: [PATCH 2/3] [serge] Fix 10 integration tests for model `glm_ocr` failing with `output_mismatch` (list output differs (10)) --- src/transformers/models/glm_ocr/modeling_glm_ocr.py | 2 +- src/transformers/models/glm_ocr/modular_glm_ocr.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/transformers/models/glm_ocr/modeling_glm_ocr.py b/src/transformers/models/glm_ocr/modeling_glm_ocr.py index ec9cfa4bd45f..616c2c70ca9f 100644 --- a/src/transformers/models/glm_ocr/modeling_glm_ocr.py +++ b/src/transformers/models/glm_ocr/modeling_glm_ocr.py @@ -820,7 +820,7 @@ def __init__(self, config): super().__init__(config) self.visual = GlmOcrVisionModel._from_config(config.vision_config) self.language_model = GlmOcrTextModel._from_config(config.text_config) - self.rope_deltas = None # cache rope_deltas here + self.rope_deltas = None # Initialize weights and apply final processing self.post_init() diff --git a/src/transformers/models/glm_ocr/modular_glm_ocr.py b/src/transformers/models/glm_ocr/modular_glm_ocr.py index 0cd6f4fd2df8..35ca19882c0c 100644 --- a/src/transformers/models/glm_ocr/modular_glm_ocr.py +++ b/src/transformers/models/glm_ocr/modular_glm_ocr.py @@ -51,6 +51,9 @@ class GlmOcrVisionMlp(Glm4VisionMlp): def __init__(self, config, bias: bool = True): super().__init__(config) self.intermediate_size = config.intermediate_size + self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=bias) + self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=bias) + self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=bias) @auto_docstring(checkpoint="zai-org/GLM-OCR") From 9cdf90fa2160dfcbb21905baa71fac037bbc2d5b Mon Sep 17 00:00:00 2001 From: "serge[bot]" Date: Sat, 4 Jul 2026 07:43:54 +0000 Subject: [PATCH 3/3] [serge] Fix 10 integration tests for model `glm_ocr` failing with `output_mismatch` (list output differs (10)) --- .../colmodernvbert/modeling_colmodernvbert.py | 17 +---------------- .../models/colqwen2/modeling_colqwen2.py | 17 +---------------- .../modeling_conditional_detr.py | 14 +------------- .../falcon_mamba/modeling_falcon_mamba.py | 13 +++---------- .../models/glm_ocr/modeling_glm_ocr.py | 1 - .../models/glm_ocr/modular_glm_ocr.py | 2 ++ .../modeling_granitemoehybrid.py | 2 ++ .../models/lfm2_moe/modeling_lfm2_moe.py | 2 ++ .../models/maskformer/modeling_maskformer.py | 14 +------------- .../modeling_mm_grounding_dino.py | 15 +-------------- .../models/nemotron_h/modeling_nemotron_h.py | 2 ++ .../pp_doclayout_v2/modeling_pp_doclayout_v2.py | 7 ++----- .../models/qwen3_5/modeling_qwen3_5.py | 2 ++ .../models/qwen3_5_moe/modeling_qwen3_5_moe.py | 2 ++ .../models/rf_detr/modeling_rf_detr.py | 4 +--- .../models/rt_detr_v2/modeling_rt_detr_v2.py | 7 ++----- .../models/siglip2/modeling_siglip2.py | 4 +--- .../models/videomt/modeling_videomt.py | 4 +--- 18 files changed, 27 insertions(+), 102 deletions(-) diff --git a/src/transformers/models/colmodernvbert/modeling_colmodernvbert.py b/src/transformers/models/colmodernvbert/modeling_colmodernvbert.py index 754ffed137df..a2e78a0b07df 100755 --- a/src/transformers/models/colmodernvbert/modeling_colmodernvbert.py +++ b/src/transformers/models/colmodernvbert/modeling_colmodernvbert.py @@ -23,7 +23,6 @@ import torch from torch import nn -from ... import initialization as init from ...modeling_utils import PreTrainedModel from ...processing_utils import Unpack from ...utils import ModelOutput, TransformersKwargs, auto_docstring @@ -44,21 +43,7 @@ class ColModernVBertPreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module): - std = ( - self.config.initializer_range - if hasattr(self.config, "initializer_range") - else self.config.vlm_config.text_config.initializer_range - ) - - if isinstance(module, (nn.Linear, nn.Conv2d)): - init.normal_(module.weight, mean=0.0, std=std) - if module.bias is not None: - init.zeros_(module.bias) - elif isinstance(module, nn.Embedding): - init.normal_(module.weight, mean=0.0, std=std) - # Here we need the check explicitly, as we slice the weight in the `zeros_` call, so it looses the flag - if module.padding_idx is not None and not getattr(module.weight, "_is_hf_initialized", False): - init.zeros_(module.weight[module.padding_idx]) + super()._init_weights(module) @auto_docstring( diff --git a/src/transformers/models/colqwen2/modeling_colqwen2.py b/src/transformers/models/colqwen2/modeling_colqwen2.py index 031ccfbab6cd..d87b5dc55c1f 100644 --- a/src/transformers/models/colqwen2/modeling_colqwen2.py +++ b/src/transformers/models/colqwen2/modeling_colqwen2.py @@ -24,7 +24,6 @@ from transformers import AutoModel -from ... import initialization as init from ...cache_utils import Cache from ...modeling_utils import PreTrainedModel from ...utils import ModelOutput, auto_docstring, can_return_tuple, is_torch_available @@ -47,21 +46,7 @@ class ColQwen2PreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module): - std = ( - self.config.initializer_range - if hasattr(self.config, "initializer_range") - else self.config.vlm_config.text_config.initializer_range - ) - - if isinstance(module, (nn.Linear, nn.Conv2d)): - init.normal_(module.weight, mean=0.0, std=std) - if module.bias is not None: - init.zeros_(module.bias) - elif isinstance(module, nn.Embedding): - init.normal_(module.weight, mean=0.0, std=std) - # Here we need the check explicitly, as we slice the weight in the `zeros_` call, so it looses the flag - if module.padding_idx is not None and not getattr(module.weight, "_is_hf_initialized", False): - init.zeros_(module.weight[module.padding_idx]) + super()._init_weights(module) @auto_docstring( diff --git a/src/transformers/models/conditional_detr/modeling_conditional_detr.py b/src/transformers/models/conditional_detr/modeling_conditional_detr.py index 05ea9ee42eea..3dd65a92135c 100644 --- a/src/transformers/models/conditional_detr/modeling_conditional_detr.py +++ b/src/transformers/models/conditional_detr/modeling_conditional_detr.py @@ -1050,7 +1050,7 @@ class ConditionalDetrPreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module): - std = self.config.init_std + super()._init_weights(module) xavier_std = self.config.init_xavier_std if isinstance(module, ConditionalDetrMaskHeadSmallConv): @@ -1068,18 +1068,6 @@ def _init_weights(self, module): elif isinstance(module, ConditionalDetrLearnedPositionEmbedding): init.uniform_(module.row_embeddings.weight) init.uniform_(module.column_embeddings.weight) - elif isinstance(module, (nn.Linear, nn.Conv2d)): - init.normal_(module.weight, mean=0.0, std=std) - if module.bias is not None: - init.zeros_(module.bias) - elif isinstance(module, nn.Embedding): - init.normal_(module.weight, mean=0.0, std=std) - # Here we need the check explicitly, as we slice the weight in the `zeros_` call, so it looses the flag - if module.padding_idx is not None and not getattr(module.weight, "_is_hf_initialized", False): - init.zeros_(module.weight[module.padding_idx]) - elif isinstance(module, (nn.LayerNorm, nn.GroupNorm)): - init.ones_(module.weight) - init.zeros_(module.bias) class ConditionalDetrEncoder(ConditionalDetrPreTrainedModel): diff --git a/src/transformers/models/falcon_mamba/modeling_falcon_mamba.py b/src/transformers/models/falcon_mamba/modeling_falcon_mamba.py index 322bcde59171..30f0e1ad0e48 100644 --- a/src/transformers/models/falcon_mamba/modeling_falcon_mamba.py +++ b/src/transformers/models/falcon_mamba/modeling_falcon_mamba.py @@ -30,6 +30,7 @@ from ...cache_utils import Cache, DynamicCache from ...generation import GenerationMixin from ...integrations import lazy_load_kernel +from ...integrations.accelerate import force_accelerate_hooks from ...modeling_layers import GradientCheckpointingLayer from ...modeling_utils import PreTrainedModel from ...utils import ModelOutput, auto_docstring, logging @@ -437,6 +438,7 @@ def combine_fn(left, right): return contextualized_states # fmt: on + @force_accelerate_hooks("conv1d") def forward( self, hidden_states, @@ -507,7 +509,7 @@ class FalconMambaPreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module): """Initialize the weights.""" - std = self.config.initializer_range + super()._init_weights(module) if isinstance(module, FalconMambaMixer): # S4D real initialization. These are not discretized! # The core is to load them, compute the discrete states, then write the updated state. Keeps the memory bounded @@ -532,15 +534,6 @@ def _init_weights(self, module): p = module.out_proj.weight p /= math.sqrt(self.config.num_hidden_layers) - if isinstance(module, nn.Linear): - init.normal_(module.weight, std=std) - if module.bias is not None: - init.zeros_(module.bias) - elif isinstance(module, FalconMambaRMSNorm): - init.ones_(module.weight) - elif isinstance(module, nn.Embedding): - init.normal_(module.weight, std=std) - @auto_docstring( custom_intro=""" diff --git a/src/transformers/models/glm_ocr/modeling_glm_ocr.py b/src/transformers/models/glm_ocr/modeling_glm_ocr.py index 616c2c70ca9f..abc2434895af 100644 --- a/src/transformers/models/glm_ocr/modeling_glm_ocr.py +++ b/src/transformers/models/glm_ocr/modeling_glm_ocr.py @@ -551,7 +551,6 @@ def __init__(self, config) -> None: head_dim = config.hidden_size // config.num_heads self.rotary_pos_emb = GlmOcrVisionRotaryEmbedding(head_dim // 2) - self.blocks = nn.ModuleList([GlmOcrVisionBlock(config) for _ in range(config.depth)]) self.merger = GlmOcrVisionPatchMerger( dim=config.out_hidden_size, diff --git a/src/transformers/models/glm_ocr/modular_glm_ocr.py b/src/transformers/models/glm_ocr/modular_glm_ocr.py index 35ca19882c0c..cbae63178eed 100644 --- a/src/transformers/models/glm_ocr/modular_glm_ocr.py +++ b/src/transformers/models/glm_ocr/modular_glm_ocr.py @@ -231,6 +231,7 @@ def forward( class GlmOcrVisionBlock(Glm4vVisionBlock): def __init__(self, config) -> None: super().__init__() + self.attn = GlmOcrVisionAttention(config) self.mlp = GlmOcrVisionMlp(config, bias=config.attention_bias) @@ -243,6 +244,7 @@ def __init__(self, config) -> None: super().__init__(config) del self.embeddings del self.post_conv_layernorm + self.blocks = nn.ModuleList([GlmOcrVisionBlock(config) for _ in range(config.depth)]) self.merger = GlmOcrVisionPatchMerger( dim=config.out_hidden_size, context_dim=config.out_hidden_size * config.in_channels, diff --git a/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py b/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py index 10939ef88c75..dfd2af072066 100644 --- a/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py +++ b/src/transformers/models/granitemoehybrid/modeling_granitemoehybrid.py @@ -35,6 +35,7 @@ use_kernel_func_from_hub, use_kernelized_func, ) +from ...integrations.accelerate import force_accelerate_hooks from ...integrations.hub_kernels import lazy_load_kernel from ...masking_utils import create_causal_mask, create_recurrent_attention_mask from ...modeling_layers import GradientCheckpointingLayer @@ -730,6 +731,7 @@ def torch_forward( return contextualized_states # fmt: on + @force_accelerate_hooks("conv1d") def forward( self, hidden_states, diff --git a/src/transformers/models/lfm2_moe/modeling_lfm2_moe.py b/src/transformers/models/lfm2_moe/modeling_lfm2_moe.py index 85b8f31742e2..0e017c682f11 100644 --- a/src/transformers/models/lfm2_moe/modeling_lfm2_moe.py +++ b/src/transformers/models/lfm2_moe/modeling_lfm2_moe.py @@ -34,6 +34,7 @@ use_kernel_func_from_hub, use_kernelized_func, ) +from ...integrations.accelerate import force_accelerate_hooks from ...masking_utils import create_causal_mask, create_recurrent_attention_mask from ...modeling_layers import GradientCheckpointingLayer from ...modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, MoeModelOutputWithPast @@ -490,6 +491,7 @@ def slow_forward( y = self.out_proj(y) return y + @force_accelerate_hooks("conv") def forward( self, hidden_states: torch.Tensor, diff --git a/src/transformers/models/maskformer/modeling_maskformer.py b/src/transformers/models/maskformer/modeling_maskformer.py index f9b51ba00b55..4f449eb5bf05 100644 --- a/src/transformers/models/maskformer/modeling_maskformer.py +++ b/src/transformers/models/maskformer/modeling_maskformer.py @@ -732,7 +732,7 @@ class MaskFormerDetrPreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module): - std = self.config.init_std + super()._init_weights(module) xavier_std = self.config.init_xavier_std if isinstance(module, MaskFormerDetrMaskHeadSmallConv): @@ -750,18 +750,6 @@ def _init_weights(self, module): elif isinstance(module, MaskFormerDetrLearnedPositionEmbedding): init.uniform_(module.row_embeddings.weight) init.uniform_(module.column_embeddings.weight) - elif isinstance(module, (nn.Linear, nn.Conv2d)): - init.normal_(module.weight, mean=0.0, std=std) - if module.bias is not None: - init.zeros_(module.bias) - elif isinstance(module, nn.Embedding): - init.normal_(module.weight, mean=0.0, std=std) - # Here we need the check explicitly, as we slice the weight in the `zeros_` call, so it looses the flag - if module.padding_idx is not None and not getattr(module.weight, "_is_hf_initialized", False): - init.zeros_(module.weight[module.padding_idx]) - elif isinstance(module, (nn.LayerNorm, nn.GroupNorm)): - init.ones_(module.weight) - init.zeros_(module.bias) class MaskFormerDetrDecoder(MaskFormerDetrPreTrainedModel): diff --git a/src/transformers/models/mm_grounding_dino/modeling_mm_grounding_dino.py b/src/transformers/models/mm_grounding_dino/modeling_mm_grounding_dino.py index 4540c2da60a4..5dd3c8a52784 100644 --- a/src/transformers/models/mm_grounding_dino/modeling_mm_grounding_dino.py +++ b/src/transformers/models/mm_grounding_dino/modeling_mm_grounding_dino.py @@ -494,8 +494,7 @@ class MMGroundingDinoPreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module): - std = self.config.init_std - + super()._init_weights(module) if isinstance(module, MMGroundingDinoLearnedPositionEmbedding): init.uniform_(module.row_embeddings.weight) init.uniform_(module.column_embeddings.weight) @@ -537,18 +536,6 @@ def _init_weights(self, module): elif isinstance(module, MMGroundingDinoFusionLayer): init.constant_(module.vision_param, 1e-4) init.constant_(module.text_param, 1e-4) - elif isinstance(module, (nn.Linear, nn.Conv2d)): - init.normal_(module.weight, mean=0.0, std=std) - if module.bias is not None: - init.zeros_(module.bias) - elif isinstance(module, (nn.LayerNorm, nn.GroupNorm)): - init.ones_(module.weight) - init.zeros_(module.bias) - elif isinstance(module, nn.Embedding): - init.normal_(module.weight, mean=0.0, std=std) - # Here we need the check explicitly, as we slice the weight in the `zeros_` call, so it looses the flag - if module.padding_idx is not None and not getattr(module.weight, "_is_hf_initialized", False): - init.zeros_(module.weight[module.padding_idx]) elif isinstance(module, MMGroundingDinoMLPPredictionHead): init.constant_(module.layers[-1].weight, 0) init.constant_(module.layers[-1].bias, 0) diff --git a/src/transformers/models/nemotron_h/modeling_nemotron_h.py b/src/transformers/models/nemotron_h/modeling_nemotron_h.py index 817ed25d5814..4f141b1628f5 100644 --- a/src/transformers/models/nemotron_h/modeling_nemotron_h.py +++ b/src/transformers/models/nemotron_h/modeling_nemotron_h.py @@ -38,6 +38,7 @@ use_kernel_func_from_hub, use_kernelized_func, ) +from ...integrations.accelerate import force_accelerate_hooks from ...masking_utils import create_causal_mask, create_recurrent_attention_mask from ...modeling_layers import GradientCheckpointingLayer from ...modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast @@ -585,6 +586,7 @@ def torch_forward(self, input_states, cache_params: Cache | None=None, attention return contextualized_states # fmt: on + @force_accelerate_hooks("conv1d") def forward( self, hidden_states, diff --git a/src/transformers/models/pp_doclayout_v2/modeling_pp_doclayout_v2.py b/src/transformers/models/pp_doclayout_v2/modeling_pp_doclayout_v2.py index 282d8700ebda..ef6c7e01193c 100644 --- a/src/transformers/models/pp_doclayout_v2/modeling_pp_doclayout_v2.py +++ b/src/transformers/models/pp_doclayout_v2/modeling_pp_doclayout_v2.py @@ -744,6 +744,7 @@ class PPDocLayoutV2PreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module): """Initialize the weights""" + super()._init_weights(module) if isinstance(module, PPDocLayoutV2ForObjectDetection): if module.model.decoder.class_embed is not None: for layer in module.model.decoder.class_embed: @@ -786,7 +787,7 @@ def _init_weights(self, module): init.xavier_uniform_(module.enc_score_head.weight) init.constant_(module.enc_score_head.bias, bias) - elif isinstance(module, (nn.Linear, nn.Conv2d, nn.BatchNorm2d)): + elif isinstance(module, nn.BatchNorm2d): init.normal_(module.weight, mean=0.0, std=self.config.initializer_range) if module.bias is not None: init.zeros_(module.bias) @@ -795,10 +796,6 @@ def _init_weights(self, module): init.ones_(module.running_var) init.zeros_(module.num_batches_tracked) - elif isinstance(module, nn.LayerNorm): - init.ones_(module.weight) - init.zeros_(module.bias) - if hasattr(module, "weight_embedding") and self.config.learn_initial_query: init.xavier_uniform_(module.weight_embedding.weight) if hasattr(module, "denoising_class_embed") and self.config.num_denoising > 0: diff --git a/src/transformers/models/qwen3_5/modeling_qwen3_5.py b/src/transformers/models/qwen3_5/modeling_qwen3_5.py index 267941b76477..1f695935030c 100644 --- a/src/transformers/models/qwen3_5/modeling_qwen3_5.py +++ b/src/transformers/models/qwen3_5/modeling_qwen3_5.py @@ -33,6 +33,7 @@ from ...cache_utils import Cache, DynamicCache from ...generation import GenerationMixin from ...integrations import use_kernel_forward_from_hub +from ...integrations.accelerate import force_accelerate_hooks from ...masking_utils import create_causal_mask, create_recurrent_attention_mask from ...modeling_flash_attention_utils import FlashAttentionKwargs from ...modeling_layers import ( @@ -436,6 +437,7 @@ def __init__(self, config: Qwen3_5Config, layer_idx: int): self.in_proj_b = nn.Linear(self.hidden_size, self.num_v_heads, bias=False) self.in_proj_a = nn.Linear(self.hidden_size, self.num_v_heads, bias=False) + @force_accelerate_hooks("conv1d") def forward( self, hidden_states: torch.Tensor, diff --git a/src/transformers/models/qwen3_5_moe/modeling_qwen3_5_moe.py b/src/transformers/models/qwen3_5_moe/modeling_qwen3_5_moe.py index 31415a3f9e03..643af3afd48b 100644 --- a/src/transformers/models/qwen3_5_moe/modeling_qwen3_5_moe.py +++ b/src/transformers/models/qwen3_5_moe/modeling_qwen3_5_moe.py @@ -33,6 +33,7 @@ from ...cache_utils import Cache, DynamicCache from ...generation import GenerationMixin from ...integrations import use_experts_implementation, use_kernel_forward_from_hub +from ...integrations.accelerate import force_accelerate_hooks from ...masking_utils import create_causal_mask, create_recurrent_attention_mask from ...modeling_flash_attention_utils import FlashAttentionKwargs from ...modeling_layers import GradientCheckpointingLayer @@ -433,6 +434,7 @@ def __init__(self, config: Qwen3_5MoeConfig, layer_idx: int): self.in_proj_b = nn.Linear(self.hidden_size, self.num_v_heads, bias=False) self.in_proj_a = nn.Linear(self.hidden_size, self.num_v_heads, bias=False) + @force_accelerate_hooks("conv1d") def forward( self, hidden_states: torch.Tensor, diff --git a/src/transformers/models/rf_detr/modeling_rf_detr.py b/src/transformers/models/rf_detr/modeling_rf_detr.py index 2a50bd5e2024..c994918057b6 100644 --- a/src/transformers/models/rf_detr/modeling_rf_detr.py +++ b/src/transformers/models/rf_detr/modeling_rf_detr.py @@ -485,13 +485,11 @@ class RfDetrDinov2PreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module: nn.Linear | nn.Conv2d | nn.LayerNorm) -> None: """Initialize the weights""" + super()._init_weights(module) if isinstance(module, (nn.Linear, nn.Conv2d)): init.trunc_normal_(module.weight, mean=0.0, std=self.config.initializer_range) if module.bias is not None: init.zeros_(module.bias) - elif isinstance(module, nn.LayerNorm): - init.zeros_(module.bias) - init.ones_(module.weight) elif isinstance(module, RfDetrDinov2Embeddings): init.trunc_normal_(module.position_embeddings, mean=0.0, std=self.config.initializer_range) init.trunc_normal_(module.cls_token, mean=0.0, std=self.config.initializer_range) diff --git a/src/transformers/models/rt_detr_v2/modeling_rt_detr_v2.py b/src/transformers/models/rt_detr_v2/modeling_rt_detr_v2.py index 5255d715d352..0f1689d0c41a 100644 --- a/src/transformers/models/rt_detr_v2/modeling_rt_detr_v2.py +++ b/src/transformers/models/rt_detr_v2/modeling_rt_detr_v2.py @@ -446,6 +446,7 @@ class RTDetrV2PreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module): """Initialize the weights""" + super()._init_weights(module) if isinstance(module, RTDetrV2ForObjectDetection): if module.model.decoder.class_embed is not None: for layer in module.model.decoder.class_embed: @@ -488,7 +489,7 @@ def _init_weights(self, module): init.xavier_uniform_(module.enc_score_head.weight) init.constant_(module.enc_score_head.bias, bias) - elif isinstance(module, (nn.Linear, nn.Conv2d, nn.BatchNorm2d)): + elif isinstance(module, nn.BatchNorm2d): init.normal_(module.weight, mean=0.0, std=self.config.initializer_range) if module.bias is not None: init.zeros_(module.bias) @@ -497,10 +498,6 @@ def _init_weights(self, module): init.ones_(module.running_var) init.zeros_(module.num_batches_tracked) - elif isinstance(module, nn.LayerNorm): - init.ones_(module.weight) - init.zeros_(module.bias) - if hasattr(module, "weight_embedding") and self.config.learn_initial_query: init.xavier_uniform_(module.weight_embedding.weight) if hasattr(module, "denoising_class_embed") and self.config.num_denoising > 0: diff --git a/src/transformers/models/siglip2/modeling_siglip2.py b/src/transformers/models/siglip2/modeling_siglip2.py index 51e83dce2a99..336fec4f9c7d 100644 --- a/src/transformers/models/siglip2/modeling_siglip2.py +++ b/src/transformers/models/siglip2/modeling_siglip2.py @@ -413,6 +413,7 @@ class Siglip2PreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module): """Initialize the weights""" + super()._init_weights(module) if isinstance(module, Siglip2VisionEmbeddings): width = ( self.config.vision_config.hidden_size @@ -454,9 +455,6 @@ def _init_weights(self, module): init.lecun_normal_(module.weight) if module.bias is not None: init.zeros_(module.bias) - elif isinstance(module, nn.LayerNorm): - init.zeros_(module.bias) - init.ones_(module.weight) elif isinstance(module, Siglip2TextEmbeddings): init.copy_(module.position_ids, torch.arange(module.position_ids.shape[-1]).expand((1, -1))) diff --git a/src/transformers/models/videomt/modeling_videomt.py b/src/transformers/models/videomt/modeling_videomt.py index e42ff1299931..7484511728de 100644 --- a/src/transformers/models/videomt/modeling_videomt.py +++ b/src/transformers/models/videomt/modeling_videomt.py @@ -951,6 +951,7 @@ class VideomtPreTrainedModel(PreTrainedModel): @torch.no_grad() def _init_weights(self, module: nn.Module) -> None: + super()._init_weights(module) std = self.config.initializer_range if isinstance(module, (nn.Linear, nn.Conv2d, nn.ConvTranspose2d)): init.kaiming_uniform_(module.weight, a=math.sqrt(5)) @@ -958,9 +959,6 @@ def _init_weights(self, module: nn.Module) -> None: fan_in, _ = torch.nn.init._calculate_fan_in_and_fan_out(module.weight) bound = 1 / math.sqrt(fan_in) if fan_in > 0 else 0 init.uniform_(module.bias, -bound, bound) - elif isinstance(module, nn.LayerNorm): - init.ones_(module.weight) - init.zeros_(module.bias) elif isinstance(module, nn.Embedding): init.normal_(module.weight, mean=0.0, std=1) # Here we need the check explicitly, as we slice the weight in the `zeros_` call, so it looses the flag