Upload code/train_sft.py with huggingface_hub
Browse files389 unmodified lines3903913923933943953963973983994004014025 unmodified lines408409410411412413414389 unmodified linesckpt_path = os.path.join(work, "checkpoints", "ckpt_latest.pt")ckpt = torch.load(ckpt_path, map_location=device)state_dict = ckpt.get("model_state_dict", ckpt)raw_model = model.module if hasattr(model, "module") else modelremapped_sd = remap_checkpoint_keys(state_dict, raw_model.state_dict())# Resize embedding and head if vocab grew (e.g. 64000 -> 64009)model_sd = raw_model.state_dict()for k in ["tok_emb.weight", "head.weight"]:if k in remapped_sd and k in model_sd and remapped_sd[k].shape != model_sd[k].shape:old_w = remapped_sd[k]new_w = model_sd[k].clone()5 unmodified linesraw_model.load_state_dict(remapped_sd, strict=False)if is_main:print("✅ Base pre-trained weights successfully loaded into SFT model!", flush=True)del ckptgc.collect()if torch.cuda.is_available():389 unmodified lines3903913923933943953963973983994004014024034044054064075 unmodified lines413414415416417418419389 unmodified linesckpt_path = os.path.join(work, "checkpoints", "ckpt_latest.pt")ckpt = torch.load(ckpt_path, map_location=device)if "model_state_dict" in ckpt:state_dict = ckpt["model_state_dict"]elif "model" in ckpt:state_dict = ckpt["model"]else:state_dict = ckptraw_model = model.module if hasattr(model, "module") else modelremapped_sd = remap_checkpoint_keys(state_dict, raw_model.state_dict())# Resize embedding and head if vocab grew (e.g. 64000 -> 64009)model_sd = raw_model.state_dict()for k in ["tok_emb.weight", "head.weight", "_orig_mod.tok_emb.weight", "_orig_mod.head.weight"]:if k in remapped_sd and k in model_sd and remapped_sd[k].shape != model_sd[k].shape:old_w = remapped_sd[k]new_w = model_sd[k].clone()5 unmodified linesraw_model.load_state_dict(remapped_sd, strict=False)if is_main:print(f"✅ Base pre-trained weights ({len(remapped_sd)} tensors) successfully loaded into SFT model!", flush=True)del ckptgc.collect()if torch.cuda.is_available():
code/train_sft.py+8-3