tchbcb commited on
Commit
ae3408c
·
verified ·
1 Parent(s): 8ecf30c

v0.4.8: safetensors-loss fix + HEAD verification + v0.4.7 OOM-gate sync

Browse files
Files changed (1) hide show
  1. ops/t4_real25.py +56 -15
ops/t4_real25.py CHANGED
@@ -39,9 +39,9 @@ system1:
39
  backend: "hf"
40
  hf_model: "Qwen/Qwen3-VL-2B-Instruct"
41
  hf_quant4: true
42
- max_leaf_tokens: 512
43
  score_levels: 10
44
- leaf_batch_size: 2
45
  eval_leaf_batch: 8
46
 
47
  stage_a_distill:
@@ -51,11 +51,11 @@ stage_b_sft:
51
  backbone_lr: 5.0e-5
52
  head_lr: 2.0e-4
53
  epochs: 1
54
- batch_questions: 2
55
- grad_accum: 2
56
- max_steps: 180 # real-games corpus is bigger; keep ~2h on T4
57
- save_every_steps: 20 # v0.4.6: WIP save every ~13min (T4-death insurance)
58
- aux_rows_per_batch: 3
59
  max_candidates: 4
60
  lora:
61
  enabled: true
@@ -146,7 +146,34 @@ def hf_api():
146
  return HfApi(token=(WORK / ".hf_token").read_text().strip())
147
 
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  def upload(name, local: Path, in_repo: str):
 
 
150
  for attempt in (1, 2, 3):
151
  try:
152
  t0 = time.time()
@@ -154,14 +181,18 @@ def upload(name, local: Path, in_repo: str):
154
  path_or_fileobj=str(local), path_in_repo=in_repo,
155
  repo_id=HF_REPO, repo_type="model",
156
  commit_message=f"t4_assets_v3: {name} (real-games run)")
157
- print(f"[v3] uploaded {in_repo} in {time.time()-t0:.0f}s",
158
- flush=True)
159
- return
 
 
 
 
160
  except Exception as e:
161
  print(f"[v3] upload {name} attempt {attempt} failed: {e}",
162
  flush=True)
163
- time.sleep(20)
164
- raise SystemExit(f"[v3] upload {name} gave up")
165
 
166
 
167
  def upload_soft(name, local: Path, in_repo: str):
@@ -169,13 +200,20 @@ def upload_soft(name, local: Path, in_repo: str):
169
  if not local.exists():
170
  print(f"[v3] upload_soft {name}: {local} missing, skip", flush=True)
171
  return
 
 
172
  for attempt in (1, 2):
173
  try:
174
  hf_api().upload_file(
175
  path_or_fileobj=str(local), path_in_repo=in_repo,
176
  repo_id=HF_REPO, repo_type="model",
177
  commit_message=f"t4_assets_v3: {name} (autosave)")
178
- print(f"[v3] soft-uploaded {in_repo}", flush=True)
 
 
 
 
 
179
  return
180
  except Exception as e:
181
  print(f"[v3] soft upload {name} attempt {attempt}: {e}",
@@ -205,10 +243,12 @@ def wip_uploader():
205
  sig = (f.stat().st_mtime, f.stat().st_size)
206
  if sig != last_sig:
207
  last_sig = sig
 
 
208
  for fn, dest in [("adapter_model.safetensors",
209
  f"{WIP_REPO}/adapter_model.safetensors"),
210
  ("adapter_config.json",
211
- f"{WIP_REPO}/adapter_config.json")]:
212
  p = WIP_DIR / fn
213
  if p.exists():
214
  upload_soft(f"wip-{fn}", p, dest)
@@ -327,11 +367,12 @@ hl = Path({str(OUT)!r}) / "hf_lora"
327
  sa = Path({str(OUT)!r}) / "stage_a_lora"
328
  if not (hl / "adapter_model.safetensors").exists():
329
  # fresh VM: pull the WIP LoRA that a crashed run pushed to HF
 
330
  if not (wip / "adapter_model.safetensors").exists():
331
  try:
332
  wip.mkdir(parents=True, exist_ok=True)
333
  p = hf_hub_download({HF_REPO!r},
334
- "t4_assets_v3/checkpoints/hf_lora_wip/adapter_model.safetensors")
335
  shutil.copy(p, wip / "adapter_model.safetensors")
336
  try:
337
  c = hf_hub_download({HF_REPO!r},
 
39
  backend: "hf"
40
  hf_model: "Qwen/Qwen3-VL-2B-Instruct"
41
  hf_quant4: true
42
+ max_leaf_tokens: 320 # OOM fix (old-T4 validated): 512 blew up on 64x64
43
  score_levels: 10
44
+ leaf_batch_size: 1 # OOM fix: 2 OOM-looped the T4
45
  eval_leaf_batch: 8
46
 
47
  stage_a_distill:
 
51
  backbone_lr: 5.0e-5
52
  head_lr: 2.0e-4
53
  epochs: 1
54
+ batch_questions: 1 # OOM fix (old-T4 validated): 2 death-looped oom-skips
55
+ grad_accum: 4 # OOM fix: keep effective batch at 4
56
+ max_steps: 180 # real-games corpus is bigger; ~38s/step on T4
57
+ save_every_steps: 20 # v0.4.6: WIP save every ~13min (T4-death insurance)
58
+ aux_rows_per_batch: 2 # OOM fix: 3 crowded the backward on 64x64 grids
59
  max_candidates: 4
60
  lora:
61
  enabled: true
 
146
  return HfApi(token=(WORK / ".hf_token").read_text().strip())
147
 
148
 
149
+ def hf_safe_name(in_repo: str) -> str:
150
+ """v0.4.8: HF silently STRIPS weight-like extensions (.safetensors/.bin)
151
+ from commits on this repo — commit lands, file 404s (LFS object path
152
+ broken server-side; verified live: same bytes as .pt upload fine,
153
+ .safetensors/.bin vanish at any size 96B..30MB, with xet on AND off).
154
+ .pt is proven end-to-end at 30MB test / 69MB lora / 254+323MB full
155
+ model. Map weight files to .pt for the IN-REPO name only."""
156
+ if in_repo.endswith(".safetensors"):
157
+ return in_repo[: -len(".safetensors")] + ".pt"
158
+ return in_repo
159
+
160
+
161
+ def verify_remote(in_repo: str, size: int) -> bool:
162
+ """HEAD-check that a file REALLY landed (uploads can report success
163
+ while the server strips the object)."""
164
+ import urllib.request
165
+ url = f"https://huggingface.co/{HF_REPO}/resolve/main/{in_repo}"
166
+ try:
167
+ r = urllib.request.urlopen(urllib.request.Request(url, method="HEAD"),
168
+ timeout=30)
169
+ return r.headers.get("Content-Length") == str(size)
170
+ except Exception:
171
+ return False
172
+
173
+
174
  def upload(name, local: Path, in_repo: str):
175
+ in_repo = hf_safe_name(in_repo)
176
+ size = Path(local).stat().st_size
177
  for attempt in (1, 2, 3):
178
  try:
179
  t0 = time.time()
 
181
  path_or_fileobj=str(local), path_in_repo=in_repo,
182
  repo_id=HF_REPO, repo_type="model",
183
  commit_message=f"t4_assets_v3: {name} (real-games run)")
184
+ time.sleep(2)
185
+ if verify_remote(in_repo, size):
186
+ print(f"[v3] uploaded {in_repo} in {time.time()-t0:.0f}s "
187
+ f"(HEAD ok {size}B)", flush=True)
188
+ return
189
+ print(f"[v3] upload {name}: HEAD-verify FAILED (file stripped "
190
+ f"server-side?), retrying", flush=True)
191
  except Exception as e:
192
  print(f"[v3] upload {name} attempt {attempt} failed: {e}",
193
  flush=True)
194
+ time.sleep(20)
195
+ raise SystemExit(f"[v3] upload {name} gave up — NOT safely on HF")
196
 
197
 
198
  def upload_soft(name, local: Path, in_repo: str):
 
200
  if not local.exists():
201
  print(f"[v3] upload_soft {name}: {local} missing, skip", flush=True)
202
  return
203
+ in_repo = hf_safe_name(in_repo)
204
+ size = local.stat().st_size
205
  for attempt in (1, 2):
206
  try:
207
  hf_api().upload_file(
208
  path_or_fileobj=str(local), path_in_repo=in_repo,
209
  repo_id=HF_REPO, repo_type="model",
210
  commit_message=f"t4_assets_v3: {name} (autosave)")
211
+ time.sleep(2)
212
+ if verify_remote(in_repo, size):
213
+ print(f"[v3] soft-uploaded {in_repo} (HEAD ok)", flush=True)
214
+ else:
215
+ print(f"[v3] soft upload {name}: HEAD-verify FAILED",
216
+ flush=True)
217
  return
218
  except Exception as e:
219
  print(f"[v3] soft upload {name} attempt {attempt}: {e}",
 
243
  sig = (f.stat().st_mtime, f.stat().st_size)
244
  if sig != last_sig:
245
  last_sig = sig
246
+ # v0.4.8: weights go as .pt (HF strips .safetensors);
247
+ # local file keeps its name, only the repo path maps.
248
  for fn, dest in [("adapter_model.safetensors",
249
  f"{WIP_REPO}/adapter_model.safetensors"),
250
  ("adapter_config.json",
251
+ f"{WIP_REPO}/adapter_config.json")]: # noqa: names mapped in upload_soft
252
  p = WIP_DIR / fn
253
  if p.exists():
254
  upload_soft(f"wip-{fn}", p, dest)
 
367
  sa = Path({str(OUT)!r}) / "stage_a_lora"
368
  if not (hl / "adapter_model.safetensors").exists():
369
  # fresh VM: pull the WIP LoRA that a crashed run pushed to HF
370
+ # (v0.4.8: it is stored as adapter_model.pt — HF strips .safetensors)
371
  if not (wip / "adapter_model.safetensors").exists():
372
  try:
373
  wip.mkdir(parents=True, exist_ok=True)
374
  p = hf_hub_download({HF_REPO!r},
375
+ "t4_assets_v3/checkpoints/hf_lora_wip/adapter_model.pt")
376
  shutil.copy(p, wip / "adapter_model.safetensors")
377
  try:
378
  c = hf_hub_download({HF_REPO!r},