hamzabouajila commited on
Commit
29e54f1
·
1 Parent(s): 742dfc3

update evaluator to start if pending models were found

Browse files
Files changed (1) hide show
  1. src/evaluator/evaluate.py +117 -2
src/evaluator/evaluate.py CHANGED
@@ -295,9 +295,124 @@ def process_evaluation_queue():
295
  print(f"Evaluation requests path does not exist: {EVAL_REQUESTS_PATH}")
296
  return
297
 
 
 
 
 
298
  pending_files = []
299
- for file in os.listdir(EVAL_REQUESTS_PATH):
300
- if file.endswith('.json'):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  pending_files.append(os.path.join(EVAL_REQUESTS_PATH, file))
302
 
303
  print(f"Found {len(pending_files)} pending evaluation requests")
 
295
  print(f"Evaluation requests path does not exist: {EVAL_REQUESTS_PATH}")
296
  return
297
 
298
+ # Find all model directories (each model has its own directory)
299
+ model_dirs = [d for d in os.listdir(EVAL_REQUESTS_PATH) if os.path.isdir(os.path.join(EVAL_REQUESTS_PATH, d))]
300
+ print(f"Found {len(model_dirs)} model directories")
301
+
302
  pending_files = []
303
+ for model_dir in model_dirs:
304
+ model_dir_path = os.path.join(EVAL_REQUESTS_PATH, model_dir)
305
+ print(f"\nChecking model directory: {model_dir_path}")
306
+
307
+ # Find all JSON files in the model directory
308
+ json_files = [f for f in os.listdir(model_dir_path) if f.endswith('.json')]
309
+ print(f"Found {len(json_files)} JSON files in {model_dir}")
310
+
311
+ for file in json_files:
312
+ file_path = os.path.join(model_dir_path, file)
313
+ try:
314
+ with open(file_path, 'r') as f:
315
+ eval_entry = json.load(f)
316
+
317
+ # Check if this is a pending evaluation
318
+ if eval_entry.get('status') == EvaluationStatus.PENDING.value:
319
+ print(f"\n=== Found pending evaluation ===")
320
+ print(f"Model: {eval_entry['model']}")
321
+ print(f"Revision: {eval_entry['revision']}")
322
+ print(f"Precision: {eval_entry['precision']}")
323
+ print(f"Weight type: {eval_entry['weight_type']}")
324
+
325
+ # Update status to RUNNING
326
+ eval_entry['status'] = EvaluationStatus.RUNNING.value
327
+ with open(file_path, 'w') as f:
328
+ json.dump(eval_entry, f, indent=2)
329
+
330
+ # Run evaluation
331
+ try:
332
+ print("\n=== Starting evaluation ===")
333
+ eval_result = evaluate_model(
334
+ model_name=eval_entry['model'],
335
+ revision=eval_entry['revision'],
336
+ precision=eval_entry['precision'],
337
+ weight_type=eval_entry['weight_type']
338
+ )
339
+
340
+ print("\n=== Evaluation completed ===")
341
+ print(f"Results: {eval_result.results}")
342
+
343
+ # Update status to FINISHED and add results
344
+ eval_entry['status'] = EvaluationStatus.FINISHED.value
345
+ eval_entry['results'] = eval_result.results
346
+
347
+ if eval_result.error:
348
+ eval_entry['error'] = eval_result.error
349
+
350
+ # Save updated entry
351
+ with open(file_path, 'w') as f:
352
+ json.dump(eval_entry, f, indent=2)
353
+
354
+ # Move file to results directory
355
+ if not os.path.exists(EVAL_RESULTS_PATH):
356
+ os.makedirs(EVAL_RESULTS_PATH)
357
+
358
+ result_filename = os.path.basename(file_path)
359
+ result_path = os.path.join(EVAL_RESULTS_PATH, result_filename)
360
+
361
+ os.rename(file_path, result_path)
362
+ print(f"\nMoved evaluation result to: {result_path}")
363
+
364
+ # Upload to Hugging Face
365
+ try:
366
+ API.upload_file(
367
+ path_or_fileobj=result_path,
368
+ path_in_repo=result_filename,
369
+ repo_id=RESULTS_REPO,
370
+ repo_type="dataset",
371
+ commit_message=f"Add evaluation results for {eval_entry['model']}"
372
+ )
373
+ print("\nResults uploaded to Hugging Face")
374
+ except Exception as upload_error:
375
+ print(f"Error uploading results: {str(upload_error)}")
376
+ eval_entry['error'] = f"Evaluation completed but failed to upload results: {str(upload_error)}"
377
+ with open(file_path, 'w') as f:
378
+ json.dump(eval_entry, f, indent=2)
379
+ except Exception as eval_error:
380
+ print(f"\n=== Error during evaluation ===")
381
+ print(f"Error: {str(eval_error)}")
382
+ print(f"Full traceback: {traceback.format_exc()}")
383
+
384
+ # Update status to FAILED and add error
385
+ eval_entry['status'] = EvaluationStatus.FAILED.value
386
+ eval_entry['error'] = str(eval_error)
387
+
388
+ with open(file_path, 'w') as f:
389
+ json.dump(eval_entry, f, indent=2)
390
+
391
+ # Move failed evaluation to results directory
392
+ if not os.path.exists(EVAL_RESULTS_PATH):
393
+ os.makedirs(EVAL_RESULTS_PATH)
394
+
395
+ result_filename = os.path.basename(file_path)
396
+ result_path = os.path.join(EVAL_RESULTS_PATH, result_filename)
397
+
398
+ os.rename(file_path, result_path)
399
+ print(f"\nMoved failed evaluation to: {result_path}")
400
+
401
+ # Upload error file
402
+ try:
403
+ API.upload_file(
404
+ path_or_fileobj=result_path,
405
+ path_in_repo=result_filename,
406
+ repo_id=RESULTS_REPO,
407
+ repo_type="dataset",
408
+ commit_message=f"Add evaluation error for {eval_entry['model']}"
409
+ )
410
+ print("\nError file uploaded to Hugging Face")
411
+ except Exception as upload_error:
412
+ print(f"Error uploading error file: {str(upload_error)}")
413
+ except Exception as e:
414
+ print(f"Error processing file {file}: {str(e)}")
415
+ print(f"Full traceback: {traceback.format_exc()}")
416
  pending_files.append(os.path.join(EVAL_REQUESTS_PATH, file))
417
 
418
  print(f"Found {len(pending_files)} pending evaluation requests")