Spaces:
Sleeping
Sleeping
File size: 1,507 Bytes
d63a1ba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | """Save a small speed summary from the current PyTorch training log."""
from __future__ import annotations
import json
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
LOG_PATH = ROOT / "artifacts" / "lora_qwen3_4b" / "logs" / "train_lora_manual.log"
OUT_PATH = ROOT / "artifacts" / "lora_qwen3_4b" / "metrics" / "speed_baseline_pytorch.json"
STEP_RE = re.compile(r"(\d+)%\|.*?\|\s+(\d+)/(\d+)\s+\[(\d+):(\d+)<")
def main() -> None:
text = LOG_PATH.read_text(encoding="utf-8") if LOG_PATH.exists() else ""
matches = STEP_RE.findall(text)
records = []
for _pct, step, total, mins, secs in matches:
step_num = int(step)
elapsed_s = int(mins) * 60 + int(secs)
if step_num > 0:
records.append(
{
"step": step_num,
"total_steps": int(total),
"elapsed_seconds": elapsed_s,
"seconds_per_step_estimate": elapsed_s / step_num,
}
)
payload = {
"method": "pytorch_mps_lora",
"source_log": str(LOG_PATH),
"records": records,
"latest_seconds_per_step": records[-1]["seconds_per_step_estimate"] if records else None,
}
OUT_PATH.parent.mkdir(parents=True, exist_ok=True)
OUT_PATH.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
print(json.dumps(payload, indent=2, sort_keys=True))
if __name__ == "__main__":
main()
|