Update vision_analyzer.py
Browse files- vision_analyzer.py +17 -35
vision_analyzer.py
CHANGED
|
@@ -76,41 +76,23 @@ import torch
|
|
| 76 |
import subprocess
|
| 77 |
import sys
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
text=True
|
| 97 |
-
)
|
| 98 |
-
print("Successfully installed flash-attn with CUDA support")
|
| 99 |
-
except subprocess.CalledProcessError as e:
|
| 100 |
-
print(f"Flash-attn installation failed (non-critical): {e.stderr}")
|
| 101 |
-
print("Falling back to standard attention mechanisms")
|
| 102 |
-
|
| 103 |
-
return device
|
| 104 |
-
|
| 105 |
-
# Usage
|
| 106 |
-
device = configure_environment()
|
| 107 |
-
print(f"Using device: {device}")
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
model_id = "microsoft/Florence-2-large"
|
| 111 |
-
# Either use CPU:
|
| 112 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True).eval()
|
| 113 |
-
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
| 114 |
|
| 115 |
def log_message(message: str):
|
| 116 |
"""Log messages with timestamp"""
|
|
|
|
| 76 |
import subprocess
|
| 77 |
import sys
|
| 78 |
|
| 79 |
+
try:
|
| 80 |
+
subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, check=True, shell=True)
|
| 81 |
+
except subprocess.CalledProcessError as e:
|
| 82 |
+
print(f"Error installing flash-attn: {e}")
|
| 83 |
+
print("Continuing without flash-attn.")
|
| 84 |
+
|
| 85 |
+
# Determine the device to use
|
| 86 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
try:
|
| 90 |
+
vision_language_model_large = AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-large', trust_remote_code=True).to(device).eval()
|
| 91 |
+
vision_language_processor_large = AutoProcessor.from_pretrained('microsoft/Florence-2-large', trust_remote_code=True)
|
| 92 |
+
except Exception as e:
|
| 93 |
+
print(f"Error loading large model: {e}")
|
| 94 |
+
vision_language_model_large = None
|
| 95 |
+
vision_language_processor_large = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
def log_message(message: str):
|
| 98 |
"""Log messages with timestamp"""
|