Conform on dataset parquet format
Browse files- app.py +46 -46
- src/core/evaluation.py +5 -2
- src/populate.py +20 -27
app.py
CHANGED
@@ -152,23 +152,27 @@ def process_evaluation_queue():
|
|
152 |
def update_request_status(model_name, status):
|
153 |
"""Update the status of a request in the Hugging Face repository."""
|
154 |
try:
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
dataset
|
171 |
-
|
|
|
|
|
|
|
|
|
172 |
logger.info(f"Updated status for {model_name} to {status}")
|
173 |
except Exception as e:
|
174 |
logger.error(f"Failed to update status for {model_name}: {str(e)}", exc_info=True)
|
@@ -180,15 +184,21 @@ from huggingface_hub import HfApi
|
|
180 |
def save_results_to_repo(results, repo):
|
181 |
"""Save evaluation results to the specified repository."""
|
182 |
try:
|
183 |
-
model_id = results.get('model', '')
|
184 |
if not model_id:
|
185 |
raise ValueError("Model ID not found in results")
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
# Create a Dataset object from the results
|
188 |
-
dataset = Dataset.from_dict(
|
189 |
|
190 |
# Push the dataset to the Hugging Face Hub
|
191 |
-
dataset.push_to_hub(repo)
|
192 |
|
193 |
logger.info(f"Saved results for {model_id} to {repo}")
|
194 |
except Exception as e:
|
@@ -368,37 +378,27 @@ with demo:
|
|
368 |
try:
|
369 |
logger.info(f"New submission received for {model}")
|
370 |
|
371 |
-
# Prepare request data
|
372 |
request_data = {
|
373 |
-
"model": model,
|
374 |
-
"
|
375 |
-
"
|
376 |
-
"
|
377 |
-
"
|
378 |
-
"
|
379 |
-
"
|
380 |
-
"
|
|
|
381 |
}
|
382 |
|
383 |
-
#
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
# Upload the JSON file to the Hub
|
391 |
-
api = HfApi()
|
392 |
-
api.upload_file(
|
393 |
-
path_or_fileobj=filename,
|
394 |
-
path_in_repo=filename,
|
395 |
-
repo_id=QUEUE_REPO,
|
396 |
-
repo_type="dataset"
|
397 |
)
|
398 |
|
399 |
-
# Clean up local file
|
400 |
-
os.remove(filename)
|
401 |
-
|
402 |
logger.info(f"Added request for {model} to {QUEUE_REPO}")
|
403 |
|
404 |
# Get updated pending evaluations
|
|
|
152 |
def update_request_status(model_name, status):
|
153 |
"""Update the status of a request in the Hugging Face repository."""
|
154 |
try:
|
155 |
+
# Load the current dataset
|
156 |
+
from datasets import load_dataset
|
157 |
+
dataset = load_dataset(QUEUE_REPO, split="train")
|
158 |
+
|
159 |
+
# Find the row for this model and update its status
|
160 |
+
data_dict = dataset.to_dict()
|
161 |
+
indices = [i for i, m in enumerate(data_dict["model"]) if m == model_name]
|
162 |
+
|
163 |
+
if not indices:
|
164 |
+
logger.error(f"No request found for model {model_name}")
|
165 |
+
return
|
166 |
+
|
167 |
+
# Update the status for the found request
|
168 |
+
data_dict["status"][indices[0]] = status
|
169 |
+
|
170 |
+
# Create new dataset with updated status
|
171 |
+
updated_dataset = Dataset.from_dict(data_dict)
|
172 |
+
|
173 |
+
# Push the updated dataset back to the hub
|
174 |
+
updated_dataset.push_to_hub(QUEUE_REPO, split="train")
|
175 |
+
|
176 |
logger.info(f"Updated status for {model_name} to {status}")
|
177 |
except Exception as e:
|
178 |
logger.error(f"Failed to update status for {model_name}: {str(e)}", exc_info=True)
|
|
|
184 |
def save_results_to_repo(results, repo):
|
185 |
"""Save evaluation results to the specified repository."""
|
186 |
try:
|
187 |
+
model_id = results.get('model', '')
|
188 |
if not model_id:
|
189 |
raise ValueError("Model ID not found in results")
|
190 |
|
191 |
+
# Convert all values to lists if they aren't already
|
192 |
+
dataset_dict = {
|
193 |
+
k: [v] if not isinstance(v, list) else v
|
194 |
+
for k, v in results.items()
|
195 |
+
}
|
196 |
+
|
197 |
# Create a Dataset object from the results
|
198 |
+
dataset = Dataset.from_dict(dataset_dict)
|
199 |
|
200 |
# Push the dataset to the Hugging Face Hub
|
201 |
+
dataset.push_to_hub(repo, split="train")
|
202 |
|
203 |
logger.info(f"Saved results for {model_id} to {repo}")
|
204 |
except Exception as e:
|
|
|
378 |
try:
|
379 |
logger.info(f"New submission received for {model}")
|
380 |
|
381 |
+
# Prepare request data as a dataset-compatible dictionary (all values must be lists)
|
382 |
request_data = {
|
383 |
+
"model": [model],
|
384 |
+
"model_raw": [model], # Store raw model name for processing
|
385 |
+
"base_model": [base_model if base_model else ""],
|
386 |
+
"revision": [revision if revision else "main"],
|
387 |
+
"precision": [precision],
|
388 |
+
"weight_type": [weight_type],
|
389 |
+
"model_type": [model_type],
|
390 |
+
"status": ["PENDING"],
|
391 |
+
"timestamp": [datetime.now().isoformat()]
|
392 |
}
|
393 |
|
394 |
+
# Convert to dataset and push to hub
|
395 |
+
dataset = Dataset.from_dict(request_data)
|
396 |
+
dataset.push_to_hub(
|
397 |
+
QUEUE_REPO,
|
398 |
+
config_name=model.replace("/", "_"),
|
399 |
+
split="train"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
)
|
401 |
|
|
|
|
|
|
|
402 |
logger.info(f"Added request for {model} to {QUEUE_REPO}")
|
403 |
|
404 |
# Get updated pending evaluations
|
src/core/evaluation.py
CHANGED
@@ -108,17 +108,20 @@ class EvaluationManager:
|
|
108 |
"model_type": request.model_type,
|
109 |
}
|
110 |
|
|
|
|
|
|
|
111 |
# Save and backup results
|
112 |
eval_id = f"{request.model.replace('/', '_')}_{request.revision}"
|
113 |
result_path = os.path.join(self.results_dir, f"{eval_id}.json")
|
114 |
|
115 |
with open(result_path, 'w') as f:
|
116 |
-
json.dump(
|
117 |
|
118 |
self.backup_results(eval_id)
|
119 |
logger.info(f"Evaluation complete for {request.model}")
|
120 |
|
121 |
-
return
|
122 |
|
123 |
except Exception as e:
|
124 |
logger.error(f"Evaluation failed: {str(e)}", exc_info=True)
|
|
|
108 |
"model_type": request.model_type,
|
109 |
}
|
110 |
|
111 |
+
# Convert results to dataset-compatible format (lists)
|
112 |
+
dataset_results = {k: [v] for k, v in results.items()}
|
113 |
+
|
114 |
# Save and backup results
|
115 |
eval_id = f"{request.model.replace('/', '_')}_{request.revision}"
|
116 |
result_path = os.path.join(self.results_dir, f"{eval_id}.json")
|
117 |
|
118 |
with open(result_path, 'w') as f:
|
119 |
+
json.dump(dataset_results, f, indent=2)
|
120 |
|
121 |
self.backup_results(eval_id)
|
122 |
logger.info(f"Evaluation complete for {request.model}")
|
123 |
|
124 |
+
return dataset_results
|
125 |
|
126 |
except Exception as e:
|
127 |
logger.error(f"Evaluation failed: {str(e)}", exc_info=True)
|
src/populate.py
CHANGED
@@ -102,34 +102,27 @@ def get_evaluation_queue_df(cols: list) -> list[pd.DataFrame]:
|
|
102 |
logger.info(f"Looking for eval requests in {QUEUE_REPO}")
|
103 |
all_evals = []
|
104 |
|
105 |
-
api = HfApi()
|
106 |
-
|
107 |
try:
|
108 |
-
#
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
# Single request in the file
|
129 |
-
formatted_data = format_eval_data(data)
|
130 |
-
all_evals.append(formatted_data)
|
131 |
-
except Exception as e:
|
132 |
-
logger.error(f"Error processing file {file}: {str(e)}", exc_info=True)
|
133 |
|
134 |
except Exception as e:
|
135 |
logger.error(f"Error fetching requests from {QUEUE_REPO}: {str(e)}", exc_info=True)
|
|
|
102 |
logger.info(f"Looking for eval requests in {QUEUE_REPO}")
|
103 |
all_evals = []
|
104 |
|
|
|
|
|
105 |
try:
|
106 |
+
# Load the dataset directly
|
107 |
+
from datasets import load_dataset
|
108 |
+
dataset = load_dataset(QUEUE_REPO, split="train")
|
109 |
+
logger.debug(f"Loaded dataset with {len(dataset)} rows")
|
110 |
+
logger.debug(f"Dataset features: {dataset.features}")
|
111 |
+
|
112 |
+
# Convert dataset to list of dicts
|
113 |
+
for row in dataset:
|
114 |
+
formatted_data = format_eval_data({
|
115 |
+
"model": row["model"],
|
116 |
+
"model_raw": row.get("model_raw", row["model"]), # Fallback to model if model_raw not present
|
117 |
+
"base_model": row.get("base_model", ""),
|
118 |
+
"revision": row.get("revision", "main"),
|
119 |
+
"precision": row.get("precision", ""),
|
120 |
+
"weight_type": row.get("weight_type", ""),
|
121 |
+
"model_type": row.get("model_type", ""),
|
122 |
+
"status": row.get("status", "PENDING"),
|
123 |
+
"timestamp": row.get("timestamp", "")
|
124 |
+
})
|
125 |
+
all_evals.append(formatted_data)
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
except Exception as e:
|
128 |
logger.error(f"Error fetching requests from {QUEUE_REPO}: {str(e)}", exc_info=True)
|