jadechoghari
commited on
Commit
•
93ae000
1
Parent(s):
744d366
add trust_remote_code = True
Browse files- builder.py +11 -11
builder.py
CHANGED
@@ -71,10 +71,10 @@ def load_pretrained_model(model_path, model_base, model_name, load_8bit=False, l
|
|
71 |
if 'llava' in model_name.lower() or 'ferret' in model_name.lower():
|
72 |
# Load LLaVA/FERRET model
|
73 |
if 'lora' in model_name.lower() and model_base is not None:
|
74 |
-
lora_cfg_pretrained = AutoConfig.from_pretrained(model_path)
|
75 |
-
tokenizer = AutoTokenizer.from_pretrained(model_base, use_fast=False)
|
76 |
print('Loading LLaVA/FERRET from base model...')
|
77 |
-
model = AutoModelForCausalLM.from_pretrained(model_base, low_cpu_mem_usage=True, config=lora_cfg_pretrained, **kwargs)
|
78 |
token_num, tokem_dim = model.lm_head.out_features, model.lm_head.in_features
|
79 |
if model.lm_head.weight.shape[0] != token_num:
|
80 |
model.lm_head.weight = torch.nn.Parameter(torch.empty(token_num, tokem_dim, device=model.device, dtype=model.dtype))
|
@@ -100,7 +100,7 @@ def load_pretrained_model(model_path, model_base, model_name, load_8bit=False, l
|
|
100 |
|
101 |
from peft import PeftModel
|
102 |
print('Loading LoRA weights...')
|
103 |
-
model = PeftModel.from_pretrained(model, model_path)
|
104 |
print('Merging LoRA weights...')
|
105 |
model = model.merge_and_unload()
|
106 |
print('Model is loaded...')
|
@@ -109,31 +109,31 @@ def load_pretrained_model(model_path, model_base, model_name, load_8bit=False, l
|
|
109 |
print('Loading LLaVA/FERRET from base model...')
|
110 |
tokenizer = AutoTokenizer.from_pretrained(model_base, use_fast=False)
|
111 |
cfg_pretrained = AutoConfig.from_pretrained(model_path)
|
112 |
-
model = AutoModelForCausalLM.from_pretrained(model_base, low_cpu_mem_usage=True, config=cfg_pretrained, **kwargs)
|
113 |
|
114 |
mm_projector_weights = torch.load(os.path.join(model_path, 'mm_projector.bin'), map_location='cpu')
|
115 |
mm_projector_weights = {k: v.to(torch.float16) for k, v in mm_projector_weights.items()}
|
116 |
model.load_state_dict(mm_projector_weights, strict=False)
|
117 |
else:
|
118 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False)
|
119 |
-
model = AutoModelForCausalLM.from_pretrained(model_path, low_cpu_mem_usage=True, **kwargs)
|
120 |
else:
|
121 |
# Load language model
|
122 |
if model_base is not None:
|
123 |
# PEFT model
|
124 |
from peft import PeftModel
|
125 |
tokenizer = AutoTokenizer.from_pretrained(model_base, use_fast=False)
|
126 |
-
model = AutoModelForCausalLM.from_pretrained(model_base, torch_dtype=torch.float16, low_cpu_mem_usage=True, device_map="auto")
|
127 |
print(f"Loading LoRA weights from {model_path}")
|
128 |
-
model = PeftModel.from_pretrained(model, model_path)
|
129 |
print(f"Merging weights")
|
130 |
model = model.merge_and_unload()
|
131 |
print('Convert to FP16...')
|
132 |
model.to(torch.float16)
|
133 |
else:
|
134 |
use_fast = False
|
135 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False)
|
136 |
-
model = AutoModelForCausalLM.from_pretrained(model_path, low_cpu_mem_usage=True, **kwargs)
|
137 |
|
138 |
image_processor = None
|
139 |
|
|
|
71 |
if 'llava' in model_name.lower() or 'ferret' in model_name.lower():
|
72 |
# Load LLaVA/FERRET model
|
73 |
if 'lora' in model_name.lower() and model_base is not None:
|
74 |
+
lora_cfg_pretrained = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
|
75 |
+
tokenizer = AutoTokenizer.from_pretrained(model_base, use_fast=False, trust_remote_code=True)
|
76 |
print('Loading LLaVA/FERRET from base model...')
|
77 |
+
model = AutoModelForCausalLM.from_pretrained(model_base, low_cpu_mem_usage=True, config=lora_cfg_pretrained, **kwargs, trust_remote_code=True)
|
78 |
token_num, tokem_dim = model.lm_head.out_features, model.lm_head.in_features
|
79 |
if model.lm_head.weight.shape[0] != token_num:
|
80 |
model.lm_head.weight = torch.nn.Parameter(torch.empty(token_num, tokem_dim, device=model.device, dtype=model.dtype))
|
|
|
100 |
|
101 |
from peft import PeftModel
|
102 |
print('Loading LoRA weights...')
|
103 |
+
model = PeftModel.from_pretrained(model, model_path, trust_remote_code=True)
|
104 |
print('Merging LoRA weights...')
|
105 |
model = model.merge_and_unload()
|
106 |
print('Model is loaded...')
|
|
|
109 |
print('Loading LLaVA/FERRET from base model...')
|
110 |
tokenizer = AutoTokenizer.from_pretrained(model_base, use_fast=False)
|
111 |
cfg_pretrained = AutoConfig.from_pretrained(model_path)
|
112 |
+
model = AutoModelForCausalLM.from_pretrained(model_base, low_cpu_mem_usage=True, config=cfg_pretrained, **kwargs, trust_remote_code=True)
|
113 |
|
114 |
mm_projector_weights = torch.load(os.path.join(model_path, 'mm_projector.bin'), map_location='cpu')
|
115 |
mm_projector_weights = {k: v.to(torch.float16) for k, v in mm_projector_weights.items()}
|
116 |
model.load_state_dict(mm_projector_weights, strict=False)
|
117 |
else:
|
118 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False, trust_remote_code=True)
|
119 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, low_cpu_mem_usage=True, **kwargs, trust_remote_code=True)
|
120 |
else:
|
121 |
# Load language model
|
122 |
if model_base is not None:
|
123 |
# PEFT model
|
124 |
from peft import PeftModel
|
125 |
tokenizer = AutoTokenizer.from_pretrained(model_base, use_fast=False)
|
126 |
+
model = AutoModelForCausalLM.from_pretrained(model_base, torch_dtype=torch.float16, low_cpu_mem_usage=True, device_map="auto", trust_remote_code=True)
|
127 |
print(f"Loading LoRA weights from {model_path}")
|
128 |
+
model = PeftModel.from_pretrained(model, model_path, trust_remote_code=True)
|
129 |
print(f"Merging weights")
|
130 |
model = model.merge_and_unload()
|
131 |
print('Convert to FP16...')
|
132 |
model.to(torch.float16)
|
133 |
else:
|
134 |
use_fast = False
|
135 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=False, trust_remote_code=True)
|
136 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, low_cpu_mem_usage=True, **kwargs, trust_remote_code=True)
|
137 |
|
138 |
image_processor = None
|
139 |
|