Add V1-style detailed training logs (Epoch, Step, CFM, Prior, Dur, F0, E, LR, clips/s, VRAM, ETA)
Browse files3 unmodified lines45678910179 unmodified lines19019119219319419519619719819911 unmodified lines21121221321421521621711 unmodified lines2292302312262322332342352362372382392402412422432442452462472482492502512522532542552292302562572582592602612622632642652662673 unmodified linesimport hashlib
import math
import os
import time
from collections import Counter
from dataclasses import asdict
from pathlib import Path179 unmodified lines
model.train()
optimizer.zero_grad(set_to_none=True)
t_start = time.time()
t_log = t_start
clips_since_log = 0
steps_at_start = step
while step < tc.max_steps and epoch < tc.max_epochs:
generator = torch.Generator().manual_seed(tc.seed + epoch)
order = torch.randperm(len(train_ds), generator=generator).tolist()11 unmodified lines raise FloatingPointError(f"Nonfinite training loss after {step} updates")
scaler.scale(loss).backward()
offset += batch["token_ids"].size(0)
clips_since_log += batch["token_ids"].size(0)
if group_idx + 1 < group_size:
continue
for pg in optimizer.param_groups:11 unmodified lines continue
step += 1
if step == 1 or step % tc.log_every == 0:
print(f"Update {step}: loss {out['loss'].item():.4f}, CFM {out['cfm_loss'].item():.4f}")
now = time.time()
dt_log = max(now - t_log, 1e-6)
clips_s = clips_since_log / dt_log
t_log = now
clips_since_log = 0
cur_lr = optimizer.param_groups[0]["lr"]
pct = 100.0 * step / max(tc.max_steps, 1)
done_steps = max(step - steps_at_start, 1)
rate = done_steps / max(now - t_start, 1e-6)
eta_h = (tc.max_steps - step) / max(rate, 1e-6) / 3600.0
vram_str = (
f" | VRAM={torch.cuda.max_memory_allocated() / (1024 ** 3):.1f}GB"
if device.type == "cuda" else ""
)
print(
f"[Ep {epoch + 1:04d}/{tc.max_epochs} | Step {step:06d}/{tc.max_steps} ({pct:.2f}%)] "
f"Loss={out['loss'].item():.4f} | CFM={out['cfm_loss'].item():.4f} | "
f"Prior={out['prior_loss'].item():.4f} | Dur={out['dur_loss'].item():.4f} | "
f"F0={out['f0_loss'].item():.4f} | E={out['energy_loss'].item():.4f} | "
f"LR={cur_lr:.2e} | {clips_s:.1f} clips/s{vram_str} | ETA={eta_h:.1f}h",
flush=True,
)
if len(val_ds) and step % tc.val_every == 0:
score = validate(model, val_loader, device, tc.seed)
print(f"Validation at update {step}: CFM {score:.4f}")
if score < best:
is_best = score < best
if is_best:
best = score
save("murli_v15_best.pt")
print(
f">>> [Val Ep {epoch + 1:04d} | Step {step:06d}] Val_CFM={score:.4f} | "
f"Best_CFM={best:.4f}{' [BEST SAVED]' if is_best else ''}",
flush=True,
)
if step % tc.save_every == 0:
save(f"murli_v15_step_{step:06d}.pt")
if tc.sample_every > 0 and step % tc.sample_every == 0:train.py+35-3