Skip to content

Commit 9ec7ada

Browse files
committed
Add on_model_done callback to AuditExperiment
1 parent e444928 commit 9ec7ada

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

simpleaudit/experiment.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
from typing import Any, Dict, List, Optional, Union
2+
from typing import Any, Callable, Dict, List, Optional, Union
33
import asyncio
44

55
from tqdm.auto import tqdm
@@ -28,6 +28,7 @@ def __init__(
2828
show_progress: bool = True,
2929
n_repetitions: int = 1,
3030
save_dir: Optional[str] = None,
31+
on_model_done: Optional[Callable[[str, "RepeatedExperimentResults"], None]] = None,
3132
):
3233
if not models or any("model" not in m for m in models):
3334
raise ValueError("Models must be dicts with a 'model' key.")
@@ -58,6 +59,7 @@ def __init__(
5859
self.show_progress = show_progress
5960
self.n_repetitions = n_repetitions
6061
self.save_dir = Path(save_dir) if save_dir else None
62+
self.on_model_done = on_model_done
6163

6264
def _make_label(self, model_info: Dict[str, Any]) -> str:
6365
return model_info.get("label") or model_info["model"]
@@ -156,6 +158,9 @@ async def run_async(
156158
pbar_reps.update(1)
157159

158160
runs_by_model[label] = [runs_ordered[i] for i in range(self.n_repetitions)]
161+
if self.on_model_done:
162+
partial = RepeatedExperimentResults({label: runs_by_model[label]})
163+
self.on_model_done(label, partial)
159164
pbar_models.update(1)
160165

161166
judge_info = {

0 commit comments

Comments
 (0)