jadechoghari commited on
Commit
03d67e9
1 Parent(s): 2ecf8d8

Update model_UI.py

Browse files
Files changed (1) hide show
  1. model_UI.py +19 -2
model_UI.py CHANGED
@@ -4,10 +4,20 @@ import os
4
  import json
5
  from tqdm import tqdm
6
 
7
- from constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN, DEFAULT_REGION_FEA_TOKEN, VOCAB_IMAGE_W, VOCAB_IMAGE_H
 
 
 
 
 
 
 
 
 
 
8
  from conversation import conv_templates, SeparatorStyle
9
  from builder import load_pretrained_model
10
- from utils import disable_torch_init
11
  from mm_utils import tokenizer_image_token, process_images
12
 
13
  from PIL import Image
@@ -17,6 +27,13 @@ import numpy as np
17
  from copy import deepcopy
18
  from functools import partial
19
 
 
 
 
 
 
 
 
20
 
21
  def split_list(lst, n):
22
  """Split a list into n (roughly) equal-sized chunks"""
 
4
  import json
5
  from tqdm import tqdm
6
 
7
+ IMAGE_TOKEN_INDEX = -200
8
+ DEFAULT_IMAGE_TOKEN = "<image>"
9
+ DEFAULT_IMAGE_PATCH_TOKEN = "<im_patch>"
10
+ DEFAULT_IM_START_TOKEN = "<im_start>"
11
+ DEFAULT_IM_END_TOKEN = "<im_end>"
12
+ IMAGE_PLACEHOLDER = "<image-placeholder>"
13
+
14
+ # Added by Ferret
15
+ DEFAULT_REGION_FEA_TOKEN = "<region_fea>"
16
+ VOCAB_IMAGE_W = 1000
17
+ VOCAB_IMAGE_H = 1000
18
  from conversation import conv_templates, SeparatorStyle
19
  from builder import load_pretrained_model
20
+
21
  from mm_utils import tokenizer_image_token, process_images
22
 
23
  from PIL import Image
 
27
  from copy import deepcopy
28
  from functools import partial
29
 
30
+ def disable_torch_init():
31
+ """
32
+ Disable the redundant torch default initialization to accelerate model creation.
33
+ """
34
+ import torch
35
+ setattr(torch.nn.Linear, "reset_parameters", lambda self: None)
36
+ setattr(torch.nn.LayerNorm, "reset_parameters", lambda self: None)
37
 
38
  def split_list(lst, n):
39
  """Split a list into n (roughly) equal-sized chunks"""