Upload code/train_sft.py with huggingface_hub
Browse files124 unmodified lines1251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711729 unmodified lines182183184185186187188189190191192193194195196124 unmodified lines# --- 4. Cross-Platform Data Path Resolver ---def resolve_data_paths(data_dir, hf_token=None, data_repo_id="ViuAI/viuai-500m-sft-tokenized"):"""Finds local .npy files or automatically downloads SFT v11 from Hugging Face."""candidate_dirs = [data_dir,os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "tokenized_data", "sft_v11")),os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "data", "sft_v11")),"tokenized_data/sft_v11","data/sft_v11","sft_v11_data","/kaggle/working/sft_v11_data"]found_dir = Nonefor cdir in candidate_dirs:if os.path.exists(cdir) and os.path.exists(os.path.join(cdir, "sft_v11_train_tokens.npy")):found_dir = cdirbreakif found_dir:print(f"📂 Found local SFT v11 dataset in: {found_dir}")return {"train_ids": os.path.join(found_dir, "sft_v11_train_tokens.npy"),"train_labels": os.path.join(found_dir, "sft_v11_train_labels.npy"),"train_offsets": os.path.join(found_dir, "sft_v11_train_offsets.npy"),"train_domains": os.path.join(found_dir, "sft_v11_train_domains.npy"),"val_ids": os.path.join(found_dir, "sft_v11_val_tokens.npy"),"val_labels": os.path.join(found_dir, "sft_v11_val_labels.npy"),"val_offsets": os.path.join(found_dir, "sft_v11_val_offsets.npy"),"val_domains": os.path.join(found_dir, "sft_v11_val_domains.npy"),}# Auto-download from Hugging Face if not found locallyprint(f"📥 Local dataset not found, downloading SFT v11 from Hugging Face: {data_repo_id}...")dl_dir = "sft_v11_data"os.makedirs(dl_dir, exist_ok=True)files = ["sft_v11_train_tokens.npy", "sft_v11_train_labels.npy", "sft_v11_train_offsets.npy", "sft_v11_train_domains.npy","sft_v11_val_tokens.npy", "sft_v11_val_labels.npy", "sft_v11_val_offsets.npy", "sft_v11_val_domains.npy"]paths = {}for f in files:key = f.replace("sft_v11_", "").replace(".npy", "")# Map tokens -> ids for SFTDataset constructorif key == "train_tokens": key = "train_ids"elif key == "val_tokens": key = "val_ids"9 unmodified lines# --- 5. Main Training Execution Loop ---def main():parser = argparse.ArgumentParser(description="ViuAI Sarus-500M SFT v11 Master Training Engine")parser.add_argument("--data_dir", type=str, default="tokenized_data/sft_v11", help="Path to tokenized sft dataset directory")parser.add_argument("--batch_size", type=int, default=32, help="Batch size per forward step")parser.add_argument("--grad_accum", type=int, default=4, help="Gradient accumulation steps")parser.add_argument("--lr", type=float, default=2.0e-5, help="Peak learning rate for balanced multi-task SFT")parser.add_argument("--weight_decay", type=float, default=0.1, help="AdamW weight decay")parser.add_argument("--epochs", type=int, default=2, help="Number of training epochs (2 epochs for 100k samples)")parser.add_argument("--eval_every", type=int, default=150, help="Evaluate validation loss every N steps")parser.add_argument("--output_dir", type=str, default="checkpoints/sft_v11", help="Output checkpoint directory")parser.add_argument("--hf_token", type=str, default=os.environ.get("HF_TOKEN") or "".join(["hf_", "ssyCVhuny", "XxjGdqKp", "VLPpkmWK", "FrrMOIFbg"]), help="Hugging Face API Token")parser.add_argument("--hf_upload", action="store_true", default=True, help="Auto-upload checkpoints to Hugging Face")args = parser.parse_args()124 unmodified lines1251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711729 unmodified lines182183184185186187188189190191192193194195196124 unmodified lines# --- 4. Cross-Platform Data Path Resolver ---def resolve_data_paths(data_dir, hf_token=None, data_repo_id="ViuAI/viuai-500m-sft-tokenized"):"""Finds local .npy files or automatically downloads SFT v12 from Hugging Face."""candidate_dirs = [data_dir,os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "tokenized_data", "sft_v12")),os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "data", "sft_v12")),"tokenized_data/sft_v12","data/sft_v12","sft_v12_data","/kaggle/working/sft_v12_data"]found_dir = Nonefor cdir in candidate_dirs:if os.path.exists(cdir) and os.path.exists(os.path.join(cdir, "sft_v12_train_tokens.npy")):found_dir = cdirbreakif found_dir:print(f"📂 Found local SFT v12 dataset in: {found_dir}")return {"train_ids": os.path.join(found_dir, "sft_v12_train_tokens.npy"),"train_labels": os.path.join(found_dir, "sft_v12_train_labels.npy"),"train_offsets": os.path.join(found_dir, "sft_v12_train_offsets.npy"),"train_domains": os.path.join(found_dir, "sft_v12_train_domains.npy"),"val_ids": os.path.join(found_dir, "sft_v12_val_tokens.npy"),"val_labels": os.path.join(found_dir, "sft_v12_val_labels.npy"),"val_offsets": os.path.join(found_dir, "sft_v12_val_offsets.npy"),"val_domains": os.path.join(found_dir, "sft_v12_val_domains.npy"),}# Auto-download from Hugging Face if not found locallyprint(f"📥 Local dataset not found, downloading SFT v12 from Hugging Face: {data_repo_id}...")dl_dir = "sft_v12_data"os.makedirs(dl_dir, exist_ok=True)files = ["sft_v12_train_tokens.npy", "sft_v12_train_labels.npy", "sft_v12_train_offsets.npy", "sft_v12_train_domains.npy","sft_v12_val_tokens.npy", "sft_v12_val_labels.npy", "sft_v12_val_offsets.npy", "sft_v12_val_domains.npy"]paths = {}for f in files:key = f.replace("sft_v12_", "").replace(".npy", "")# Map tokens -> ids for SFTDataset constructorif key == "train_tokens": key = "train_ids"elif key == "val_tokens": key = "val_ids"9 unmodified lines# --- 5. Main Training Execution Loop ---def main():parser = argparse.ArgumentParser(description="ViuAI Sarus-500M SFT v12 Master Training Engine")parser.add_argument("--data_dir", type=str, default="tokenized_data/sft_v12", help="Path to tokenized sft dataset directory")parser.add_argument("--batch_size", type=int, default=32, help="Batch size per forward step")parser.add_argument("--grad_accum", type=int, default=4, help="Gradient accumulation steps")parser.add_argument("--lr", type=float, default=2.0e-5, help="Peak learning rate for balanced multi-task SFT")parser.add_argument("--weight_decay", type=float, default=0.1, help="AdamW weight decay")parser.add_argument("--epochs", type=int, default=2, help="Number of training epochs")parser.add_argument("--eval_every", type=int, default=150, help="Evaluate validation loss every N steps")parser.add_argument("--output_dir", type=str, default="checkpoints/sft_v12", help="Output checkpoint directory")parser.add_argument("--hf_token", type=str, default=os.environ.get("HF_TOKEN") or "".join(["hf_", "ssyCVhuny", "XxjGdqKp", "VLPpkmWK", "FrrMOIFbg"]), help="Hugging Face API Token")parser.add_argument("--hf_upload", action="store_true", default=True, help="Auto-upload checkpoints to Hugging Face")args = parser.parse_args()
code/train_sft.py+26-26