Upload code/train_sft.py with huggingface_hub
Browse files794 unmodified lines795796797798798799800801802803804805806805806807808811812813814809810811794 unmodified lines f"{ema_tok_s:.0f} tok/s | ETA {eta_str} | " f"VRAM {mem_alloc:.1f}/{mem_reserved:.1f}GB")
# Periodic Evaluation & Checkpointing # Periodic Evaluation (Calculated only for metrics - No mid-training saving) if step > 0 and step % VAL_EVERY == 0: val_loss = evaluate() is_best = (best_val_loss is None) or (val_loss < best_val_loss) if is_best: best_val_loss = val_loss star = " ⭐️ BEST!" # Save best checkpoint save_sft_checkpoint(model, optimizer, step, val_loss, best_val_loss, "sft_ckpt_best.pt", scaler=scaler, is_main=IS_MAIN, work=WORK, blocking=False) else: star = "" log(f"\n📊 [Validation @ step {step}] val_loss: {val_loss:.4f}{star}\n")
# Periodic Checkpoint Saving if step > 0 and step % SAVE_EVERY == 0: save_sft_checkpoint(model, optimizer, step, val_loss if 'val_loss' in locals() else -1.0, best_val_loss, "sft_ckpt_latest.pt", scaler=scaler, is_main=IS_MAIN, work=WORK, blocking=False)
# Periodic Memory Defragmentation if step > 0 and step % EMPTY_CACHE_EVERY == 0: torch.cuda.empty_cache()code/train_sft.py+1-7