convitom commited on
Commit
7255a88
·
1 Parent(s): 6344cc7
Files changed (1) hide show
  1. scripts/gcp_entrypoint.py +49 -1
scripts/gcp_entrypoint.py CHANGED
@@ -20,9 +20,15 @@ Optional env vars (defaults shown):
20
  S1_EPOCHS = 2
21
  S2_EPOCHS = 7
22
  MODE = resume # 'fresh' | 'resume'
23
- EXPLICIT_RUN_ID = '' # only matters when MODE=resume
24
  HF_RUNS_REPO = hieu3636/cxr-vlm-runs
25
  WORK = /workspace
 
 
 
 
 
 
26
  """
27
 
28
  from __future__ import annotations
@@ -63,6 +69,8 @@ MODE = env("MODE", "resume")
63
  EXPLICIT_RUN_ID = env("EXPLICIT_RUN_ID", "")
64
  HF_RUNS_REPO = env("HF_RUNS_REPO", "hieu3636/cxr-vlm-runs")
65
  WORK = Path(env("WORK", "/workspace"))
 
 
66
 
67
  assert DATASET_NAME in ("IU-Xray", "MIMIC-CXR", "MIMIC-CXR_resized"), DATASET_NAME
68
  assert MODE in ("fresh", "resume"), MODE
@@ -297,6 +305,46 @@ train_cfg.hf_hub.token_env = "HF_TOKEN"
297
  train_cfg.hf_hub.private = True
298
  train_cfg.hf_hub.run_state_file = str(CKPT_ROOT / "run_id.txt")
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  OmegaConf.save(train_cfg, train_cfg_path)
301
  OmegaConf.save(model_cfg, model_cfg_path)
302
  print("[gcp_entrypoint] configs patched.")
 
20
  S1_EPOCHS = 2
21
  S2_EPOCHS = 7
22
  MODE = resume # 'fresh' | 'resume'
23
+ EXPLICIT_RUN_ID = '' # passes through as --run_id for both modes
24
  HF_RUNS_REPO = hieu3636/cxr-vlm-runs
25
  WORK = /workspace
26
+ USE_ITC = true # BLIP-2-style Stage 1 contrastive alignment.
27
+ # When true, downloads CXR-BERT text-embed cache from
28
+ # {HF_USER}/cxr-vlm-data/cxr_bert_text_embeddings/.
29
+ # Must have run scripts/precompute_cxrbert_embeddings.ipynb
30
+ # first. Set 'false' to use original LM-loss Stage 1.
31
+ ITC_TEMPERATURE = 0.07
32
  """
33
 
34
  from __future__ import annotations
 
69
  EXPLICIT_RUN_ID = env("EXPLICIT_RUN_ID", "")
70
  HF_RUNS_REPO = env("HF_RUNS_REPO", "hieu3636/cxr-vlm-runs")
71
  WORK = Path(env("WORK", "/workspace"))
72
+ USE_ITC = env("USE_ITC", "true").lower() in ("1", "true", "yes")
73
+ ITC_TEMPERATURE = float(env("ITC_TEMPERATURE", "0.07"))
74
 
75
  assert DATASET_NAME in ("IU-Xray", "MIMIC-CXR", "MIMIC-CXR_resized"), DATASET_NAME
76
  assert MODE in ("fresh", "resume"), MODE
 
305
  train_cfg.hf_hub.private = True
306
  train_cfg.hf_hub.run_state_file = str(CKPT_ROOT / "run_id.txt")
307
 
308
+ # ── Stage 1 ITC toggle (mirrors notebook cell-itc) ────────────────────────────
309
+ # Repo defaults to itc.enabled=true with text_embed_cache=null which causes
310
+ # train.py to raise at Stage 1 start. Either supply the precomputed cache OR
311
+ # explicitly disable ITC (falls back to RaDialog-style LM-loss alignment).
312
+ _itc_cache_by_ds = {
313
+ "IU-Xray": "cxrbert_text_embeds_iu_xray.pt",
314
+ "MIMIC-CXR_resized": "cxrbert_text_embeds_mimic_resized.pt",
315
+ "MIMIC-CXR": "cxrbert_text_embeds_mimic.pt",
316
+ }
317
+
318
+ if USE_ITC:
319
+ cache_filename = _itc_cache_by_ds[DATASET_NAME]
320
+ print(f"[gcp_entrypoint] downloading ITC cache {cache_filename} …")
321
+ cache_path = hf_hub_download(
322
+ repo_id=f"{HF_USER}/cxr-vlm-data",
323
+ repo_type="dataset",
324
+ filename=f"cxr_bert_text_embeddings/{cache_filename}",
325
+ token=HF_TOKEN,
326
+ )
327
+ print(f"[gcp_entrypoint] ITC cache → {cache_path}")
328
+
329
+ # Stage-1 contrastive batch (Vicuna not loaded → can go much bigger)
330
+ if _vram_gb >= 35: itc_bs = 256
331
+ elif _vram_gb >= 22: itc_bs = 192
332
+ elif _vram_gb >= 14: itc_bs = 96
333
+ else: itc_bs = 32
334
+
335
+ train_cfg.stage1.itc.enabled = True
336
+ train_cfg.stage1.itc.text_embed_cache = cache_path
337
+ train_cfg.stage1.itc.temperature = ITC_TEMPERATURE
338
+ train_cfg.stage1.itc.fallback_to_impression = True
339
+ train_cfg.stage1.itc.per_device_train_batch_size = itc_bs
340
+ train_cfg.stage1.itc.per_device_eval_batch_size = itc_bs
341
+ train_cfg.stage1.itc.gradient_accumulation_steps = 1
342
+ print(f"[gcp_entrypoint] ITC ENABLED batch={itc_bs} temp={ITC_TEMPERATURE}")
343
+ else:
344
+ # Force-disable so train.py uses original LM-loss Stage 1.
345
+ train_cfg.stage1.itc.enabled = False
346
+ print("[gcp_entrypoint] ITC DISABLED — Stage 1 uses LM-loss alignment.")
347
+
348
  OmegaConf.save(train_cfg, train_cfg_path)
349
  OmegaConf.save(model_cfg, model_cfg_path)
350
  print("[gcp_entrypoint] configs patched.")