Upload code/train_sft_v5.py with huggingface_hub
Browse files307 unmodified lines30830931031131231331431531631731831932032132215 unmodified lines338339340341342343344345346347348349350351352353307 unmodified linesif global_optim_step % VAL_INTERVAL == 0:val_loss = run_validation()log(f" π Validation Loss: {val_loss:.4f}")if val_loss < best_val_loss:best_val_loss = val_losslog(f" π New best validation loss! Saving checkpoint...")# Save best checkpointif IS_MAIN:os.makedirs("v5_checkpoints", exist_ok=True)unwrapped = model._orig_mod if hasattr(model, '_orig_mod') else (model.module if hasattr(model, 'module') else model)torch.save({"model": unwrapped.state_dict(), "optimizer": optimizer.state_dict(), "step": global_optim_step, "val_loss": val_loss},"v5_checkpoints/sft_ckpt_best.pt")log(f"β Epoch {epoch+1}/{NUM_EPOCHS} complete! (Optimizer steps so far: {global_optim_step})")15 unmodified linesrepo_id=MAIN_REPO,repo_type="model")# Upload best (lowest val loss) checkpoint toobest_path = "v5_checkpoints/sft_ckpt_best.pt"if os.path.exists(best_path):api.upload_file(path_or_fileobj=best_path,path_in_repo=f"{SFT_CHECKPOINT_DIR}/sft_ckpt_best.pt",repo_id=MAIN_REPO,repo_type="model")log("β Best checkpoint uploaded!")log("π V5 Training and Upload COMPLETE!")307 unmodified lines30830931031131231315 unmodified lines329330331332333334335307 unmodified linesif global_optim_step % VAL_INTERVAL == 0:val_loss = run_validation()log(f" π Validation Loss: {val_loss:.4f}")log(f"β Epoch {epoch+1}/{NUM_EPOCHS} complete! (Optimizer steps so far: {global_optim_step})")15 unmodified linesrepo_id=MAIN_REPO,repo_type="model")log("π V5 Training and Upload COMPLETE!")
code/train_sft_v5.py+1-19