Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files
app.py
CHANGED
|
@@ -134,34 +134,39 @@ def load_model_with_retry(max_retries=3):
|
|
| 134 |
# First try loading from local cache only
|
| 135 |
if attempt == 0:
|
| 136 |
print("Attempting to load from local cache...")
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
return model, tokenizer
|
| 159 |
|
| 160 |
except Exception as e:
|
| 161 |
if attempt == max_retries - 1:
|
| 162 |
raise RuntimeError(f"Failed after {max_retries} attempts: {str(e)}")
|
| 163 |
|
| 164 |
-
wait_time = min(2 ** (attempt + 1), 10)
|
| 165 |
print(f"Attempt {attempt + 1} failed ({str(e)}), retrying in {wait_time}s...")
|
| 166 |
time.sleep(wait_time)
|
| 167 |
|
|
|
|
| 134 |
# First try loading from local cache only
|
| 135 |
if attempt == 0:
|
| 136 |
print("Attempting to load from local cache...")
|
| 137 |
+
try:
|
| 138 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 139 |
+
MODEL_ID,
|
| 140 |
+
cache_dir=CACHE_DIR,
|
| 141 |
+
local_files_only=True
|
| 142 |
+
).to(DEVICE)
|
| 143 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 144 |
+
MODEL_ID,
|
| 145 |
+
cache_dir=CACHE_DIR,
|
| 146 |
+
local_files_only=True
|
| 147 |
+
)
|
| 148 |
+
return model, tokenizer
|
| 149 |
+
except OSError:
|
| 150 |
+
print("Cache not found, will download...")
|
| 151 |
+
continue
|
| 152 |
+
|
| 153 |
+
# Download with retry
|
| 154 |
+
print(f"Downloading model (attempt {attempt + 1})...")
|
| 155 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 156 |
+
MODEL_ID,
|
| 157 |
+
cache_dir=CACHE_DIR
|
| 158 |
+
).to(DEVICE)
|
| 159 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 160 |
+
MODEL_ID,
|
| 161 |
+
cache_dir=CACHE_DIR
|
| 162 |
+
)
|
| 163 |
return model, tokenizer
|
| 164 |
|
| 165 |
except Exception as e:
|
| 166 |
if attempt == max_retries - 1:
|
| 167 |
raise RuntimeError(f"Failed after {max_retries} attempts: {str(e)}")
|
| 168 |
|
| 169 |
+
wait_time = min(2 ** (attempt + 1), 10)
|
| 170 |
print(f"Attempt {attempt + 1} failed ({str(e)}), retrying in {wait_time}s...")
|
| 171 |
time.sleep(wait_time)
|
| 172 |
|