Spaces:
Build error
Build error
Wisdom Chen
commited on
Update model.py
Browse files
model.py
CHANGED
@@ -107,8 +107,7 @@ def initialize_models() -> bool:
|
|
107 |
global clip_model, clip_preprocess, clip_tokenizer, llm_tokenizer, llm_model, device
|
108 |
|
109 |
try:
|
110 |
-
# Force CPU
|
111 |
-
device = "cpu"
|
112 |
print(f"Initializing models on device: {device}")
|
113 |
|
114 |
# Initialize CLIP model with error handling
|
@@ -127,12 +126,6 @@ def initialize_models() -> bool:
|
|
127 |
try:
|
128 |
model_name = "mistralai/Mistral-7B-v0.1"
|
129 |
|
130 |
-
# CPU-compatible configuration
|
131 |
-
quantization_config = BitsAndBytesConfig(
|
132 |
-
load_in_8bit=True, # Use 8-bit instead of 4-bit
|
133 |
-
llm_int8_enable_fp32_cpu_offload=True # Enable CPU offloading
|
134 |
-
)
|
135 |
-
|
136 |
# Get token from Streamlit secrets
|
137 |
hf_token = st.secrets["HUGGINGFACE_TOKEN"]
|
138 |
|
@@ -146,9 +139,8 @@ def initialize_models() -> bool:
|
|
146 |
|
147 |
llm_model = AutoModelForCausalLM.from_pretrained(
|
148 |
model_name,
|
149 |
-
quantization_config=quantization_config,
|
150 |
device_map="auto",
|
151 |
-
low_cpu_mem_usage=True,
|
152 |
token=hf_token
|
153 |
)
|
154 |
llm_model.eval()
|
|
|
107 |
global clip_model, clip_preprocess, clip_tokenizer, llm_tokenizer, llm_model, device
|
108 |
|
109 |
try:
|
110 |
+
device = "cpu" # Force CPU usage for Streamlit Cloud
|
|
|
111 |
print(f"Initializing models on device: {device}")
|
112 |
|
113 |
# Initialize CLIP model with error handling
|
|
|
126 |
try:
|
127 |
model_name = "mistralai/Mistral-7B-v0.1"
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
# Get token from Streamlit secrets
|
130 |
hf_token = st.secrets["HUGGINGFACE_TOKEN"]
|
131 |
|
|
|
139 |
|
140 |
llm_model = AutoModelForCausalLM.from_pretrained(
|
141 |
model_name,
|
|
|
142 |
device_map="auto",
|
143 |
+
low_cpu_mem_usage=True,
|
144 |
token=hf_token
|
145 |
)
|
146 |
llm_model.eval()
|