Spaces:
Build error
Build error
Wisdom Chen
commited on
Update model.py
Browse files
model.py
CHANGED
@@ -52,17 +52,31 @@ def initialize_models() -> bool:
|
|
52 |
try:
|
53 |
print(f"Initializing models on device: {device}")
|
54 |
|
55 |
-
# Initialize CLIP model with error handling
|
56 |
try:
|
|
|
57 |
clip_model, _, clip_preprocess = open_clip.create_model_and_transforms(
|
58 |
-
'hf-hub:Marqo/marqo-fashionCLIP'
|
|
|
59 |
)
|
60 |
-
clip_model = clip_model.to(device)
|
61 |
clip_model.eval()
|
62 |
clip_tokenizer = open_clip.get_tokenizer('hf-hub:Marqo/marqo-fashionCLIP')
|
63 |
print("CLIP model initialized successfully")
|
64 |
except Exception as e:
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
# Initialize LLM with optimized settings
|
68 |
try:
|
@@ -94,7 +108,8 @@ def initialize_models() -> bool:
|
|
94 |
quantization_config=quantization_config,
|
95 |
device_map="auto",
|
96 |
torch_dtype=torch.float16,
|
97 |
-
token=hf_token
|
|
|
98 |
)
|
99 |
llm_model.eval()
|
100 |
print("LLM initialized successfully")
|
|
|
52 |
try:
|
53 |
print(f"Initializing models on device: {device}")
|
54 |
|
55 |
+
# Initialize CLIP model with error handling and fallback
|
56 |
try:
|
57 |
+
# First try loading with device mapping
|
58 |
clip_model, _, clip_preprocess = open_clip.create_model_and_transforms(
|
59 |
+
'hf-hub:Marqo/marqo-fashionCLIP',
|
60 |
+
device=device
|
61 |
)
|
|
|
62 |
clip_model.eval()
|
63 |
clip_tokenizer = open_clip.get_tokenizer('hf-hub:Marqo/marqo-fashionCLIP')
|
64 |
print("CLIP model initialized successfully")
|
65 |
except Exception as e:
|
66 |
+
print(f"CLIP initialization error: {str(e)}")
|
67 |
+
print("Attempting to load CLIP model with CPU fallback...")
|
68 |
+
try:
|
69 |
+
# Fallback to CPU
|
70 |
+
device = "cpu"
|
71 |
+
clip_model, _, clip_preprocess = open_clip.create_model_and_transforms(
|
72 |
+
'hf-hub:Marqo/marqo-fashionCLIP',
|
73 |
+
device=device
|
74 |
+
)
|
75 |
+
clip_model.eval()
|
76 |
+
clip_tokenizer = open_clip.get_tokenizer('hf-hub:Marqo/marqo-fashionCLIP')
|
77 |
+
print("CLIP model initialized successfully on CPU")
|
78 |
+
except Exception as cpu_e:
|
79 |
+
raise RuntimeError(f"Failed to initialize CLIP model on CPU: {str(cpu_e)}")
|
80 |
|
81 |
# Initialize LLM with optimized settings
|
82 |
try:
|
|
|
108 |
quantization_config=quantization_config,
|
109 |
device_map="auto",
|
110 |
torch_dtype=torch.float16,
|
111 |
+
token=hf_token,
|
112 |
+
low_cpu_mem_usage=False # Disable low CPU memory usage to prevent meta tensor issues
|
113 |
)
|
114 |
llm_model.eval()
|
115 |
print("LLM initialized successfully")
|