sam25kat commited on
Commit
88bf8da
·
verified ·
1 Parent(s): f3126c3

Upload train_sft.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_sft.py +16 -7
train_sft.py CHANGED
@@ -28,7 +28,7 @@ SCENARIO_FOLDER = "iac" # subdir under app/tasks/scenarios/
28
  MODEL_NAME = "unsloth/Qwen2.5-7B-Instruct-bnb-4bit"
29
  MAX_SEQ_LEN = 1536
30
  MAX_NEW_TOKENS = 600
31
- NUM_EPOCHS = 5
32
  LEARNING_RATE = 5e-5
33
  LORA_RANK = 16
34
  GRAD_ACCUM_STEPS = 2
@@ -194,11 +194,10 @@ def main():
194
 
195
  scenario_ids = [
196
  "iac_002", "iac_004", "iac_005", "iac_007",
197
- "iac_009", "iac_010", "iac_011", "iac_014",
198
- "iac_015", "iac_016", "iac_017", "iac_018",
199
- "iac_019", "iac_020", "iac_021",
200
- "iac_022", "iac_023",
201
- "iac_024",
202
  ]
203
  examples = []
204
  for sid in scenario_ids:
@@ -216,7 +215,7 @@ def main():
216
  full_text = tokenizer.apply_chat_template(
217
  messages, tokenize=False, add_generation_prompt=False
218
  )
219
- examples.append({"text": full_text})
220
  print(f" Loaded {sid} ({len(gt['ground_truth'])} findings)")
221
  except Exception as e:
222
  print(f" Skipping {sid}: {e}")
@@ -256,6 +255,16 @@ def main():
256
  baseline_scores = evaluate(scenario_ids, "before")
257
  print(f" Baseline mean: {sum(baseline_scores.values())/len(baseline_scores):.3f}")
258
 
 
 
 
 
 
 
 
 
 
 
259
  # SFT training
260
  print("\n[5/6] SFT training...")
261
  FastLanguageModel.for_training(model)
 
28
  MODEL_NAME = "unsloth/Qwen2.5-7B-Instruct-bnb-4bit"
29
  MAX_SEQ_LEN = 1536
30
  MAX_NEW_TOKENS = 600
31
+ NUM_EPOCHS = 3
32
  LEARNING_RATE = 5e-5
33
  LORA_RANK = 16
34
  GRAD_ACCUM_STEPS = 2
 
194
 
195
  scenario_ids = [
196
  "iac_002", "iac_004", "iac_005", "iac_007",
197
+ "iac_010", "iac_014",
198
+ "iac_016", "iac_018",
199
+ "iac_019", "iac_020",
200
+ "iac_022", "iac_023", "iac_024",
 
201
  ]
202
  examples = []
203
  for sid in scenario_ids:
 
215
  full_text = tokenizer.apply_chat_template(
216
  messages, tokenize=False, add_generation_prompt=False
217
  )
218
+ examples.append({"text": full_text, "scenario_id": sid})
219
  print(f" Loaded {sid} ({len(gt['ground_truth'])} findings)")
220
  except Exception as e:
221
  print(f" Skipping {sid}: {e}")
 
255
  baseline_scores = evaluate(scenario_ids, "before")
256
  print(f" Baseline mean: {sum(baseline_scores.values())/len(baseline_scores):.3f}")
257
 
258
+ # Curriculum filter — only train on scenarios with baseline <= 0.5
259
+ # (high-baseline scenarios already work; SFT on them causes regression)
260
+ CURRICULUM_THRESHOLD = 0.5
261
+ train_sids = [s for s in scenario_ids if baseline_scores.get(s, 1.0) <= CURRICULUM_THRESHOLD]
262
+ print(f"\n Curriculum filter (baseline <= {CURRICULUM_THRESHOLD}): "
263
+ f"{len(train_sids)}/{len(scenario_ids)} scenarios → {train_sids}")
264
+ filtered = [{"text": e["text"]} for e in examples if e["scenario_id"] in train_sids]
265
+ dataset = Dataset.from_list(filtered)
266
+ print(f" Filtered training dataset: {len(filtered)} examples")
267
+
268
  # SFT training
269
  print("\n[5/6] SFT training...")
270
  FastLanguageModel.for_training(model)