Add 50k-step atomic Hugging Face checkpoint backup (murli_v15_step + best + final)
Browse files105 unmodified lines106107108109110111112105 unmodified lines val_every: int = 1000
save_every: int = 2500
sample_every: int = 50_000
hf_backup_every: int = 50_000
hf_sample_repo: Optional[str] = None
seed: int = 42
56 unmodified lines57585960616263646566676869707172737475767778798081828384858629 unmodified lines11611711895119120121122163 unmodified lines28628728828929026629129229329429529629729829930030130230330430530612 unmodified lines31932032132229232332432532656 unmodified lines print(f"[Sample Upload Warning] {exc}")
def upload_checkpoints_to_hf(output_dir, repo_id, step, filenames):
if not repo_id:
return
try:
from huggingface_hub import CommitOperationAdd, HfApi
ops = []
for name in filenames:
local_path = Path(output_dir) / name
if local_path.is_file():
ops.append(CommitOperationAdd(path_in_repo=f"checkpoints/{name}", path_or_fileobj=str(local_path)))
if not ops:
return
api = HfApi(token=os.getenv("HF_TOKEN"))
api.create_commit(
repo_id=repo_id,
repo_type="model",
operations=ops,
commit_message=f"Backup Murli V1.5 checkpoints at step {step}",
)
print(f"[HF Backup] Uploaded {len(ops)} checkpoint(s) at step {step} to {repo_id}/checkpoints/", flush=True)
except Exception as exc:
print(f"[HF Backup Warning] {exc}", flush=True)
def get_lr(step, warmup, max_steps, base_lr, min_lr):
if step < warmup:
return base_lr * (step + 1) / max(warmup, 1)29 unmodified lines tc = cfg.train
for key in ("target_speaker", "target_gender", "batch_size", "grad_accum_steps",
"max_epochs", "max_steps", "num_workers", "max_samples",
"checkpoint_dir", "cache_dir", "sample_every", "hf_sample_repo"):
"checkpoint_dir", "cache_dir", "sample_every", "hf_backup_every", "hf_sample_repo"):
value = getattr(args, key, None)
if value is not None:
setattr(tc, key, value)163 unmodified lines f"{' [BEST]' if is_best else ''}",
flush=True,
)
step_ckpt = f"murli_v15_step_{step:06d}.pt"
if step % tc.save_every == 0:
save(f"murli_v15_step_{step:06d}.pt")
save(step_ckpt)
if tc.sample_every > 0 and step % tc.sample_every == 0:
generate_test_sample(model, cfg, step, vocoder_holder)
if tc.hf_backup_every > 0 and step % tc.hf_backup_every == 0 and tc.hf_sample_repo:
if step % tc.save_every != 0:
save(step_ckpt)
upload_checkpoints_to_hf(output, tc.hf_sample_repo, step, [step_ckpt, "murli_v15_best.pt"])
if step >= tc.max_steps:
break
if not step:
raise RuntimeError("No optimizer update completed")
save("murli_v15_final.pt")
upload_checkpoints_to_hf(output, tc.hf_sample_repo, step, ["murli_v15_final.pt", "murli_v15_best.pt"])
print(f"Saved final checkpoint after {step} optimizer updates")
12 unmodified lines p.add_argument("--cache_dir")
p.add_argument("--checkpoint_dir")
p.add_argument("--sample_every", type=int, help="Render test WAV every N optimizer updates (default 50000)")
p.add_argument("--hf_backup_every", type=int, help="Upload checkpoints to HF every N updates (default 50000)")
p.add_argument("--hf_sample_repo", help="Optional HF model repo to upload test WAVs for download")
p.add_argument("--hf_sample_repo", help="Optional HF model repo to upload test WAVs & checkpoints")
group = p.add_mutually_exclusive_group()
group.add_argument("--resume", help="Restore model, optimizer and training progress")
group.add_argument("--init_weights", help="Initialize model weights and start a fresh optimizer")config.py+1
train.py+34-3