ChirathD commited on
Commit
9467c14
1 Parent(s): 9e0a81f

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +12 -4
handler.py CHANGED
@@ -7,8 +7,9 @@ import io
7
  import base64
8
  from io import BytesIO
9
  # from transformers import BlipForConditionalGeneration, BlipProcessor
10
- from transformers import Blip2Processor, Blip2ForConditionalGeneration
11
-
 
12
 
13
  # -
14
 
@@ -18,10 +19,17 @@ class EndpointHandler():
18
  def __init__(self, path=""):
19
  # load the optimized model
20
  print("####### Start Deploying #####")
21
- self.processor = Blip2Processor.from_pretrained("ChirathD/Blip-2-test-1")
22
- self.model = Blip2ForConditionalGeneration.from_pretrained("ChirathD/Blip-2-test-1")
23
  # self.model.eval()
24
  # self.model = self.model.to(device)
 
 
 
 
 
 
 
25
 
26
 
27
 
 
7
  import base64
8
  from io import BytesIO
9
  # from transformers import BlipForConditionalGeneration, BlipProcessor
10
+ # from transformers import Blip2Processor, Blip2ForConditionalGeneration
11
+ from transformers import Blip2ForConditionalGeneration, AutoProcessor
12
+ from peft import PeftModel, PeftConfig
13
 
14
  # -
15
 
 
19
  def __init__(self, path=""):
20
  # load the optimized model
21
  print("####### Start Deploying #####")
22
+ # self.processor = Blip2Processor.from_pretrained("ChirathD/Blip-2-test-1")
23
+ # self.model = Blip2ForConditionalGeneration.from_pretrained("ChirathD/Blip-2-test-1")
24
  # self.model.eval()
25
  # self.model = self.model.to(device)
26
+
27
+ peft_model_id = "ChirathD/Blip-2-test-4"
28
+ config = PeftConfig.from_pretrained(peft_model_id)
29
+
30
+ self.model = Blip2ForConditionalGeneration.from_pretrained(config.base_model_name_or_path, load_in_8bit=True, device_map="auto")
31
+ self.model = PeftModel.from_pretrained(self.model, peft_model_id)
32
+ self.processor = AutoProcessor.from_pretrained("Salesforce/blip2-opt-2.7b")
33
 
34
 
35