load models to GPU during use to fit all versions
Browse files
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)
|
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,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)
|