convitom commited on
Commit
d313d81
·
1 Parent(s): 1c5d410
scripts/cxrvlm_colab_train.ipynb CHANGED
@@ -65,6 +65,12 @@
65
  "# Supported: 'kaggle' | 'colab' | 'lightning' | 'gcp' | 'local'\n",
66
  "PLATFORM = 'colab'\n",
67
  "DATASET_NAME = 'MIMIC-CXR_resized' # 'MIMIC-CXR' | 'MIMIC-CXR_resized' | 'IU-Xray'\n",
 
 
 
 
 
 
68
  "\n",
69
  "assert PLATFORM in ('kaggle', 'colab', 'lightning', 'gcp', 'local')\n",
70
  "assert DATASET_NAME in ('MIMIC-CXR', 'MIMIC-CXR_resized', 'IU-Xray')\n",
@@ -337,6 +343,9 @@
337
  " def patched(self, *args, **kwargs):\n",
338
  " if 'allow_redirects' in kwargs:\n",
339
  " kwargs['follow_redirects'] = kwargs.pop('allow_redirects')\n",
 
 
 
340
  " return orig(self, *args, **kwargs)\n",
341
  " return patched\n",
342
  " for cls in (httpx.Client, httpx.AsyncClient):\n",
@@ -741,8 +750,8 @@
741
  "# 'merged' → 1 task (full report \"Findings: ...\\n\\nImpression: ...\")\n",
742
  "# 'split_cascade' → split, but impression's context = GT findings\n",
743
  "# image_mode : 'all_views_split' | 'frontal_only_split' | 'multi_image_merged'\n",
744
- "train_cfg.data.report_mode = 'split'\n",
745
- "train_cfg.data.image_mode = 'all_views_split'\n",
746
  "train_cfg.data.max_images_per_sample = 2 # only used in multi_image_merged\n",
747
  "\n",
748
  "# ── dataset-specific paths ──\n",
@@ -912,7 +921,8 @@
912
  "train_cfg.training.dataloader_persistent_workers = True\n",
913
  "train_cfg.training.optim = _profile['optim']\n",
914
  "# Ensure stage2 still uses the same per-run epoch count we want.\n",
915
- "train_cfg.stage2.num_epochs = 5\n",
 
916
  "\n",
917
  "model_cfg.llm.attn_implementation = _profile['attn_implementation']\n",
918
  "model_cfg.llm.gradient_checkpointing = _profile['gradient_checkpointing']\n",
@@ -976,8 +986,10 @@
976
  },
977
  {
978
  "cell_type": "code",
 
979
  "id": "cell-itc",
980
  "metadata": {},
 
981
  "source": [
982
  "# ── (Optional) Stage-1 ITC alignment toggle ─────────────────────────\n",
983
  "USE_ITC = False # True → contrastive Stage-1 (no Vicuna); False → original\n",
@@ -1029,9 +1041,7 @@
1029
  " print(OmegaConf.to_yaml(train_cfg.stage1))\n",
1030
  "else:\n",
1031
  " print('ITC disabled - Stage 1 uses the original LM-loss alignment.')"
1032
- ],
1033
- "execution_count": null,
1034
- "outputs": []
1035
  },
1036
  {
1037
  "cell_type": "markdown",
@@ -1201,8 +1211,6 @@
1201
  "outputs": [],
1202
  "source": [
1203
  "# Resume controller — set MODE once, run the train cell below.\n",
1204
- "MODE = 'fresh' # 'fresh' | 'resume'\n",
1205
- "EXPLICIT_RUN_ID = None # None | 'IU-Xray_run_5' (only matters when MODE='resume')\n",
1206
  "\n",
1207
  "assert MODE in ('fresh', 'resume'), \"MODE must be 'fresh' or 'resume'\"\n",
1208
  "if MODE == 'resume' and EXPLICIT_RUN_ID:\n",
 
65
  "# Supported: 'kaggle' | 'colab' | 'lightning' | 'gcp' | 'local'\n",
66
  "PLATFORM = 'colab'\n",
67
  "DATASET_NAME = 'MIMIC-CXR_resized' # 'MIMIC-CXR' | 'MIMIC-CXR_resized' | 'IU-Xray'\n",
68
+ "REPORT_MODE = 'split_cascade' # 'split' | 'merged' | 'split_cascade'\n",
69
+ "IMAGE_MODE = 'all_views_split' # 'all_views_split' | 'frontal_only_split' | 'multi_image_merged'\n",
70
+ "S1_EPOCHS = 2\n",
71
+ "S2_EPOCHS = 5\n",
72
+ "MODE = 'fresh' # 'fresh' | 'resume'\n",
73
+ "EXPLICIT_RUN_ID = None # None | 'IU-Xray_run_5' (only matters when MODE='resume')\n",
74
  "\n",
75
  "assert PLATFORM in ('kaggle', 'colab', 'lightning', 'gcp', 'local')\n",
76
  "assert DATASET_NAME in ('MIMIC-CXR', 'MIMIC-CXR_resized', 'IU-Xray')\n",
 
343
  " def patched(self, *args, **kwargs):\n",
344
  " if 'allow_redirects' in kwargs:\n",
345
  " kwargs['follow_redirects'] = kwargs.pop('allow_redirects')\n",
346
+ " # httpx 0.28+ removed per-request `proxies=` too — transformers ≤4.49\n",
347
+ " # still passes it via huggingface_hub.has_file → drop it silently.\n",
348
+ " kwargs.pop('proxies', None)\n",
349
  " return orig(self, *args, **kwargs)\n",
350
  " return patched\n",
351
  " for cls in (httpx.Client, httpx.AsyncClient):\n",
 
750
  "# 'merged' → 1 task (full report \"Findings: ...\\n\\nImpression: ...\")\n",
751
  "# 'split_cascade' → split, but impression's context = GT findings\n",
752
  "# image_mode : 'all_views_split' | 'frontal_only_split' | 'multi_image_merged'\n",
753
+ "train_cfg.data.report_mode = REPORT_MODE\n",
754
+ "train_cfg.data.image_mode = IMAGE_MODE\n",
755
  "train_cfg.data.max_images_per_sample = 2 # only used in multi_image_merged\n",
756
  "\n",
757
  "# ── dataset-specific paths ──\n",
 
921
  "train_cfg.training.dataloader_persistent_workers = True\n",
922
  "train_cfg.training.optim = _profile['optim']\n",
923
  "# Ensure stage2 still uses the same per-run epoch count we want.\n",
924
+ "train_cfg.stage1.num_epochs = S1_EPOCHS\n",
925
+ "train_cfg.stage2.num_epochs = S2_EPOCHS\n",
926
  "\n",
927
  "model_cfg.llm.attn_implementation = _profile['attn_implementation']\n",
928
  "model_cfg.llm.gradient_checkpointing = _profile['gradient_checkpointing']\n",
 
986
  },
987
  {
988
  "cell_type": "code",
989
+ "execution_count": null,
990
  "id": "cell-itc",
991
  "metadata": {},
992
+ "outputs": [],
993
  "source": [
994
  "# ── (Optional) Stage-1 ITC alignment toggle ─────────────────────────\n",
995
  "USE_ITC = False # True → contrastive Stage-1 (no Vicuna); False → original\n",
 
1041
  " print(OmegaConf.to_yaml(train_cfg.stage1))\n",
1042
  "else:\n",
1043
  " print('ITC disabled - Stage 1 uses the original LM-loss alignment.')"
1044
+ ]
 
 
1045
  },
1046
  {
1047
  "cell_type": "markdown",
 
1211
  "outputs": [],
1212
  "source": [
1213
  "# Resume controller — set MODE once, run the train cell below.\n",
 
 
1214
  "\n",
1215
  "assert MODE in ('fresh', 'resume'), \"MODE must be 'fresh' or 'resume'\"\n",
1216
  "if MODE == 'resume' and EXPLICIT_RUN_ID:\n",
utils/_httpx_compat.py CHANGED
@@ -45,6 +45,12 @@ def apply() -> bool:
45
  # follow_redirects is the modern equivalent. If both are
46
  # somehow set, allow_redirects wins (matches old behaviour).
47
  kwargs["follow_redirects"] = kwargs.pop("allow_redirects")
 
 
 
 
 
 
48
  return orig(self, *args, **kwargs)
49
  return patched
50
 
 
45
  # follow_redirects is the modern equivalent. If both are
46
  # somehow set, allow_redirects wins (matches old behaviour).
47
  kwargs["follow_redirects"] = kwargs.pop("allow_redirects")
48
+ # httpx 0.28 also removed per-request `proxies=`. Some
49
+ # transformers / huggingface_hub paths still pass it (e.g.
50
+ # transformers.utils.hub.has_file → Client.head(proxies=...)),
51
+ # raising TypeError. Drop it silently — httpx 0.28 picks up
52
+ # proxies from the Client/transport instead.
53
+ kwargs.pop("proxies", None)
54
  return orig(self, *args, **kwargs)
55
  return patched
56