Upload code/train_sft.py with huggingface_hub
Browse files324 unmodified lines325326327328329330331332333334335336337315 unmodified lines65365465565665765865966066166266366431 unmodified lines696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727324 unmodified linesstage_subfolder = f"sft_{args.version}"stage_data_dir = os.path.join(data_dir, stage_subfolder)final_save_path = os.path.join(output_dir, f"sft_{args.version}_final.pt")best_save_path = os.path.join(output_dir, f"sft_{args.version}_best.pt")if args.init_ckpt:init_ckpt = args.init_ckptelif args.resume and os.path.exists(best_save_path):init_ckpt = best_save_pathelse:init_ckpt = os.path.join(root_dir, "checkpoints", "ckpt_latest.pt")315 unmodified lines"model_args": vars(model_args),"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")}# Save both step checkpoint and best checkpointif is_best:torch.save(save_payload, best_save_path)print(f" ๐พ Saved BEST checkpoint -> {best_save_path}")torch.save(save_payload, final_save_path)print(f" ๐พ Saved LATEST checkpoint -> {final_save_path}\n")# End of Epoch Handlingif (micro_idx + 1) % grad_acc != 0:31 unmodified lines"model_args": vars(model_args),"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")}torch.save(final_payload, final_save_path)print(f"๐พ Final master checkpoint saved to: {final_save_path}")# Push to Hugging Face Hub (Both Best & Final Checkpoints)if args.push_to_hf:print("\n๐ Pushing Best & Final Checkpoints to Hugging Face Model Hub (ViuAI/ViuAI-500M)...")token = args.hf_token or os.environ.get("HF_TOKEN")if token:try:api = HfApi(token=token)if os.path.exists(best_save_path):api.upload_file(path_or_fileobj=best_save_path,path_in_repo=f"checkpoints/sft_{args.version}_best.pt",repo_id="ViuAI/ViuAI-500M",repo_type="model")print(f"โ Successfully uploaded sft_{args.version}_best.pt!")if os.path.exists(final_save_path):api.upload_file(path_or_fileobj=final_save_path,path_in_repo=f"checkpoints/sft_{args.version}_final.pt",repo_id="ViuAI/ViuAI-500M",repo_type="model")print(f"โ Successfully uploaded sft_{args.version}_final.pt!")except Exception as e:print(f"โ ๏ธ Error uploading to Hugging Face: {e}")else:324 unmodified lines325326327328329330331332333334335336337315 unmodified lines65365465565665765865966031 unmodified lines692693694695696697698699700701702703704705706707708709710711712713714715324 unmodified linesstage_subfolder = f"sft_{args.version}"stage_data_dir = os.path.join(data_dir, stage_subfolder)ckpt_filename = f"sft_{args.version}_final.pt"save_path = os.path.join(output_dir, ckpt_filename)if args.init_ckpt:init_ckpt = args.init_ckptelif args.resume and os.path.exists(save_path):init_ckpt = save_pathelse:init_ckpt = os.path.join(root_dir, "checkpoints", "ckpt_latest.pt")315 unmodified lines"model_args": vars(model_args),"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")}torch.save(save_payload, save_path)print(f" ๐พ Saved checkpoint -> {save_path}\n")# End of Epoch Handlingif (micro_idx + 1) % grad_acc != 0:31 unmodified lines"model_args": vars(model_args),"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")}torch.save(final_payload, save_path)print(f"๐พ Final master checkpoint saved to: {save_path}")# Push to Hugging Face Hub (Only Final Checkpoint)if args.push_to_hf:print("\n๐ Pushing Final Checkpoint to Hugging Face Model Hub (ViuAI/ViuAI-500M)...")token = args.hf_token or os.environ.get("HF_TOKEN")if token:try:api = HfApi(token=token)if os.path.exists(save_path):api.upload_file(path_or_fileobj=save_path,path_in_repo=f"checkpoints/{ckpt_filename}",repo_id="ViuAI/ViuAI-500M",repo_type="model")print(f"โ Successfully uploaded {ckpt_filename} to ViuAI/ViuAI-500M!")except Exception as e:print(f"โ ๏ธ Error uploading to Hugging Face: {e}")else:
code/train_sft.py+14-26