mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-13 04:25:32 +08:00
- Add write_training_metrics() in new compressors/training_metrics.py for appending epoch/step/lr/component rows as JSON Lines - Wire --metrics-path and --log-every CLI options into train.py, passing them to the training loop so metrics rows are written every N steps - Accept absolute metrics paths or paths relative to output directory - Add quantization component to loss log alongside existing distill/contrastive - Replace inline torch.device() with get_device() utility - Add test_hash_training_metrics.py covering multi-row JSONL append Infrastructure: - Pin torch 2.7.1 + CUDA 12.8 index for Linux/Windows in pyproject.toml - Add .justfile rsync upload recipe with .stignore exclusion - Exclude **/__marimo__ from rsync in .stignore Dependencies updated: numpy 2.4.5, pandas 3.0.3, black 26.5.0, click 8.4.0, contourpy, etc.
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
"""Utilities for recording hash compressor training metrics."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Mapping
|
|
|
|
|
|
def write_training_metrics(
|
|
path: str | Path,
|
|
*,
|
|
epoch: int,
|
|
step: int,
|
|
lr: float,
|
|
components: Mapping[str, float],
|
|
) -> None:
|
|
"""Append one training metrics row as JSON Lines.
|
|
|
|
The JSONL format keeps training logging cheap and easy to resume: every
|
|
training step is an independent row that plotting scripts can stream later.
|
|
"""
|
|
metrics_path = Path(path)
|
|
metrics_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
row = {
|
|
"epoch": int(epoch),
|
|
"step": int(step),
|
|
"lr": float(lr),
|
|
"total": float(components["total"]),
|
|
"contrastive": float(components["contrastive"]),
|
|
"distill": float(components["distill"]),
|
|
"quantization": float(components["quantization"]),
|
|
}
|
|
|
|
with metrics_path.open("a", encoding="utf-8") as f:
|
|
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|