CoolFace
Apppublic

EmbodiedAgentInterface/backend

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
main_backend_lighteval.py92 linesDownload Raw Back to root
1import logging2import pprint3 4from huggingface_hub import snapshot_download5 6logging.getLogger("openai").setLevel(logging.WARNING)7 8from src.backend.run_eval_suite_lighteval import run_evaluation9from src.backend.manage_requests import check_completed_evals, get_eval_requests, set_eval_request10from src.backend.sort_queue import sort_models_by_priority11 12from src.envs import QUEUE_REPO, EVAL_REQUESTS_PATH_BACKEND, RESULTS_REPO, EVAL_RESULTS_PATH_BACKEND, API, LIMIT, TOKEN, ACCELERATOR, VENDOR, REGION13from src.about import TASKS_LIGHTEVAL14from src.logging import setup_logger15 16logger = setup_logger(__name__)17 18# logging.basicConfig(level=logging.ERROR)19pp = pprint.PrettyPrinter(width=80)20 21PENDING_STATUS = "PENDING"22RUNNING_STATUS = "RUNNING"23FINISHED_STATUS = "FINISHED"24FAILED_STATUS = "FAILED"25 26snapshot_download(repo_id=RESULTS_REPO, revision="main", local_dir=EVAL_RESULTS_PATH_BACKEND, repo_type="dataset", max_workers=60, token=TOKEN)27snapshot_download(repo_id=QUEUE_REPO, revision="main", local_dir=EVAL_REQUESTS_PATH_BACKEND, repo_type="dataset", max_workers=60, token=TOKEN)28 29def run_auto_eval():30    current_pending_status = [PENDING_STATUS]31 32    # pull the eval dataset from the hub and parse any eval requests33    # check completed evals and set them to finished34    check_completed_evals(35        api=API,36        checked_status=RUNNING_STATUS,37        completed_status=FINISHED_STATUS,38        failed_status=FAILED_STATUS,39        hf_repo=QUEUE_REPO,40        local_dir=EVAL_REQUESTS_PATH_BACKEND,41        hf_repo_results=RESULTS_REPO,42        local_dir_results=EVAL_RESULTS_PATH_BACKEND43    )44 45    # Get all eval request that are PENDING, if you want to run other evals, change this parameter46    eval_requests = get_eval_requests(job_status=current_pending_status, hf_repo=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH_BACKEND)47    # Sort the evals by priority (first submitted first run)48    eval_requests = sort_models_by_priority(api=API, models=eval_requests)49 50    logger.info(f"Found {len(eval_requests)} {','.join(current_pending_status)} eval requests")51 52    if len(eval_requests) == 0:53        return54 55    eval_request = eval_requests[0]56    logger.info(pp.pformat(eval_request))57 58 59    set_eval_request(60        api=API,61        eval_request=eval_request,62        set_to_status=RUNNING_STATUS,63        hf_repo=QUEUE_REPO,64        local_dir=EVAL_REQUESTS_PATH_BACKEND,65    )66 67    # This needs to be done68    #instance_size, instance_type = get_instance_for_model(eval_request)69    # For GPU70    # instance_size, instance_type = "small", "g4dn.xlarge" 71    # For CPU72    instance_size, instance_type = "medium", "c6i"73    logger.info(f'Starting Evaluation of {eval_request.json_filepath} on Inference endpoints: {instance_size} {instance_type}')74 75    run_evaluation(76        eval_request=eval_request, 77        task_names=TASKS_LIGHTEVAL, 78        local_dir=EVAL_RESULTS_PATH_BACKEND,79        batch_size=1, 80        accelerator=ACCELERATOR, 81        region=REGION, 82        vendor=VENDOR, 83        instance_size=instance_size, 84        instance_type=instance_type,  85        limit=LIMIT86        )87 88    logger.info(f'Completed Evaluation of {eval_request.json_filepath} on Inference endpoints: {instance_size} {instance_type}')89 90 91if __name__ == "__main__":92    run_auto_eval()