maxiw commited on
Commit
3858798
1 Parent(s): c46a8ee

load models to GPU during use to fit all versions

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -5,10 +5,10 @@ import torch
5
  from PIL import Image
6
 
7
  models = {
8
- "Salesforce/xgen-mm-phi3-mini-instruct-r-v1": AutoModelForVision2Seq.from_pretrained("Salesforce/xgen-mm-phi3-mini-instruct-r-v1", trust_remote_code=True).to("cuda").eval(),
9
- "Salesforce/xgen-mm-phi3-mini-instruct-interleave-r-v1.5": AutoModelForVision2Seq.from_pretrained("Salesforce/xgen-mm-phi3-mini-instruct-interleave-r-v1.5", trust_remote_code=True).to("cuda").eval(),
10
- "Salesforce/xgen-mm-phi3-mini-instruct-singleimg-r-v1.5": AutoModelForVision2Seq.from_pretrained("Salesforce/xgen-mm-phi3-mini-instruct-singleimg-r-v1.5", trust_remote_code=True).to("cuda").eval(),
11
- "Salesforce/xgen-mm-phi3-mini-instruct-dpo-r-v1.5": AutoModelForVision2Seq.from_pretrained("Salesforce/xgen-mm-phi3-mini-instruct-dpo-r-v1.5", trust_remote_code=True).to("cuda").eval()
12
  }
13
 
14
  processors = {
@@ -49,7 +49,7 @@ class EosListStoppingCriteria(StoppingCriteria):
49
 
50
  @spaces.GPU
51
  def run_example(image, text_input=None, model_id="Salesforce/xgen-mm-phi3-mini-instruct-interleave-r-v1.5"):
52
- model = models[model_id]
53
  processor = processors[model_id]
54
  tokenizer = tokenizers[model_id]
55
  tokenizer = model.update_special_tokens(tokenizer)
 
5
  from PIL import Image
6
 
7
  models = {
8
+ "Salesforce/xgen-mm-phi3-mini-instruct-r-v1": AutoModelForVision2Seq.from_pretrained("Salesforce/xgen-mm-phi3-mini-instruct-r-v1", trust_remote_code=True),
9
+ "Salesforce/xgen-mm-phi3-mini-instruct-interleave-r-v1.5": AutoModelForVision2Seq.from_pretrained("Salesforce/xgen-mm-phi3-mini-instruct-interleave-r-v1.5", trust_remote_code=True),
10
+ "Salesforce/xgen-mm-phi3-mini-instruct-singleimg-r-v1.5": AutoModelForVision2Seq.from_pretrained("Salesforce/xgen-mm-phi3-mini-instruct-singleimg-r-v1.5", trust_remote_code=True),
11
+ "Salesforce/xgen-mm-phi3-mini-instruct-dpo-r-v1.5": AutoModelForVision2Seq.from_pretrained("Salesforce/xgen-mm-phi3-mini-instruct-dpo-r-v1.5", trust_remote_code=True)
12
  }
13
 
14
  processors = {
 
49
 
50
  @spaces.GPU
51
  def run_example(image, text_input=None, model_id="Salesforce/xgen-mm-phi3-mini-instruct-interleave-r-v1.5"):
52
+ model = models[model_id].to("cuda").eval()
53
  processor = processors[model_id]
54
  tokenizer = tokenizers[model_id]
55
  tokenizer = model.update_special_tokens(tokenizer)