Spaces:
Sleeping
Sleeping
Clémentine
commited on
Commit
·
80d548a
1
Parent(s):
a092a3a
slight reorg
Browse files- app.py +14 -62
- globals.py +1 -1
- utils/io.py +6 -0
- utils/jobs.py +24 -1
app.py
CHANGED
|
@@ -3,8 +3,8 @@ import time
|
|
| 3 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 4 |
import threading
|
| 5 |
import globals
|
| 6 |
-
from utils.io import initialize_models_providers_file, save_results, load_results, load_models_providers, get_results_table
|
| 7 |
-
from utils.jobs import run_single_job, launch_jobs, update_job_statuses
|
| 8 |
from typing import List, Optional
|
| 9 |
|
| 10 |
|
|
@@ -31,12 +31,19 @@ def create_app() -> gr.Blocks:
|
|
| 31 |
with gr.Row():
|
| 32 |
init_btn = gr.Button("Fetch and Initialize Models/Providers", variant="secondary")
|
| 33 |
launch_btn = gr.Button("Launch All Jobs", variant="primary")
|
| 34 |
-
relaunch_all_btn = gr.Button("Relaunch All", variant="primary")
|
| 35 |
relaunch_failed_btn = gr.Button("Relaunch Failed", variant="stop")
|
| 36 |
refresh_btn = gr.Button("Refresh Results", variant="secondary")
|
| 37 |
|
| 38 |
output = gr.Textbox(label="Status", interactive=False)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
with gr.Row():
|
| 41 |
with gr.Column():
|
| 42 |
gr.Markdown("## Job Results")
|
|
@@ -52,77 +59,22 @@ def create_app() -> gr.Blocks:
|
|
| 52 |
elem_id="results_table"
|
| 53 |
)
|
| 54 |
|
| 55 |
-
def update_model_choices() -> gr.update:
|
| 56 |
-
models_providers = load_models_providers(globals.LOCAL_CONFIG_FILE)
|
| 57 |
-
model_choices = sorted(list(set([mp[0] for mp in models_providers])))
|
| 58 |
-
return gr.update(choices=model_choices, value=model_choices[0] if model_choices else None)
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
def update_provider_choices(model: Optional[str]) -> gr.update:
|
| 62 |
-
"""Update provider dropdown based on selected model."""
|
| 63 |
-
if not model:
|
| 64 |
-
return gr.update(choices=[])
|
| 65 |
-
|
| 66 |
-
# Get providers for the selected model from the config file
|
| 67 |
-
models_providers = load_models_providers(globals.LOCAL_CONFIG_FILE)
|
| 68 |
-
providers = [mp[1] for mp in models_providers if mp[0] == model]
|
| 69 |
-
|
| 70 |
-
return gr.update(choices=providers, value=providers[0] if providers else None)
|
| 71 |
|
| 72 |
# Event handlers
|
| 73 |
init_btn.click(
|
| 74 |
fn=initialize_models_providers_file,
|
| 75 |
outputs=output
|
| 76 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
launch_btn.click(
|
| 79 |
fn=launch_jobs,
|
| 80 |
outputs=output
|
| 81 |
)
|
| 82 |
|
| 83 |
-
def relaunch_all_jobs():
|
| 84 |
-
"""Relaunch all existing model-provider combinations from job results."""
|
| 85 |
-
if not globals.job_results:
|
| 86 |
-
return "No existing jobs to relaunch"
|
| 87 |
-
|
| 88 |
-
relaunched_count = 0
|
| 89 |
-
for key, info in globals.job_results.items():
|
| 90 |
-
model = info["model"]
|
| 91 |
-
provider = info["provider"]
|
| 92 |
-
job_id = run_single_job(model, provider, globals.TASKS)
|
| 93 |
-
if job_id != -1:
|
| 94 |
-
relaunched_count += 1
|
| 95 |
-
time.sleep(2) # Small delay between launches to avoid rate limiting
|
| 96 |
-
|
| 97 |
-
return f"Relaunched {relaunched_count}/{len(globals.job_results)} jobs"
|
| 98 |
-
|
| 99 |
-
relaunch_all_btn.click(
|
| 100 |
-
fn=relaunch_all_jobs,
|
| 101 |
-
outputs=output
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
def relaunch_failed_jobs():
|
| 105 |
-
"""Relaunch only failed model-provider combinations from job results."""
|
| 106 |
-
if not globals.job_results:
|
| 107 |
-
return "No existing jobs to relaunch"
|
| 108 |
-
|
| 109 |
-
failed_jobs = [(key, info) for key, info in globals.job_results.items()
|
| 110 |
-
if info.get("status") in ["ERROR", "FAILED"]]
|
| 111 |
-
|
| 112 |
-
if not failed_jobs:
|
| 113 |
-
return "No failed jobs to relaunch"
|
| 114 |
-
|
| 115 |
-
relaunched_count = 0
|
| 116 |
-
for key, info in failed_jobs:
|
| 117 |
-
model = info["model"]
|
| 118 |
-
provider = info["provider"]
|
| 119 |
-
job_id = run_single_job(model, provider, globals.TASKS)
|
| 120 |
-
if job_id != -1:
|
| 121 |
-
relaunched_count += 1
|
| 122 |
-
time.sleep(2) # Small delay between launches to avoid rate limiting
|
| 123 |
-
|
| 124 |
-
return f"Relaunched {relaunched_count}/{len(failed_jobs)} failed jobs"
|
| 125 |
-
|
| 126 |
relaunch_failed_btn.click(
|
| 127 |
fn=relaunch_failed_jobs,
|
| 128 |
outputs=output
|
|
|
|
| 3 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 4 |
import threading
|
| 5 |
import globals
|
| 6 |
+
from utils.io import initialize_models_providers_file, save_results, load_results, load_models_providers, get_results_table, load_models_providers_str
|
| 7 |
+
from utils.jobs import run_single_job, launch_jobs, update_job_statuses, relaunch_failed_jobs
|
| 8 |
from typing import List, Optional
|
| 9 |
|
| 10 |
|
|
|
|
| 31 |
with gr.Row():
|
| 32 |
init_btn = gr.Button("Fetch and Initialize Models/Providers", variant="secondary")
|
| 33 |
launch_btn = gr.Button("Launch All Jobs", variant="primary")
|
|
|
|
| 34 |
relaunch_failed_btn = gr.Button("Relaunch Failed", variant="stop")
|
| 35 |
refresh_btn = gr.Button("Refresh Results", variant="secondary")
|
| 36 |
|
| 37 |
output = gr.Textbox(label="Status", interactive=False)
|
| 38 |
|
| 39 |
+
# Accordion for viewing models/providers list
|
| 40 |
+
with gr.Accordion("Models/Providers Configuration", open=False):
|
| 41 |
+
models_providers_display = gr.Code(
|
| 42 |
+
label="Current Models and Providers",
|
| 43 |
+
value=load_models_providers_str(),
|
| 44 |
+
interactive=False,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
with gr.Row():
|
| 48 |
with gr.Column():
|
| 49 |
gr.Markdown("## Job Results")
|
|
|
|
| 59 |
elem_id="results_table"
|
| 60 |
)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# Event handlers
|
| 64 |
init_btn.click(
|
| 65 |
fn=initialize_models_providers_file,
|
| 66 |
outputs=output
|
| 67 |
)
|
| 68 |
+
init_btn.click(
|
| 69 |
+
fn=load_models_providers_str,
|
| 70 |
+
outputs=models_providers_display
|
| 71 |
+
)
|
| 72 |
|
| 73 |
launch_btn.click(
|
| 74 |
fn=launch_jobs,
|
| 75 |
outputs=output
|
| 76 |
)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
relaunch_failed_btn.click(
|
| 79 |
fn=relaunch_failed_jobs,
|
| 80 |
outputs=output
|
globals.py
CHANGED
|
@@ -11,7 +11,7 @@ job_results: Dict[str, JobResult] = {} # {model_provider_key: JobResult}
|
|
| 11 |
results_lock: threading.Lock = threading.Lock()
|
| 12 |
|
| 13 |
# Configuration
|
| 14 |
-
NUM_MODELS_RUN: int =
|
| 15 |
RESULTS_DATASET_NAME: str = "IPTesting/inference-provider-test-results"
|
| 16 |
LOCAL_CONFIG_FILE: str = "model_providers.txt"
|
| 17 |
TASKS: str = "extended|ifeval|0,lighteval|gsm_plus|0,lighteval|gpqa:diamond|0"
|
|
|
|
| 11 |
results_lock: threading.Lock = threading.Lock()
|
| 12 |
|
| 13 |
# Configuration
|
| 14 |
+
NUM_MODELS_RUN: int = 100
|
| 15 |
RESULTS_DATASET_NAME: str = "IPTesting/inference-provider-test-results"
|
| 16 |
LOCAL_CONFIG_FILE: str = "model_providers.txt"
|
| 17 |
TASKS: str = "extended|ifeval|0,lighteval|gsm_plus|0,lighteval|gpqa:diamond|0"
|
utils/io.py
CHANGED
|
@@ -48,6 +48,12 @@ def initialize_models_providers_file(file_path: str = globals.LOCAL_CONFIG_FILE)
|
|
| 48 |
return f"Initialized {count} model-provider combinations"
|
| 49 |
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
def load_models_providers(file_path: str = globals.LOCAL_CONFIG_FILE) -> List[Tuple[str, str]]:
|
| 52 |
"""Load models and providers from text file."""
|
| 53 |
models_providers = []
|
|
|
|
| 48 |
return f"Initialized {count} model-provider combinations"
|
| 49 |
|
| 50 |
|
| 51 |
+
def load_models_providers_str(file_path: str = globals.LOCAL_CONFIG_FILE) -> str:
|
| 52 |
+
mp_list = load_models_providers(file_path)
|
| 53 |
+
|
| 54 |
+
return "\n".join([f"{model} : {provider}" for (model, provider) in mp_list])
|
| 55 |
+
|
| 56 |
+
|
| 57 |
def load_models_providers(file_path: str = globals.LOCAL_CONFIG_FILE) -> List[Tuple[str, str]]:
|
| 58 |
"""Load models and providers from text file."""
|
| 59 |
models_providers = []
|
utils/jobs.py
CHANGED
|
@@ -118,7 +118,7 @@ def run_single_job(model: str, provider: str, tasks: str = globals.TASKS) -> Opt
|
|
| 118 |
print(f"Job launched: ID={job_id}, model={model}, provider={provider}")
|
| 119 |
return job_id
|
| 120 |
|
| 121 |
-
|
| 122 |
def launch_jobs(tasks: str = globals.TASKS, config_file: str = globals.LOCAL_CONFIG_FILE):
|
| 123 |
"""Launch jobs for all models and providers."""
|
| 124 |
models_providers = load_models_providers(config_file)
|
|
@@ -140,6 +140,29 @@ def launch_jobs(tasks: str = globals.TASKS, config_file: str = globals.LOCAL_CON
|
|
| 140 |
print(f"Launched {launched_count}/{len(models_providers)} jobs successfully")
|
| 141 |
return f"Launched {launched_count} jobs"
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
def update_job_statuses() -> None:
|
| 145 |
"""Check and update the status of active jobs."""
|
|
|
|
| 118 |
print(f"Job launched: ID={job_id}, model={model}, provider={provider}")
|
| 119 |
return job_id
|
| 120 |
|
| 121 |
+
# Todo: factorize both following functions
|
| 122 |
def launch_jobs(tasks: str = globals.TASKS, config_file: str = globals.LOCAL_CONFIG_FILE):
|
| 123 |
"""Launch jobs for all models and providers."""
|
| 124 |
models_providers = load_models_providers(config_file)
|
|
|
|
| 140 |
print(f"Launched {launched_count}/{len(models_providers)} jobs successfully")
|
| 141 |
return f"Launched {launched_count} jobs"
|
| 142 |
|
| 143 |
+
def relaunch_failed_jobs():
|
| 144 |
+
"""Relaunch only failed model-provider combinations from job results."""
|
| 145 |
+
if not globals.job_results:
|
| 146 |
+
return "No existing jobs to relaunch"
|
| 147 |
+
|
| 148 |
+
failed_jobs = [(key, info) for key, info in globals.job_results.items()
|
| 149 |
+
if info.get("status") in ["ERROR", "FAILED"]]
|
| 150 |
+
|
| 151 |
+
if not failed_jobs:
|
| 152 |
+
return "No failed jobs to relaunch"
|
| 153 |
+
|
| 154 |
+
relaunched_count = 0
|
| 155 |
+
for key, info in failed_jobs:
|
| 156 |
+
model = info["model"]
|
| 157 |
+
provider = info["provider"]
|
| 158 |
+
job_id = run_single_job(model, provider, globals.TASKS)
|
| 159 |
+
if job_id != -1:
|
| 160 |
+
relaunched_count += 1
|
| 161 |
+
time.sleep(2) # Small delay between launches to avoid rate limiting
|
| 162 |
+
|
| 163 |
+
return f"Relaunched {relaunched_count}/{len(failed_jobs)} failed jobs"
|
| 164 |
+
|
| 165 |
+
|
| 166 |
|
| 167 |
def update_job_statuses() -> None:
|
| 168 |
"""Check and update the status of active jobs."""
|