Upload code/train_align.py with huggingface_hub
Browse files225 unmodified lines22622722822923023123223323423523623723823924024124224324424524624724824925025125225350 unmodified lines304305306307308309310311312313225 unmodified linesanchors.append({"prompt": p.capitalize(), "chosen": r})anchors.append({"prompt": p + "?", "chosen": r})# 9. Load Gold DPO Pairs from ViuAI/500M_Sarus_DPOdpo_file = os.path.join("data", "dpo_5k", "dpo_train.json")if not os.path.exists(dpo_file):if IS_MAIN:print(" ⬇️ Fetching gold DPO dataset from Hugging Face...")dl = hf_hub_download(repo_id=DATA_REPO, filename="dpo_5k/dpo_train.json", repo_type="dataset", token=HF_TOKEN)os.makedirs(os.path.dirname(dpo_file), exist_ok=True)shutil.copy(dl, dpo_file)if IS_DDP:dist.barrier()with open(dpo_file, "r", encoding="utf-8") as f:dpo_data = json.load(f)# Combine: anchors + DPO gold chosen pairscombined = list(anchors) + dpo_data# Shuffle for uniform distribution across batchesrandom.seed(42)random.shuffle(combined)if IS_MAIN:print(f" ✅ Dataset Prepared: {len(anchors)} Curated Anchors + {len(dpo_data)} Gold DPO Pairs = {len(combined):,} Total Pairs!")return combined# ==============================================================================50 unmodified linescandidates = [args.base_checkpoint,"sft_checkpoints/sft_v2/sft_v2_final.pt","dpo_checkpoints/dpo_5k/dpo_5k_best.pt","dpo_checkpoints/dpo_5k/dpo_5k_final.pt","sft_v2_final.pt","dpo_5k_best.pt"]ckpt_path = Nonefor cand in candidates:225 unmodified lines22622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525650 unmodified lines307308309310311312313225 unmodified linesanchors.append({"prompt": p.capitalize(), "chosen": r})anchors.append({"prompt": p + "?", "chosen": r})# 9. Load Master Diverse Alignment Dataset (~10,000 unique non-repeating samples)diverse_file = os.path.join("data", "alignment_diverse", "sarus_align_diverse_10k.json")if not os.path.exists(diverse_file):if IS_MAIN:print(" ⬇️ Fetching master diverse alignment dataset from Hugging Face...")try:dl = hf_hub_download(repo_id=MODEL_REPO, filename="data/alignment_diverse/sarus_align_diverse_10k.json", token=HF_TOKEN)except Exception:dl = hf_hub_download(repo_id=DATA_REPO, filename="sarus_align_diverse_10k.json", repo_type="dataset", token=HF_TOKEN)os.makedirs(os.path.dirname(diverse_file), exist_ok=True)shutil.copy(dl, diverse_file)if IS_DDP:dist.barrier()with open(diverse_file, "r", encoding="utf-8") as f:diverse_data = json.load(f)# Combine: anchors + diverse pairs (strict zero repetition)combined = list(anchors) + diverse_data# Shuffle for uniform distribution across batchesrandom.seed(42)random.shuffle(combined)if IS_MAIN:print(f" ✅ Dataset Prepared: {len(combined):,} Truly Diverse Pairs (Zero Repetitive Hallucinations)!")return combined# ==============================================================================50 unmodified linescandidates = [args.base_checkpoint,"sft_checkpoints/sft_v2/sft_v2_final.pt","sft_v2_final.pt"]ckpt_path = Nonefor cand in candidates:
code/train_align.py+16-16