fnruha0921 commited on
Commit
5cede12
·
verified ·
1 Parent(s): b792420

stage3: drop snake records from training

Browse files
Files changed (1) hide show
  1. code/train.py +14 -1
code/train.py CHANGED
@@ -8,7 +8,7 @@ Loss per step = proper score(full) + proper score(fast) + lambda * KL(stopgrad p
8
  LayerSkip / MatFormer style). LoRA r=16 on attention q/k/v/o only, so FFN slicing stays exact.
9
  Trains in a background thread; progress in /content/train.log.
10
  """
11
- import math, random, threading, time, json
12
  import torch, torch.nn.functional as F
13
  from torch.utils.checkpoint import checkpoint
14
  from mmjev import FastConfig, decision_loss, set_ffn_width, QTYPES
@@ -82,6 +82,16 @@ def add_lora(jev, r=16, alpha=32, mlp_from=10):
82
 
83
 
84
  EXCLUDE_TASKS = {"typed_decisions", "snake_syn"} # benchmark train split + demo task: both kept out (zero-shot)
 
 
 
 
 
 
 
 
 
 
85
 
86
 
87
  def train_records(DATA, calib_frac=0.05, seed=0, modalities=None, max_records=None):
@@ -174,6 +184,9 @@ def train(jev, DATA, epochs=1, bs=4, lr_lora=2e-4, lr_head=1e-3, warmup=50, moda
174
  tr, cal = train_records(DATA, modalities=modalities, max_records=max_records)
175
  else:
176
  tr, cal = recs
 
 
 
177
  globals()["CALIB"] = cal
178
  log(f"train records {len(tr)} calib {len(cal)}")
179
  if lora:
 
8
  LayerSkip / MatFormer style). LoRA r=16 on attention q/k/v/o only, so FFN slicing stays exact.
9
  Trains in a background thread; progress in /content/train.log.
10
  """
11
+ import collections, math, random, re, threading, time, json
12
  import torch, torch.nn.functional as F
13
  from torch.utils.checkpoint import checkpoint
14
  from mmjev import FastConfig, decision_loss, set_ffn_width, QTYPES
 
82
 
83
 
84
  EXCLUDE_TASKS = {"typed_decisions", "snake_syn"} # benchmark train split + demo task: both kept out (zero-shot)
85
+ _SNAKE_Q = re.compile(r"\bsnake\b", re.I)
86
+
87
+
88
+ def is_snake(r):
89
+ """Snake-game records from any public corpus (Open-Jev snake-v1 boards, snake questions): kept out of training."""
90
+ if r["task"].startswith("snake"):
91
+ return True
92
+ if any(s.kind == "text" and '"game": "snake"' in str(s.data) for s in r["state"]):
93
+ return True
94
+ return any(_SNAKE_Q.search(q.get("instructions", "")) for q in r["qs"])
95
 
96
 
97
  def train_records(DATA, calib_frac=0.05, seed=0, modalities=None, max_records=None):
 
184
  tr, cal = train_records(DATA, modalities=modalities, max_records=max_records)
185
  else:
186
  tr, cal = recs
187
+ drop = collections.Counter(r["task"] for r in tr + cal if is_snake(r))
188
+ tr, cal = [r for r in tr if not is_snake(r)], [r for r in cal if not is_snake(r)]
189
+ log(f"snake records removed: {sum(drop.values())} {dict(drop.most_common(8))}")
190
  globals()["CALIB"] = cal
191
  log(f"train records {len(tr)} calib {len(cal)}")
192
  if lora: