Spaces:
Runtime error
Runtime error
Vision-CAIR
commited on
Commit
β’
6feb8b1
1
Parent(s):
bc58293
Update minigpt4/models/mini_gpt4.py
Browse files- minigpt4/models/mini_gpt4.py +11 -2
minigpt4/models/mini_gpt4.py
CHANGED
@@ -92,11 +92,11 @@ class MiniGPT4(Blip2Base):
|
|
92 |
|
93 |
if llama_cache_dir:
|
94 |
self.llama_model = LlamaForCausalLM.from_pretrained(
|
95 |
-
llama_model, load_in_8bit=True, torch_dtype=torch.float16, device_map=
|
96 |
)
|
97 |
else:
|
98 |
self.llama_model = LlamaForCausalLM.from_pretrained(
|
99 |
-
llama_model, load_in_8bit=True, torch_dtype=torch.float16, device_map=
|
100 |
)
|
101 |
for name, param in self.llama_model.named_parameters():
|
102 |
param.requires_grad = False
|
@@ -118,7 +118,16 @@ class MiniGPT4(Blip2Base):
|
|
118 |
else:
|
119 |
self.prompt_list = []
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
def encode_img(self, image):
|
|
|
|
|
|
|
122 |
with self.maybe_autocast():
|
123 |
image_embeds = self.ln_vision(self.visual_encoder(image))
|
124 |
image_atts = torch.ones(image_embeds.size()[:-1], dtype=torch.long).to(
|
|
|
92 |
|
93 |
if llama_cache_dir:
|
94 |
self.llama_model = LlamaForCausalLM.from_pretrained(
|
95 |
+
llama_model, load_in_8bit=True, torch_dtype=torch.float16, device_map="auto", cache_dir=llama_cache_dir
|
96 |
)
|
97 |
else:
|
98 |
self.llama_model = LlamaForCausalLM.from_pretrained(
|
99 |
+
llama_model, load_in_8bit=True, torch_dtype=torch.float16, device_map="auto"
|
100 |
)
|
101 |
for name, param in self.llama_model.named_parameters():
|
102 |
param.requires_grad = False
|
|
|
118 |
else:
|
119 |
self.prompt_list = []
|
120 |
|
121 |
+
def vit_to_cpu(self):
|
122 |
+
self.ln_vision.to("cpu")
|
123 |
+
self.ln_vision.float()
|
124 |
+
self.visual_encoder.to("cpu")
|
125 |
+
self.visual_encoder.float()
|
126 |
+
|
127 |
def encode_img(self, image):
|
128 |
+
device = image.device
|
129 |
+
self.vit_to_cpu()
|
130 |
+
image = image.to("cpu")
|
131 |
with self.maybe_autocast():
|
132 |
image_embeds = self.ln_vision(self.visual_encoder(image))
|
133 |
image_atts = torch.ones(image_embeds.size()[:-1], dtype=torch.long).to(
|