Commit
·
24a0d89
1
Parent(s):
bd67535
attempting to let this work on CPU only
Browse files
app.py
CHANGED
@@ -6,25 +6,21 @@ from PIL import Image
|
|
6 |
# Check for GPU availability and set the device variable accordingly
|
7 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
# Load the BLIP-2 model and processor (needs A10G)
|
14 |
-
#processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-6.7b-coco")
|
15 |
-
# Load model in int8 using bitsandbytes, and pass device_map='auto'
|
16 |
-
#model = Blip2ForConditionalGeneration.from_pretrained(
|
17 |
-
# "Salesforce/blip2-opt-6.7b-coco", load_in_8bit=True, device_map='auto'
|
18 |
-
#)
|
19 |
-
|
20 |
-
# Uncomment lines 20, 22, 23, & 24 to begin using blip2-opt-2.7b model (can run on T4 Medium)
|
21 |
-
|
22 |
# Load the BLIP-2 model and processor
|
23 |
processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
24 |
-
|
25 |
-
model
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
def blip2_interface(image, prompted_caption_text, vqa_question, chat_context):
|
30 |
# Prepare image input
|
|
|
6 |
# Check for GPU availability and set the device variable accordingly
|
7 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Load the BLIP-2 model and processor
|
10 |
processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
11 |
+
|
12 |
+
# Load model with additional parameters if GPU is available, else load without additional parameters
|
13 |
+
if torch.cuda.is_available():
|
14 |
+
device_map = {0: 'cpu', 1: 'cpu'} # Define a custom device map if needed
|
15 |
+
model = Blip2ForConditionalGeneration.from_pretrained(
|
16 |
+
"Salesforce/blip2-opt-2.7b",
|
17 |
+
load_in_8bit=True,
|
18 |
+
device_map=device_map,
|
19 |
+
load_in_8bit_fp32_cpu_offload=True
|
20 |
+
)
|
21 |
+
else:
|
22 |
+
model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b")
|
23 |
+
|
24 |
|
25 |
def blip2_interface(image, prompted_caption_text, vqa_question, chat_context):
|
26 |
# Prepare image input
|