Mandeep Sidhu
Refactor experiment pipeline and add regime paper
e7a7275
Raw
History Blame Contribute Delete
2.26 kB
"""
Derived from Andrej Karpathy's nanochat project.
MIT License
Copyright (c) 2025 Andrej Karpathy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
"""
from __future__ import annotations
import time
def format_duration(seconds: float) -> str:
seconds = max(0, int(seconds))
hours, remainder = divmod(seconds, 3600)
minutes, secs = divmod(remainder, 60)
if hours:
return f"{hours}h{minutes:02d}m"
if minutes:
return f"{minutes}m{secs:02d}s"
return f"{secs}s"
class ProgressMeter:
def __init__(self, total: int):
self.total = max(0, total)
self.done = 0
self.started_at = time.time()
def mark_done(self, row: dict) -> None:
self.done += 1
elapsed = time.time() - self.started_at
mean = elapsed / self.done if self.done else 0.0
remaining = max(0, self.total - self.done)
eta = remaining * mean
stage = row.get("stage")
stage_text = f"stage={stage} " if stage is not None else ""
print(
"progress "
f"{self.done}/{self.total} "
f"eta={format_duration(eta)} "
f"mode={row['run_mode']} "
f"model={row['model_name']} "
f"params={int(row['parameters']):,} "
f"prefix={int(row['token_limit']):,} "
f"{stage_text}"
f"seed={row['seed']} "
f"condition={row['condition']} "
f"dropout={float(row['dropout_active_final']):.3f} "
f"val={row['val_eval_loss']:.4f} "
f"train={row['train_eval_loss']:.4f} "
f"gap={row['generalization_gap']:.4f} "
f"elapsed={format_duration(float(row['elapsed_sec']))}",
flush=True,
)