File size: 1,952 Bytes
13c6f75
 
 
92305c2
13c6f75
 
 
 
 
9704550
13c6f75
 
 
 
8eccf98
 
 
 
 
9704550
8eccf98
4402217
8eccf98
4402217
8eccf98
 
 
9704550
8eccf98
 
9704550
92305c2
 
8a060db
92305c2
9704550
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
from fastapi import FastAPI
from huggingface_hub import HfApi
import time

TOKEN = os.environ.get("BULK_ENERGY_TOKEN")
API = HfApi(token=TOKEN)

REPO_ID = "AIEnergyScore/BulkCalcSpace"
RESULTS_DSET = "AIEnergyScore/BulkCalcResults"
app = FastAPI()

@app.get("/")
def start_train():
    model_file = open("models.txt", "r+").readlines()
    task_file = open("tasks.txt", "r+").readlines()
    hardware_file = open("hardware.txt", "r+").readlines()
    for hardware in hardware_file:
        hardware = hardware.strip()
        print(f"Requested hardware is {hardware}")
        curr_runtime = API.get_space_runtime(repo_id=REPO_ID)
        print(f"Current hardware is {curr_runtime}")
        if curr_runtime != hardware:
            print("Trying to switch.")
            API.request_space_hardware(repo_id=REPO_ID, hardware=hardware)
        for model in model_file:
            model = model.strip()
            print(f"Attempting to benchmark model {model}.")
            for task in task_file:
                task = task.strip()
                print(f"Attempting to benchmark model {model} on task {task}.")
                # Create the name of the directory for output.
                now = time.time()
                run_dir = f"runs/{task}/{model}/{now}"
                os.system(f"./entrypoint.sh {REPO_ID} {model} {task} {hardware} {run_dir}")
                # Uploads all run output to the results dataset.
                print(f"Uploading {run_dir} to {RESULTS_DSET}")
                try:
                    API.create_repo(repo_id=f"{RESULTS_DSET}", repo_type="dataset",)
                    print(f"Created results dataset repository")
                except:
                    print(f"Using pre-existing dataset respository.")
                API.upload_folder(folder_path=run_dir, repo_id=f"{RESULTS_DSET}", repo_type="dataset",)
    print("Pausing space")
    API.pause_space(REPO_ID)
    #return {"Status": "Done"}