Upload code/train_sft.py with huggingface_hub
Browse files- code/train_sft.py +27 -5
code/train_sft.py
CHANGED
|
@@ -290,10 +290,10 @@ def ensure_cloud_data_and_checkpoint(version: str, data_dir: str, ckpt_path: str
|
|
| 290 |
|
| 291 |
|
| 292 |
# ------------------------------------------------------------------------------
|
| 293 |
-
# 7. Live Generation Helper for Training Telemetry
|
| 294 |
# ------------------------------------------------------------------------------
|
| 295 |
@torch.no_grad()
|
| 296 |
-
def generate_sample_preview(model, tokenizer, device, prompt
|
| 297 |
if tokenizer is None:
|
| 298 |
return ""
|
| 299 |
model.eval()
|
|
@@ -309,6 +309,29 @@ def generate_sample_preview(model, tokenizer, device, prompt="<|user|>\nWho crea
|
|
| 309 |
model.train()
|
| 310 |
|
| 311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
# ------------------------------------------------------------------------------
|
| 313 |
# 8. Main Ultra-Optimized Training Engine
|
| 314 |
# ------------------------------------------------------------------------------
|
|
@@ -661,10 +684,9 @@ def main():
|
|
| 661 |
# Print Domain Loss Breakdown
|
| 662 |
print(" 📊 Domain Breakdown: " + " | ".join([f"{k[:6]}: {v:.3f}" for k, v in d_losses.items()]))
|
| 663 |
|
| 664 |
-
# Live Sample Generation
|
| 665 |
if tokenizer is not None:
|
| 666 |
-
|
| 667 |
-
print(f" 💬 [Preview Identity]: \"{preview_id}\"")
|
| 668 |
|
| 669 |
is_best = v_loss < best_val_loss
|
| 670 |
if is_best:
|
|
|
|
| 290 |
|
| 291 |
|
| 292 |
# ------------------------------------------------------------------------------
|
| 293 |
+
# 7. Live Generation Helper for Training Telemetry (Multi-Domain Previews)
|
| 294 |
# ------------------------------------------------------------------------------
|
| 295 |
@torch.no_grad()
|
| 296 |
+
def generate_sample_preview(model, tokenizer, device, prompt: str, max_new_tokens=60):
|
| 297 |
if tokenizer is None:
|
| 298 |
return ""
|
| 299 |
model.eval()
|
|
|
|
| 309 |
model.train()
|
| 310 |
|
| 311 |
|
| 312 |
+
def run_live_eval_previews(model, tokenizer, device):
|
| 313 |
+
"""Runs a suite of multi-domain test prompts to visually monitor model progress."""
|
| 314 |
+
if tokenizer is None:
|
| 315 |
+
return
|
| 316 |
+
|
| 317 |
+
test_suite = [
|
| 318 |
+
("Identity", "<|user|>\nWho created you?<|endofturn|>\n<|assistant|>\n", 40),
|
| 319 |
+
("Greeting", "<|user|>\nHello! Kaise ho aap?<|endofturn|>\n<|assistant|>\n", 40),
|
| 320 |
+
("Translation", "<|user|>\nTranslate the following English sentence to Hindi:\n\"Artificial intelligence is shaping the future.\"<|endofturn|>\n<|assistant|>\n", 50),
|
| 321 |
+
("Logic & Math", "<|user|>\nIf a train travels at 60 km/h, how far will it travel in 3.5 hours?<|endofturn|>\n<|assistant|>\n", 80),
|
| 322 |
+
("Coding", "<|user|>\nWrite a Python function to check if a number is prime.<|endofturn|>\n<|assistant|>\n", 70)
|
| 323 |
+
]
|
| 324 |
+
|
| 325 |
+
print(" 💬 --- [LIVE MULTI-DOMAIN TEST PREVIEWS] ---")
|
| 326 |
+
for category, prompt, max_tok in test_suite:
|
| 327 |
+
answer = generate_sample_preview(model, tokenizer, device, prompt, max_new_tokens=max_tok)
|
| 328 |
+
# Format response cleanly for terminal
|
| 329 |
+
clean_ans = answer.replace("\n", " ").strip()
|
| 330 |
+
if len(clean_ans) > 120:
|
| 331 |
+
clean_ans = clean_ans[:117] + "..."
|
| 332 |
+
print(f" • [{category:12s}]: \"{clean_ans}\"")
|
| 333 |
+
|
| 334 |
+
|
| 335 |
# ------------------------------------------------------------------------------
|
| 336 |
# 8. Main Ultra-Optimized Training Engine
|
| 337 |
# ------------------------------------------------------------------------------
|
|
|
|
| 684 |
# Print Domain Loss Breakdown
|
| 685 |
print(" 📊 Domain Breakdown: " + " | ".join([f"{k[:6]}: {v:.3f}" for k, v in d_losses.items()]))
|
| 686 |
|
| 687 |
+
# Live Multi-Domain Sample Generation Previews
|
| 688 |
if tokenizer is not None:
|
| 689 |
+
run_live_eval_previews(model, tokenizer, device)
|
|
|
|
| 690 |
|
| 691 |
is_best = v_loss < best_val_loss
|
| 692 |
if is_best:
|