Upload code/train_sft.py with huggingface_hub
Browse files280 unmodified lines28128228328428528628766 unmodified lines35435535635735835936036136236336436536658 unmodified lines425426427428429430431432433434435436437427 unmodified lines865866867868869870871872873874875876877280 unmodified linesdef ensure_cloud_data_and_checkpoint(version: str, data_dir: str, ckpt_path: str, token: str = None):stage_subfolder = f"sft_{version}"target_data_folder = os.path.join(data_dir, stage_subfolder)needed_files = [66 unmodified linesif tokenizer is None:returnif "translator" in version:test_suite = [("Identity", "<|user|>\nWho created you and what is your purpose?<|endofturn|>\n<|assistant|>\n", 40),("EN -> HI", "<|user|>\nTranslate to Hindi: 'The sun rises in the east and sets in the west.'<|endofturn|>\n<|assistant|>\n", 45),("HI -> EN", "<|user|>\nTranslate to English: 'सूरज पूर्व में उगता है और पश्चिम में डूबता है।'<|endofturn|>\n<|assistant|>\n", 45),("Proverb", "<|user|>\nTranslate to Hindi: 'Consistency and discipline are the keys to long term success.'<|endofturn|>\n<|assistant|>\n", 50),("Hinglish", "<|user|>\nTranslate to Hinglish: 'I am waiting outside your office, please call me when you are free.'<|endofturn|>\n<|assistant|>\n", 50)]else:test_suite = [58 unmodified linesroot_dir = os.path.abspath(os.path.join(cur_dir, ".."))data_dir = args.data_dir or os.path.join(root_dir, "tokenized_data")output_dir = args.output_dir or os.path.join(root_dir, "sft_checkpoints", f"sft_{args.version}")os.makedirs(output_dir, exist_ok=True)stage_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:427 unmodified linestry:api = HfApi(token=token)if os.path.exists(save_path):api.upload_file(path_or_fileobj=save_path,path_in_repo=f"sft_checkpoints/sft_{args.version}/{ckpt_filename}",repo_id="ViuAI/ViuAI-500M",repo_type="model")print(f"✅ Successfully uploaded {ckpt_filename} to ViuAI/ViuAI-500M (sft_checkpoints/sft_{args.version}/)!")except Exception as e:print(f"⚠️ Error uploading to Hugging Face: {e}")else:280 unmodified lines28128228328428528628728828929066 unmodified lines35735835936036136236336436536636736836958 unmodified lines428429430431432433434435436437438439440441442443444427 unmodified lines872873874875876877878879880881882883884885280 unmodified linesdef ensure_cloud_data_and_checkpoint(version: str, data_dir: str, ckpt_path: str, token: str = None):if str(version).lower() == "viutranslate":stage_subfolder = "ViuTranslate"else:stage_subfolder = f"sft_{version}"target_data_folder = os.path.join(data_dir, stage_subfolder)needed_files = [66 unmodified linesif tokenizer is None:returnif any(k in str(version).lower() for k in ["translat", "viutranslate"]):test_suite = [("Identity", "<|user|>\nWho created you and what is your purpose?<|endofturn|>\n<|assistant|>\n", 40),("EN -> HI Direct", "<|user|>\nThe sun rises in the east and sets in the west.<|endofturn|>\n<|assistant|>\n", 45),("HI -> EN Direct", "<|user|>\nसूरज पूर्व में उगता है और पश्चिम में डूबता है।<|endofturn|>\n<|assistant|>\n", 45),("Proverb Command", "<|user|>\nTranslate to Hindi: 'Consistency and discipline are the keys to long term success.'<|endofturn|>\n<|assistant|>\n", 50),("Hinglish Command","<|user|>\nTranslate to Hinglish: 'I am waiting outside your office, please call me when you are free.'<|endofturn|>\n<|assistant|>\n", 50)]else:test_suite = [58 unmodified linesroot_dir = os.path.abspath(os.path.join(cur_dir, ".."))data_dir = args.data_dir or os.path.join(root_dir, "tokenized_data")stage_subfolder = "ViuTranslate" if str(args.version).lower() == "viutranslate" else f"sft_{args.version}"stage_data_dir = os.path.join(data_dir, stage_subfolder)output_dir = args.output_dir or (os.path.join(root_dir, "sft_checkpoints", "ViuTranslate")if str(args.version).lower() == "viutranslate"else os.path.join(root_dir, "sft_checkpoints", f"sft_{args.version}"))os.makedirs(output_dir, exist_ok=True)ckpt_filename = "viutranslate_final.pt" if str(args.version).lower() == "viutranslate" else f"sft_{args.version}_final.pt"save_path = os.path.join(output_dir, ckpt_filename)if args.init_ckpt:427 unmodified linestry:api = HfApi(token=token)if os.path.exists(save_path):repo_subfolder = "ViuTranslate" if str(args.version).lower() == "viutranslate" else f"sft_{args.version}"api.upload_file(path_or_fileobj=save_path,path_in_repo=f"sft_checkpoints/{repo_subfolder}/{ckpt_filename}",repo_id="ViuAI/ViuAI-500M",repo_type="model")print(f"✅ Successfully uploaded {ckpt_filename} to ViuAI/ViuAI-500M (sft_checkpoints/{repo_subfolder}/)!")except Exception as e:print(f"⚠️ Error uploading to Hugging Face: {e}")else:
code/train_sft.py+22-14