Factor Studios commited on
Commit
81f8e82
·
verified ·
1 Parent(s): f9d329b

Update vision_analyzer.py

Browse files
Files changed (1) hide show
  1. vision_analyzer.py +18 -20
vision_analyzer.py CHANGED
@@ -21,6 +21,17 @@ import numpy as np
21
  from PIL import Image
22
  import torch
23
  from transformers import AutoProcessor, AutoModelForCausalLM
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  # Initialize FastAPI
26
  app = FastAPI()
@@ -79,27 +90,14 @@ import sys
79
  device = "cpu" # Explicitly ensure CPU usage
80
 
81
  try:
82
- # Load processor with padding configuration
83
- vision_processor = AutoProcessor.from_pretrained(
84
- "microsoft/git-base-coco",
85
- padding="max_length",
86
- truncation=True
87
- )
88
-
89
- # Load model with CPU optimizations
90
- vision_model = AutoModelForCausalLM.from_pretrained(
91
- "microsoft/git-base-coco",
92
- torch_dtype=torch.float32,
93
- low_cpu_mem_usage=True,
94
- device_map="cpu"
95
- ).eval()
96
-
97
- print("✅ Successfully loaded GIT model and processor")
98
-
99
  except Exception as e:
100
- print(f"Error loading model: {str(e)}")
101
- vision_model = None
102
- vision_processor = None
 
103
 
104
  # Preprompt templates
105
  PREPROMPT_TEMPLATES = {
 
21
  from PIL import Image
22
  import torch
23
  from transformers import AutoProcessor, AutoModelForCausalLM
24
+ # from transformers import AutoProcessor, AutoModelForCausalLM
25
+
26
+ # Attempt to install flash-attn
27
+ try:
28
+ subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, check=True, shell=True)
29
+ except subprocess.CalledProcessError as e:
30
+ print(f"Error installing flash-attn: {e}")
31
+ print("Continuing without flash-attn.")
32
+
33
+ # Determine the device to use
34
+ device = "cuda" if torch.cuda.is_available() else "cpu"
35
 
36
  # Initialize FastAPI
37
  app = FastAPI()
 
90
  device = "cpu" # Explicitly ensure CPU usage
91
 
92
  try:
93
+ vision_model = AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-base', trust_remote_code=True,
94
+ attn_implementation="eager" ).to(device).eval()
95
+ vision_processor = AutoProcessor.from_pretrained('microsoft/Florence-2-base', trust_remote_code=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  except Exception as e:
97
+ print(f"Error loading base model: {e}")
98
+ vision_language_model_base = None
99
+ vision_language_processor_base = None
100
+
101
 
102
  # Preprompt templates
103
  PREPROMPT_TEMPLATES = {