Upload train.py with huggingface_hub
Browse files
train.py
CHANGED
|
@@ -131,6 +131,20 @@ def train(a):
|
|
| 131 |
recs = [r for r in recs if r["src"] not in gold_ids] # never train on gold
|
| 132 |
print("training %d records | gold %d (disjoint)" % (len(recs), len(gold)), flush=True)
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
print("BEFORE:", json.dumps(evaluate(m, gold, tok, cfg, dev)), flush=True)
|
| 135 |
if a.eval_only:
|
| 136 |
return
|
|
@@ -173,15 +187,6 @@ def train(a):
|
|
| 173 |
# two running moments per parameter, and OneCycleLR has to know where on its
|
| 174 |
# curve it stopped. Without both it is a warm start with a fresh warmup cycle,
|
| 175 |
# not a continuation -- the learning rate jumps back up and shakes the weights.
|
| 176 |
-
# --init is NOT --resume. Resuming continues an interrupted run on its own
|
| 177 |
-
# schedule; init starts a NEW run from trained weights, with a fresh optimizer
|
| 178 |
-
# and a fresh learning-rate curve. Use it to add a question, or to retrain one
|
| 179 |
-
# question on a rebalanced set without starting from the base model.
|
| 180 |
-
if a.init:
|
| 181 |
-
st = torch.load(a.init, map_location=dev, weights_only=False)
|
| 182 |
-
m.load_state_dict(st["model"] if "model" in st else st)
|
| 183 |
-
print(" initialised from %s (fresh optimizer and schedule)" % a.init, flush=True)
|
| 184 |
-
|
| 185 |
src = a.resume or os.environ.get("LAYA_RESUME")
|
| 186 |
if src and os.path.exists(src):
|
| 187 |
st = torch.load(src, map_location=dev, weights_only=False)
|
|
|
|
| 131 |
recs = [r for r in recs if r["src"] not in gold_ids] # never train on gold
|
| 132 |
print("training %d records | gold %d (disjoint)" % (len(recs), len(gold)), flush=True)
|
| 133 |
|
| 134 |
+
# --init is NOT --resume. Resuming continues an interrupted run on its own
|
| 135 |
+
# schedule; init starts a NEW run from trained weights, with a fresh optimizer
|
| 136 |
+
# and a fresh learning-rate curve. Use it to add a question, or to retrain one
|
| 137 |
+
# question on a rebalanced set without starting from the base model.
|
| 138 |
+
#
|
| 139 |
+
# This has to happen BEFORE the baseline measurement. Loading the weights
|
| 140 |
+
# after it prints a "before" score for the untrained model -- which is not
|
| 141 |
+
# the number you are comparing against, and the run looks like a bigger win
|
| 142 |
+
# than it was.
|
| 143 |
+
if a.init:
|
| 144 |
+
st = torch.load(a.init, map_location=dev, weights_only=False)
|
| 145 |
+
m.load_state_dict(st["model"] if "model" in st else st)
|
| 146 |
+
print(" initialised from %s (fresh optimizer and schedule)" % a.init, flush=True)
|
| 147 |
+
|
| 148 |
print("BEFORE:", json.dumps(evaluate(m, gold, tok, cfg, dev)), flush=True)
|
| 149 |
if a.eval_only:
|
| 150 |
return
|
|
|
|
| 187 |
# two running moments per parameter, and OneCycleLR has to know where on its
|
| 188 |
# curve it stopped. Without both it is a warm start with a fresh warmup cycle,
|
| 189 |
# not a continuation -- the learning rate jumps back up and shakes the weights.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
src = a.resume or os.environ.get("LAYA_RESUME")
|
| 191 |
if src and os.path.exists(src):
|
| 192 |
st = torch.load(src, map_location=dev, weights_only=False)
|