Add 50k-step atomic Hugging Face checkpoint backup (murli_v15_step + best + final)
Browse files105 unmodified lines106107108109110111105 unmodified linesval_every: int = 1000save_every: int = 2500sample_every: int = 50_000hf_sample_repo: Optional[str] = Noneseed: int = 42105 unmodified lines106107108109110111112105 unmodified linesval_every: int = 1000save_every: int = 2500sample_every: int = 50_000hf_backup_every: int = 50_000hf_sample_repo: Optional[str] = Noneseed: int = 42
56 unmodified lines57585960616229 unmodified lines92939495969798163 unmodified lines26226326426526626726826927027127227327427527612 unmodified lines28929029129229329429556 unmodified linesprint(f"[Sample Upload Warning] {exc}")def get_lr(step, warmup, max_steps, base_lr, min_lr):if step < warmup:return base_lr * (step + 1) / max(warmup, 1)29 unmodified linestc = cfg.trainfor 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"):value = getattr(args, key, None)if value is not None:setattr(tc, key, value)163 unmodified linesf"{' [BEST]' 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:generate_test_sample(model, cfg, step, vocoder_holder)if step >= tc.max_steps:breakif not step:raise RuntimeError("No optimizer update completed")save("murli_v15_final.pt")print(f"Saved final checkpoint after {step} optimizer updates")12 unmodified linesp.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_sample_repo", help="Optional HF model repo to upload test WAVs for download")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")56 unmodified lines57585960616263646566676869707172737475767778798081828384858629 unmodified lines116117118119120121122163 unmodified lines28628728828929029129229329429529629729829930030130230330430530612 unmodified lines31932032132232332432532656 unmodified linesprint(f"[Sample Upload Warning] {exc}")def upload_checkpoints_to_hf(output_dir, repo_id, step, filenames):if not repo_id:returntry:from huggingface_hub import CommitOperationAdd, HfApiops = []for name in filenames:local_path = Path(output_dir) / nameif local_path.is_file():ops.append(CommitOperationAdd(path_in_repo=f"checkpoints/{name}", path_or_fileobj=str(local_path)))if not ops:returnapi = 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 linestc = cfg.trainfor 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_backup_every", "hf_sample_repo"):value = getattr(args, key, None)if value is not None:setattr(tc, key, value)163 unmodified linesf"{' [BEST]' if is_best else ''}",flush=True,)step_ckpt = f"murli_v15_step_{step:06d}.pt"if step % tc.save_every == 0: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:breakif 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 linesp.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 & 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