darrenphodgson76 commited on
Commit
b095c6e
Β·
verified Β·
1 Parent(s): 6bb00a3

Update train.py

Browse files
Files changed (1) hide show
  1. train.py +11 -24
train.py CHANGED
@@ -57,28 +57,15 @@ trainer = SFTTrainer(
57
 
58
  trainer.train()
59
 
60
- # Save the fine-tuned LoRA adapter
61
- model.save_pretrained("./lora-finetuned")
 
62
 
63
- # Copy to final_model AND Hugging Face root directory
64
- src_dir = "./lora-finetuned"
65
- dst_dir = "/home/user/app/final_model"
66
- root_dir = "/home/user/app"
67
- os.makedirs(dst_dir, exist_ok=True)
68
-
69
- if os.path.exists(src_dir):
70
- for fname in os.listdir(src_dir):
71
- fpath = os.path.join(src_dir, fname)
72
- if os.path.isfile(fpath):
73
- shutil.copy2(fpath, dst_dir)
74
- print(f"βœ… Copied {fname} to final_model")
75
-
76
- try:
77
- shutil.copy2(fpath, root_dir)
78
- print(f"βœ… Copied {fname} to app root for UI visibility")
79
- except Exception as e:
80
- print(f"⚠️ Failed to copy {fname} to root: {e}")
81
- else:
82
- print(f"πŸ“‚ Skipped {fname} (not a file)")
83
- else:
84
- print("❌ Source folder does not exist")
 
57
 
58
  trainer.train()
59
 
60
+ # βœ… Save to Hugging Face persistent path
61
+ output_path = "./outputs/final_model"
62
+ os.makedirs(output_path, exist_ok=True)
63
 
64
+ try:
65
+ model.save_pretrained(output_path)
66
+ print(f"βœ… Model saved to {output_path}")
67
+ print("πŸ“ Contents of saved model directory:")
68
+ for file in os.listdir(output_path):
69
+ print(" -", file)
70
+ except Exception as e:
71
+ print(f"❌ Failed to save model: {e}")