Upload code/train_sft.py with huggingface_hub
Browse files- code/train_sft.py +14 -26
code/train_sft.py
CHANGED
|
@@ -325,13 +325,13 @@ def main():
|
|
| 325 |
stage_subfolder = f"sft_{args.version}"
|
| 326 |
stage_data_dir = os.path.join(data_dir, stage_subfolder)
|
| 327 |
|
| 328 |
-
|
| 329 |
-
|
| 330 |
|
| 331 |
if args.init_ckpt:
|
| 332 |
init_ckpt = args.init_ckpt
|
| 333 |
-
elif args.resume and os.path.exists(
|
| 334 |
-
init_ckpt =
|
| 335 |
else:
|
| 336 |
init_ckpt = os.path.join(root_dir, "checkpoints", "ckpt_latest.pt")
|
| 337 |
|
|
@@ -653,12 +653,8 @@ def main():
|
|
| 653 |
"model_args": vars(model_args),
|
| 654 |
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")
|
| 655 |
}
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
torch.save(save_payload, best_save_path)
|
| 659 |
-
print(f" 💾 Saved BEST checkpoint -> {best_save_path}")
|
| 660 |
-
torch.save(save_payload, final_save_path)
|
| 661 |
-
print(f" 💾 Saved LATEST checkpoint -> {final_save_path}\n")
|
| 662 |
|
| 663 |
# End of Epoch Handling
|
| 664 |
if (micro_idx + 1) % grad_acc != 0:
|
|
@@ -696,32 +692,24 @@ def main():
|
|
| 696 |
"model_args": vars(model_args),
|
| 697 |
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")
|
| 698 |
}
|
| 699 |
-
torch.save(final_payload,
|
| 700 |
-
print(f"💾 Final master checkpoint saved to: {
|
| 701 |
|
| 702 |
-
# Push to Hugging Face Hub (
|
| 703 |
if args.push_to_hf:
|
| 704 |
-
print("\n🚀 Pushing
|
| 705 |
token = args.hf_token or os.environ.get("HF_TOKEN")
|
| 706 |
if token:
|
| 707 |
try:
|
| 708 |
api = HfApi(token=token)
|
| 709 |
-
if os.path.exists(
|
| 710 |
-
api.upload_file(
|
| 711 |
-
path_or_fileobj=best_save_path,
|
| 712 |
-
path_in_repo=f"checkpoints/sft_{args.version}_best.pt",
|
| 713 |
-
repo_id="ViuAI/ViuAI-500M",
|
| 714 |
-
repo_type="model"
|
| 715 |
-
)
|
| 716 |
-
print(f"✅ Successfully uploaded sft_{args.version}_best.pt!")
|
| 717 |
-
if os.path.exists(final_save_path):
|
| 718 |
api.upload_file(
|
| 719 |
-
path_or_fileobj=
|
| 720 |
-
path_in_repo=f"checkpoints/
|
| 721 |
repo_id="ViuAI/ViuAI-500M",
|
| 722 |
repo_type="model"
|
| 723 |
)
|
| 724 |
-
print(f"✅ Successfully uploaded
|
| 725 |
except Exception as e:
|
| 726 |
print(f"⚠️ Error uploading to Hugging Face: {e}")
|
| 727 |
else:
|
|
|
|
| 325 |
stage_subfolder = f"sft_{args.version}"
|
| 326 |
stage_data_dir = os.path.join(data_dir, stage_subfolder)
|
| 327 |
|
| 328 |
+
ckpt_filename = f"sft_{args.version}_final.pt"
|
| 329 |
+
save_path = os.path.join(output_dir, ckpt_filename)
|
| 330 |
|
| 331 |
if args.init_ckpt:
|
| 332 |
init_ckpt = args.init_ckpt
|
| 333 |
+
elif args.resume and os.path.exists(save_path):
|
| 334 |
+
init_ckpt = save_path
|
| 335 |
else:
|
| 336 |
init_ckpt = os.path.join(root_dir, "checkpoints", "ckpt_latest.pt")
|
| 337 |
|
|
|
|
| 653 |
"model_args": vars(model_args),
|
| 654 |
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")
|
| 655 |
}
|
| 656 |
+
torch.save(save_payload, save_path)
|
| 657 |
+
print(f" 💾 Saved checkpoint -> {save_path}\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 658 |
|
| 659 |
# End of Epoch Handling
|
| 660 |
if (micro_idx + 1) % grad_acc != 0:
|
|
|
|
| 692 |
"model_args": vars(model_args),
|
| 693 |
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S")
|
| 694 |
}
|
| 695 |
+
torch.save(final_payload, save_path)
|
| 696 |
+
print(f"💾 Final master checkpoint saved to: {save_path}")
|
| 697 |
|
| 698 |
+
# Push to Hugging Face Hub (Only Final Checkpoint)
|
| 699 |
if args.push_to_hf:
|
| 700 |
+
print("\n🚀 Pushing Final Checkpoint to Hugging Face Model Hub (ViuAI/ViuAI-500M)...")
|
| 701 |
token = args.hf_token or os.environ.get("HF_TOKEN")
|
| 702 |
if token:
|
| 703 |
try:
|
| 704 |
api = HfApi(token=token)
|
| 705 |
+
if os.path.exists(save_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
api.upload_file(
|
| 707 |
+
path_or_fileobj=save_path,
|
| 708 |
+
path_in_repo=f"checkpoints/{ckpt_filename}",
|
| 709 |
repo_id="ViuAI/ViuAI-500M",
|
| 710 |
repo_type="model"
|
| 711 |
)
|
| 712 |
+
print(f"✅ Successfully uploaded {ckpt_filename} to ViuAI/ViuAI-500M!")
|
| 713 |
except Exception as e:
|
| 714 |
print(f"⚠️ Error uploading to Hugging Face: {e}")
|
| 715 |
else:
|