Spaces:
Sleeping
Sleeping
Felipe Meres
commited on
Commit
·
8ec6e89
1
Parent(s):
1ddb064
Fix Florence-2 model compatibility issue
Browse files- Pin transformers to version 4.37.2 for Florence-2 compatibility
- Add attn_implementation="eager" to avoid SDPA issues
- Disable use_cache for better stability
- Remove flash-attn dependency to avoid CPU compatibility issues
This resolves the "'Florence2ForConditionalGeneration' object has no attribute '_supports_sdpa'" error.
- app.py +7 -1
- requirements.txt +3 -2
app.py
CHANGED
|
@@ -39,12 +39,18 @@ def load_florence_model():
|
|
| 39 |
|
| 40 |
print(f"Loading Florence-2 model on {device}...")
|
| 41 |
|
|
|
|
| 42 |
model = AutoModelForCausalLM.from_pretrained(
|
| 43 |
FLORENCE_MODEL_ID,
|
| 44 |
torch_dtype=torch.float16 if (torch.cuda.is_available() and not FORCE_CPU) else torch.float32,
|
| 45 |
-
trust_remote_code=True
|
|
|
|
| 46 |
).to(device)
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
processor = AutoProcessor.from_pretrained(FLORENCE_MODEL_ID, trust_remote_code=True)
|
| 49 |
|
| 50 |
model_cache['model'] = model
|
|
|
|
| 39 |
|
| 40 |
print(f"Loading Florence-2 model on {device}...")
|
| 41 |
|
| 42 |
+
# Load model with compatibility fixes
|
| 43 |
model = AutoModelForCausalLM.from_pretrained(
|
| 44 |
FLORENCE_MODEL_ID,
|
| 45 |
torch_dtype=torch.float16 if (torch.cuda.is_available() and not FORCE_CPU) else torch.float32,
|
| 46 |
+
trust_remote_code=True,
|
| 47 |
+
attn_implementation="eager" # Use eager attention for compatibility
|
| 48 |
).to(device)
|
| 49 |
|
| 50 |
+
# Fix for transformers compatibility issue
|
| 51 |
+
if hasattr(model, 'config'):
|
| 52 |
+
model.config.use_cache = False
|
| 53 |
+
|
| 54 |
processor = AutoProcessor.from_pretrained(FLORENCE_MODEL_ID, trust_remote_code=True)
|
| 55 |
|
| 56 |
model_cache['model'] = model
|
requirements.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
# Core dependencies -
|
| 2 |
gradio>=4.44.0,<5.0.0
|
| 3 |
torch>=2.0.0
|
| 4 |
torchvision>=0.15.0
|
| 5 |
-
transformers
|
| 6 |
Pillow>=9.0.0
|
| 7 |
numpy>=1.21.0
|
| 8 |
|
|
@@ -11,6 +11,7 @@ timm>=0.9.0
|
|
| 11 |
einops>=0.7.0
|
| 12 |
safetensors>=0.4.0
|
| 13 |
accelerate>=0.21.0
|
|
|
|
| 14 |
|
| 15 |
# PDF processing
|
| 16 |
pdf2image>=1.16.0
|
|
|
|
| 1 |
+
# Core dependencies - specific versions for Florence-2 compatibility
|
| 2 |
gradio>=4.44.0,<5.0.0
|
| 3 |
torch>=2.0.0
|
| 4 |
torchvision>=0.15.0
|
| 5 |
+
transformers==4.37.2
|
| 6 |
Pillow>=9.0.0
|
| 7 |
numpy>=1.21.0
|
| 8 |
|
|
|
|
| 11 |
einops>=0.7.0
|
| 12 |
safetensors>=0.4.0
|
| 13 |
accelerate>=0.21.0
|
| 14 |
+
# flash-attn>=2.5.0 # Commented out - can cause issues on CPU
|
| 15 |
|
| 16 |
# PDF processing
|
| 17 |
pdf2image>=1.16.0
|