zamal commited on
Commit
27298b1
·
verified ·
1 Parent(s): 0f63890

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -3
main.py CHANGED
@@ -172,8 +172,12 @@ def fetch_github_repositories(query, max_results=10):
172
  # ---------------------------
173
  # Dense Retrieval Model Setup
174
  # ---------------------------
175
- model = SentenceTransformer('all-mpnet-base-v2', device='cuda')
176
-
 
 
 
 
177
  def robust_min_max_norm(scores):
178
  min_val = scores.min()
179
  max_val = scores.max()
@@ -185,7 +189,11 @@ def robust_min_max_norm(scores):
185
  # Cross-Encoder Re-Ranking Function
186
  # ---------------------------
187
  def cross_encoder_rerank_candidates(candidates, query, model_name, top_n=10):
188
- cross_encoder = CrossEncoder(model_name, device='cuda')
 
 
 
 
189
  CHUNK_SIZE = 2000
190
  MAX_DOC_LENGTH = 5000
191
  MIN_DOC_LENGTH = 200
 
172
  # ---------------------------
173
  # Dense Retrieval Model Setup
174
  # ---------------------------
175
+ try:
176
+ model = SentenceTransformer('all-mpnet-base-v2', device='cuda')
177
+ except Exception as e:
178
+ print("Error initializing GPU for SentenceTransformer; falling back to CPU:", e)
179
+ model = SentenceTransformer('all-mpnet-base-v2', device='cpu')
180
+
181
  def robust_min_max_norm(scores):
182
  min_val = scores.min()
183
  max_val = scores.max()
 
189
  # Cross-Encoder Re-Ranking Function
190
  # ---------------------------
191
  def cross_encoder_rerank_candidates(candidates, query, model_name, top_n=10):
192
+ try:
193
+ cross_encoder = CrossEncoder(model_name, device='cuda')
194
+ except Exception as e:
195
+ print("Error initializing CrossEncoder on GPU; falling back to CPU:", e)
196
+ cross_encoder = CrossEncoder(model_name, device='cpu')
197
  CHUNK_SIZE = 2000
198
  MAX_DOC_LENGTH = 5000
199
  MIN_DOC_LENGTH = 200