Download benchmarks/results.py from Pulsar-Dynamic-Technologies/Adria: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/Pulsar-Dynamic-Technologies/Adria/resolve/main/benchmarks/results.py
- Command line
-
hf download hf://Pulsar-Dynamic-Technologies/Adria/benchmarks/results.py
-
curl -L -o results.py https://huggingface.co/Pulsar-Dynamic-Technologies/Adria/resolve/main/benchmarks/results.py
1.94 kB
| import dataclasses | |
| import json | |
| from pathlib import Path | |
| RESULTS_DIR = Path(__file__).parent / "results" | |
| class StepRecord: | |
| """ | |
| A dataclass to help logging and graphing by holding one step of results | |
| """ | |
| step: int | |
| tokens: int | |
| loss: float | |
| accuracy: float | |
| class TaskResult: | |
| model_name: str | |
| task_name: str | |
| n_params: int | |
| seq_len: int | |
| batch_size: int | |
| total_steps: int | |
| total_tokens: int | |
| curve: list[StepRecord] | |
| final_loss: float | |
| final_accuracy: float | |
| tokens_to_90pct: int | None | |
| def result_path(model_name: str, task_name: str, n_params: int) -> Path: | |
| return RESULTS_DIR / model_name / f"{task_name}_{n_params}.json" | |
| def result_exists(model_name: str, task_name: str, n_params: int) -> bool: | |
| return result_path(model_name, task_name, n_params).exists() | |
| def save_result(result: TaskResult, params: int): | |
| path = result_path(result.model_name, result.task_name, params) | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| with open(path, "w") as f: | |
| json.dump(dataclasses.asdict(result), f, indent=4) | |
| f.close() | |
| def load_result(model_name: str, task_name: str, n_params: int) -> TaskResult: | |
| path = result_path(model_name, task_name, n_params) | |
| with open(path) as f: | |
| result = json.load(f) | |
| f.close() | |
| result["curve"] = [StepRecord(**r) for r in result["curve"]] | |
| return TaskResult(**result) | |
| def load_all_results() -> list[TaskResult]: | |
| results = [] | |
| for path in RESULTS_DIR.rglob("*.json"): | |
| # noinspection PyBroadException | |
| try: | |
| model_name = path.parent.name | |
| filename_parts = path.stem.rsplit("_", 1) | |
| task_name, n_params = filename_parts[0], int(filename_parts[1]) | |
| results.append(load_result(model_name, task_name, n_params)) | |
| except Exception: | |
| pass | |
| return results | |