sunkencity commited on
Commit
689d2ea
·
verified ·
1 Parent(s): 69fb596

Upload train_survival.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_survival.py +30 -5
train_survival.py CHANGED
@@ -17,6 +17,20 @@ OUTPUT_MODEL_ID = "sunkencity/survival-expert-3b"
17
  # Load Dataset
18
  dataset = load_dataset(DATASET_ID, split="train")
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  # Load Model
21
  bnb_config = BitsAndBytesConfig(
22
  load_in_4bit=True,
@@ -56,14 +70,25 @@ training_args = SFTConfig(
56
  fp16=True,
57
  dataset_text_field="text",
58
  packing=False,
59
- max_length=1024 # Correct parameter name for SFTConfig
60
  )
61
 
62
  def formatting_prompts_func(example):
63
  output_texts = []
64
- for i in range(len(example['instruction'])):
65
- instruction = example['instruction'][i]
66
- response = example['response'][i]
 
 
 
 
 
 
 
 
 
 
 
67
  text = f"<|im_start|>user\n{instruction}<|im_end|>\n<|im_start|>assistant\n{response}<|im_end|>"
68
  output_texts.append(text)
69
  return output_texts
@@ -83,4 +108,4 @@ trainer.train()
83
 
84
  print("Pushing to hub...")
85
  trainer.push_to_hub()
86
- print("Done!")
 
17
  # Load Dataset
18
  dataset = load_dataset(DATASET_ID, split="train")
19
 
20
+ # SANITIZE DATASET
21
+ # Filter out any rows that have None or empty strings
22
+ def filter_empty(example):
23
+ return (
24
+ example["instruction"] is not None
25
+ and example["response"] is not None
26
+ and len(example["instruction"]) > 0
27
+ and len(example["response"]) > 0
28
+ )
29
+
30
+ print(f"Original dataset size: {len(dataset)}")
31
+ dataset = dataset.filter(filter_empty)
32
+ print(f"Filtered dataset size: {len(dataset)}")
33
+
34
  # Load Model
35
  bnb_config = BitsAndBytesConfig(
36
  load_in_4bit=True,
 
70
  fp16=True,
71
  dataset_text_field="text",
72
  packing=False,
73
+ max_length=1024
74
  )
75
 
76
  def formatting_prompts_func(example):
77
  output_texts = []
78
+ # Ensure we handle list input (batched)
79
+ instructions = example['instruction']
80
+ responses = example['response']
81
+
82
+ for i in range(len(instructions)):
83
+ if i >= len(responses):
84
+ break # Should not happen after filtering, but safety first
85
+
86
+ instruction = instructions[i]
87
+ response = responses[i]
88
+
89
+ if not instruction or not response:
90
+ continue
91
+
92
  text = f"<|im_start|>user\n{instruction}<|im_end|>\n<|im_start|>assistant\n{response}<|im_end|>"
93
  output_texts.append(text)
94
  return output_texts
 
108
 
109
  print("Pushing to hub...")
110
  trainer.push_to_hub()
111
+ print("Done!")