Spaces:
Running
on
Zero
Running
on
Zero
Update util/utils.py
Browse files- util/utils.py +15 -2
util/utils.py
CHANGED
|
@@ -59,12 +59,25 @@ def get_caption_model_processor(model_name, model_name_or_path="Salesforce/blip2
|
|
| 59 |
model_name_or_path, device_map=None, torch_dtype=torch.float16
|
| 60 |
).to(device)
|
| 61 |
elif model_name == "florence2":
|
|
|
|
| 62 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
|
|
|
|
|
|
| 63 |
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True)
|
|
|
|
| 64 |
if device == 'cpu':
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
else:
|
| 67 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return {'model': model.to(device), 'processor': processor}
|
| 69 |
|
| 70 |
|
|
|
|
| 59 |
model_name_or_path, device_map=None, torch_dtype=torch.float16
|
| 60 |
).to(device)
|
| 61 |
elif model_name == "florence2":
|
| 62 |
+
# Fixed: Use AutoProcessor and AutoModelForCausalLM to avoid deprecation warning
|
| 63 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
| 64 |
+
|
| 65 |
+
# Keep both processors - base for processor, ft for model
|
| 66 |
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True)
|
| 67 |
+
|
| 68 |
if device == 'cpu':
|
| 69 |
+
# Use AutoModelForCausalLM instead of direct Florence2 class
|
| 70 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 71 |
+
model_name_or_path,
|
| 72 |
+
torch_dtype=torch.float32,
|
| 73 |
+
trust_remote_code=True
|
| 74 |
+
)
|
| 75 |
else:
|
| 76 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 77 |
+
model_name_or_path,
|
| 78 |
+
torch_dtype=torch.float16,
|
| 79 |
+
trust_remote_code=True
|
| 80 |
+
).to(device)
|
| 81 |
return {'model': model.to(device), 'processor': processor}
|
| 82 |
|
| 83 |
|