iamrobotbear commited on
Commit
6fa10d1
·
1 Parent(s): ef3ce27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -3,9 +3,16 @@ from transformers import AutoProcessor, Blip2ForConditionalGeneration
3
  import torch
4
  from PIL import Image
5
 
6
- # Load the BLIP-2 model and processor with 8-bit loading
7
  processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
8
- model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", load_in_8bit=True)
 
 
 
 
 
 
 
9
 
10
  # Set device to GPU if available
11
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
3
  import torch
4
  from PIL import Image
5
 
6
+ # Load the BLIP-2 model and processor
7
  processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
8
+ # Load model in int8 using bitsandbytes, and pass device_map='auto'
9
+ model = Blip2ForConditionalGeneration.from_pretrained(
10
+ "Salesforce/blip2-opt-2.7b", load_in_8bit=True, device_map='auto'
11
+ )
12
+
13
+ # Set device to GPU if available
14
+ device = "cuda" if torch.cuda.is_available() else "cpu"
15
+ model.to(device)
16
 
17
  # Set device to GPU if available
18
  device = "cuda" if torch.cuda.is_available() else "cpu"