Fred808 commited on
Commit
6a89b7c
·
verified ·
1 Parent(s): 32d750e

Update vision_analyzer.py

Browse files
Files changed (1) hide show
  1. vision_analyzer.py +17 -35
vision_analyzer.py CHANGED
@@ -76,41 +76,23 @@ import torch
76
  import subprocess
77
  import sys
78
 
79
- def configure_environment():
80
- # Determine device first
81
- device = "cuda" if torch.cuda.is_available() else "cpu"
82
-
83
- # Only attempt flash-attn on CUDA
84
- if device == "cuda":
85
- try:
86
- subprocess.run(
87
- [
88
- sys.executable, "-m", "pip", "install",
89
- "flash-attn==2.5.8", # Pinned version
90
- "--no-build-isolation",
91
- "--no-cache-dir"
92
- ],
93
- env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "1"},
94
- check=True,
95
- capture_output=True,
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"""