Juna190825 commited on
Commit
5b7a0e3
·
verified ·
1 Parent(s): fba310c

Update Dockerfile

Browse files
Files changed (1) hide show
  1. app.py +27 -22
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
- model = AutoModelForCausalLM.from_pretrained(
138
- MODEL_ID,
139
- cache_dir=CACHE_DIR,
140
- local_files_only=True # Only use cache
141
- ).to(DEVICE)
142
- tokenizer = AutoTokenizer.from_pretrained(
143
- MODEL_ID,
144
- cache_dir=CACHE_DIR,
145
- local_files_only=True
146
- )
147
- # Fallback to download if cache missing
148
- else:
149
- print(f"Downloading model (attempt {attempt + 1})...")
150
- model = AutoModelForCausalLM.from_pretrained(
151
- MODEL_ID,
152
- cache_dir=CACHE_DIR
153
- ).to(DEVICE)
154
- tokenizer = AutoTokenizer.from_pretrained(
155
- MODEL_ID,
156
- cache_dir=CACHE_DIR
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) # Cap at 10 seconds
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