Update code/train_sft.py for SFT v1 21-domain curriculum
Browse files134 unmodified lines1351361371381391401411421431441451461471481491501517 unmodified lines159160161162163164251 unmodified lines4164174184194204216 unmodified lines428429430431432433138 unmodified lines572573574575576577438 unmodified lines1016101710181019102010211022102310241025102610271028102910301031103210331034103510361037134 unmodified linesDOMAIN_NAMES_V25 = DOMAIN_NAMES_V22DOMAIN_NAMES_V26 = DOMAIN_NAMES_V22# SFT v1 (Sarus Master 9-Domain Architecture)DOMAIN_NAMES_V1 = {0: "identity_sarus",1: "greetings_cultural",2: "ncert_indian_history",3: "coding_tech",4: "math_arithmetic",5: "general_stem",6: "hindi_culture",7: "summarization_translation",8: "multiturn_dialogue"}# SFT v2 (Sarus Pure Chat 8-Domain Architecture - 0% Math, 0% Code)7 unmodified lines6: "culture_recipes_lifestyle",7: "translation_bilingual"}DOMAIN_NAMES = DOMAIN_NAMES_V2251 unmodified lines("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)]elif _vnum == "2":test_suite = [6 unmodified lines("Writing (Email)", "<|user|>\nWrite a 2-sentence formal leave request email to my manager.<|endofturn|>\n<|assistant|>\n", 60),("Proverb Translate","<|user|>\nTranslate to Hindi: 'Consistency and discipline are the keys to long term success.'<|endofturn|>\n<|assistant|>\n", 50)]else:test_suite = [("Identity", "<|user|>\nWho created you and what is your name?<|endofturn|>\n<|assistant|>\n", 40),138 unmodified linesvnum = vnorm[1:] if vnorm.startswith("v") and vnorm[1:].isdigit() else vnormif vnorm == "viutranslate" or vnum in ("2",):DOMAIN_NAMES = DOMAIN_NAMES_V2elif vnum in ("1",):DOMAIN_NAMES = DOMAIN_NAMES_V1elif vnum in ("22", "23", "24", "25", "26"):438 unmodified linesif os.path.exists(best_save_path):print(f"🏆 Best checkpoint (lowest val loss) kept at: {best_save_path}")# Push to Hugging Face Hub (Only Final Checkpoint - saves ~10 mins upload time)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):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:134 unmodified lines1351361371381391401411421431441451461471481491501511521531541551561571581591601611621637 unmodified lines171172173174175176177178179180181182183184185186251 unmodified lines4384394404414424434444454464474484494504514524534544554564574586 unmodified lines465466467468469470471472473474475476477478479480481482138 unmodified lines621622623624625626627628438 unmodified lines1067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091134 unmodified linesDOMAIN_NAMES_V25 = DOMAIN_NAMES_V22DOMAIN_NAMES_V26 = DOMAIN_NAMES_V22# SFT v1 (Sarus Master 21-Domain Architecture - 100% Pure English)DOMAIN_NAMES_V1 = {0: "identity_persona",1: "ncert_curriculum",2: "indian_history_affairs",3: "everyday_chat_empathy",4: "multiturn_dialogue",5: "instruction_following",6: "typo_robustness_slangs",7: "summarization_tldr",8: "corporate_workplace_writing",9: "cooking_kitchen_science",10: "antihallucination_trick_qa",11: "extraction_table_formatting",12: "comparisons_pros_cons",13: "health_wellness_remedies",14: "career_guidance_interview",15: "tech_troubleshooting",16: "indian_festivals_heritage",17: "finance_budgeting_scam_safety",18: "mental_wellness_exam_habits",19: "creative_writing_scripts",20: "commonsense_practical_logic"}# SFT v2 (Sarus Pure Chat 8-Domain Architecture - 0% Math, 0% Code)7 unmodified lines6: "culture_recipes_lifestyle",7: "translation_bilingual"}# SFT v3 (Sarus English-Only 6-Domain Architecture - 0% Hindi, 0% Translation)DOMAIN_NAMES_V3 = {0: "identity_sarus_en",1: "greetings_everyday_en",2: "conversational_dialogue_en",3: "general_knowledge_science_en",4: "practical_writing_tasks_en",5: "culture_recipes_lifestyle_en"}DOMAIN_NAMES = DOMAIN_NAMES_V2251 unmodified lines("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)elif _vnum == "1":# SFT v1: 100% Pure English, 21 capability domains, 0% Math, 0% Translationtest_suite = [("Identity", "<|user|>\nWho created you and what is your name?<|endofturn|>\n<|assistant|>\n", 40),("Competitor Deny", "<|user|>\nAre you ChatGPT made by OpenAI?<|endofturn|>\n<|assistant|>\n", 40),("Everyday Chat", "<|user|>\nHey! I had a very busy day at work and feeling tired.<|endofturn|>\n<|assistant|>\n", 50),("NCERT Science", "<|user|>\nWhat causes lightning and thunder in the atmosphere?<|endofturn|>\n<|assistant|>\n", 60),("Indian History", "<|user|>\nWhen did the Constitution of India come into effect and who was the Chairman of the Drafting Committee?<|endofturn|>\n<|assistant|>\n", 60),("Typo Robustness", "<|user|>\nplz tell me hw 2 improve my focus in study<|endofturn|>\n<|assistant|>\n", 55),("Writing (Email)", "<|user|>\nWrite a polite 2-sentence leave request email to my manager.<|endofturn|>\n<|assistant|>\n", 50),("Cooking Recipe", "<|user|>\nExplain how to prepare authentic Kadak Masala Chai step by step.<|endofturn|>\n<|assistant|>\n", 70),("Health Care", "<|user|>\nWhat are common signs of dehydration and how can you treat it?<|endofturn|>\n<|assistant|>\n", 60),("Comparison", "<|user|>\nWhat are the main differences between SQL and NoSQL databases?<|endofturn|>\n<|assistant|>\n", 65),("Finance Safety", "<|user|>\nWhy should you never share your banking OTP with anyone?<|endofturn|>\n<|assistant|>\n", 50),("Common Sense", "<|user|>\nIf yesterday was Sunday, what day of the week will it be in 15 days?<|endofturn|>\n<|assistant|>\n", 45)]elif _vnum == "2":test_suite = [6 unmodified lines("Writing (Email)", "<|user|>\nWrite a 2-sentence formal leave request email to my manager.<|endofturn|>\n<|assistant|>\n", 60),("Proverb Translate","<|user|>\nTranslate to Hindi: 'Consistency and discipline are the keys to long term success.'<|endofturn|>\n<|assistant|>\n", 50)]elif _vnum == "3":# v3 is English-only: no Hindi/math/coding probes (0% in data by design).test_suite = [("Identity", "<|user|>\nWho created you and what is your name?<|endofturn|>\n<|assistant|>\n", 40),("Competitor Deny", "<|user|>\nAre you ChatGPT made by OpenAI?<|endofturn|>\n<|assistant|>\n", 40),("Greeting", "<|user|>\nHey! How are you doing today?<|endofturn|>\n<|assistant|>\n", 35),("Science Fact", "<|user|>\nWhat gas do humans inhale to stay alive?<|endofturn|>\n<|assistant|>\n", 40),("World GK", "<|user|>\nWho was the first President of the United States? Answer in one line.<|endofturn|>\n<|assistant|>\n", 40),("Everyday Chat", "<|user|>\nI'm feeling a bit low today, tell me something nice.<|endofturn|>\n<|assistant|>\n", 50),("Writing (Email)", "<|user|>\nWrite a 2-sentence formal leave request email to my manager.<|endofturn|>\n<|assistant|>\n", 60),("Summarization", "<|user|>\nSummarize why yoga is important for mental and physical health in 2 sentences.<|endofturn|>\n<|assistant|>\n", 50)]else:test_suite = [("Identity", "<|user|>\nWho created you and what is your name?<|endofturn|>\n<|assistant|>\n", 40),138 unmodified linesvnum = vnorm[1:] if vnorm.startswith("v") and vnorm[1:].isdigit() else vnormif vnorm == "viutranslate" or vnum in ("2",):DOMAIN_NAMES = DOMAIN_NAMES_V2elif vnum in ("3",):DOMAIN_NAMES = DOMAIN_NAMES_V3elif vnum in ("1",):DOMAIN_NAMES = DOMAIN_NAMES_V1elif vnum in ("22", "23", "24", "25", "26"):438 unmodified linesif os.path.exists(best_save_path):print(f"🏆 Best checkpoint (lowest val loss) kept at: {best_save_path}")# Push to Hugging Face Hub (final + best checkpoints)if args.push_to_hf:print("\n🚀 Pushing Final + Best 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)repo_subfolder = "ViuTranslate" if str(args.version).lower() == "viutranslate" else f"sft_{args.version}"for _local, _name in [(save_path, ckpt_filename), (best_save_path, best_filename)]:if os.path.exists(_local):api.upload_file(path_or_fileobj=_local,path_in_repo=f"sft_checkpoints/{repo_subfolder}/{_name}",repo_id="ViuAI/ViuAI-500M",repo_type="model")print(f"✅ Successfully uploaded {_name} to ViuAI/ViuAI-500M (sft_checkpoints/{repo_subfolder}/)!")else:print(f"⚠️ Skipping upload (not found): {_local}")except Exception as e:print(f"⚠️ Error uploading to Hugging Face: {e}")else:
code/train_sft.py+75-21