Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ydshieh committed Apr 16, 2024
1 parent ec95602 commit 496f32b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/transformers/models/layoutlmv2/modeling_layoutlmv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ def __init__(self, config):
self.visual_proj = nn.Linear(config.image_feature_pool_shape[-1], config.hidden_size)
if self.has_visual_segment_embedding:
self.visual_segment_embedding = nn.Parameter(nn.Embedding(1, config.hidden_size).weight[0])
# For `nn.Parameter`, we need to give it an initialized weight in order to keep reproducibility.
# Otherwise, since `_fast_init` is used in `modeling_utils.py`, the layer `nn.Embedding` is not initialized,
# and `_init_weights` is not designed to deal with `nn.Parameter`.
self.visual_segment_embedding.data.normal_(mean=0.0, std=self.config.initializer_range)
self.visual_LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
self.visual_dropout = nn.Dropout(config.hidden_dropout_prob)
Expand Down

0 comments on commit 496f32b

Please sign in to comment.