Compatibility with v5

#6
by RaushanTurganbay HF Staff - opened
Files changed (1) hide show
  1. modeling_intern_vit.py +4 -1
modeling_intern_vit.py CHANGED
@@ -3,6 +3,8 @@
3
  # Copyright (c) 2023 OpenGVLab
4
  # Licensed under The MIT License [see LICENSE for details]
5
  # --------------------------------------------------------
 
 
6
  from typing import Optional, Tuple, Union
7
 
8
  import torch
@@ -243,7 +245,7 @@ class InternVisionEncoder(nn.Module):
243
  super().__init__()
244
  self.config = config
245
  # stochastic depth decay rule
246
- dpr = [x.item() for x in torch.linspace(0, config.drop_path_rate, config.num_hidden_layers)]
247
  self.layers = nn.ModuleList([
248
  InternVisionEncoderLayer(config, dpr[idx]) for idx in range(config.num_hidden_layers)])
249
  self.gradient_checkpointing = True
@@ -306,6 +308,7 @@ class InternVisionModel(PreTrainedModel):
306
 
307
  self.embeddings = InternVisionEmbeddings(config)
308
  self.encoder = InternVisionEncoder(config)
 
309
 
310
  def resize_pos_embeddings(self, old_size, new_size, patch_size):
311
  pos_emb = self.embeddings.position_embedding
 
3
  # Copyright (c) 2023 OpenGVLab
4
  # Licensed under The MIT License [see LICENSE for details]
5
  # --------------------------------------------------------
6
+
7
+ import numpy as np
8
  from typing import Optional, Tuple, Union
9
 
10
  import torch
 
245
  super().__init__()
246
  self.config = config
247
  # stochastic depth decay rule
248
+ dpr = [x for x in np.linspace(0, config.drop_path_rate, config.num_hidden_layers)]
249
  self.layers = nn.ModuleList([
250
  InternVisionEncoderLayer(config, dpr[idx]) for idx in range(config.num_hidden_layers)])
251
  self.gradient_checkpointing = True
 
308
 
309
  self.embeddings = InternVisionEmbeddings(config)
310
  self.encoder = InternVisionEncoder(config)
311
+ self.post_init()
312
 
313
  def resize_pos_embeddings(self, old_size, new_size, patch_size):
314
  pos_emb = self.embeddings.position_embedding