Support local RTX GPU execution and auto-detection
Browse files- run_colab_remaining_ablations.py +47 -21
run_colab_remaining_ablations.py
CHANGED
|
@@ -41,11 +41,17 @@ try:
|
|
| 41 |
HF_TOKEN = userdata.get("HF_TOKEN")
|
| 42 |
except Exception:
|
| 43 |
pass
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 46 |
print(f"Executing on: {DEVICE}")
|
| 47 |
-
if DEVICE.type
|
| 48 |
-
print("
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Set random seeds
|
| 51 |
SEED = 42
|
|
@@ -59,15 +65,31 @@ if torch.cuda.is_available():
|
|
| 59 |
# 2. DATASET DOWNLOAD / SETUP
|
| 60 |
# -------------------------------------------------------------
|
| 61 |
print("\nPreparing dataset...")
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
def find_chest_xray_root(base_dir):
|
| 73 |
for root, dirs, files in os.walk(base_dir):
|
|
@@ -424,15 +446,19 @@ print(df_results[["run_id", "test_acc_pct", "test_f1", "test_specificity_pct", "
|
|
| 424 |
try:
|
| 425 |
from huggingface_hub import HfApi
|
| 426 |
api = HfApi()
|
| 427 |
-
print("\nPushing results CSV to Hugging Face...")
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
except Exception as e:
|
| 437 |
print(f"Notice pushing to HF: {e}")
|
| 438 |
|
|
|
|
| 41 |
HF_TOKEN = userdata.get("HF_TOKEN")
|
| 42 |
except Exception:
|
| 43 |
pass
|
| 44 |
+
HF_REPOS = [
|
| 45 |
+
"unknownBrain/BioHCL-SSSM-Complete-Workspace",
|
| 46 |
+
"unknownBrain/BioHCL-SSSM-Pediatric-Pneumonia"
|
| 47 |
+
]
|
| 48 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 49 |
print(f"Executing on: {DEVICE}")
|
| 50 |
+
if DEVICE.type == "cuda":
|
| 51 |
+
print(f"GPU Model: {torch.cuda.get_device_name(0)}")
|
| 52 |
+
print(f"VRAM Available: {torch.cuda.get_device_properties(0).total_memory / 1e9:.2f} GB")
|
| 53 |
+
else:
|
| 54 |
+
print("WARNING: Running on CPU. For fast training, run on a CUDA-enabled machine (e.g. RTX 3080 Ti or Colab GPU).")
|
| 55 |
|
| 56 |
# Set random seeds
|
| 57 |
SEED = 42
|
|
|
|
| 65 |
# 2. DATASET DOWNLOAD / SETUP
|
| 66 |
# -------------------------------------------------------------
|
| 67 |
print("\nPreparing dataset...")
|
| 68 |
+
data_dir = None
|
| 69 |
+
DATA_DIR_ENV = os.environ.get("DATA_DIR", "")
|
| 70 |
+
if DATA_DIR_ENV and os.path.exists(DATA_DIR_ENV):
|
| 71 |
+
data_dir = DATA_DIR_ENV
|
| 72 |
+
print(f"Using local DATA_DIR from environment: {data_dir}")
|
| 73 |
+
elif os.path.exists("./chest_xray"):
|
| 74 |
+
data_dir = "./chest_xray"
|
| 75 |
+
print(f"Found local chest_xray folder: {data_dir}")
|
| 76 |
+
elif os.path.exists("../chest_xray"):
|
| 77 |
+
data_dir = "../chest_xray"
|
| 78 |
+
print(f"Found local ../chest_xray folder: {data_dir}")
|
| 79 |
+
else:
|
| 80 |
+
try:
|
| 81 |
+
import kagglehub
|
| 82 |
+
print("Downloading dataset via kagglehub (paultimothymooney/chest-xray-pneumonia)...")
|
| 83 |
+
data_dir = kagglehub.dataset_download("paultimothymooney/chest-xray-pneumonia")
|
| 84 |
+
print(f"Dataset downloaded from Kaggle: {data_dir}")
|
| 85 |
+
except Exception as e_kag:
|
| 86 |
+
print(f"Kagglehub fallback: {e_kag}")
|
| 87 |
+
try:
|
| 88 |
+
from huggingface_hub import snapshot_download
|
| 89 |
+
data_dir = snapshot_download(repo_id="unknownBrain/chest-xray-pneumonia", repo_type="dataset", token=HF_TOKEN if HF_TOKEN else None)
|
| 90 |
+
print(f"Dataset downloaded from Hugging Face: {data_dir}")
|
| 91 |
+
except Exception as e_hf:
|
| 92 |
+
raise RuntimeError(f"Could not automatically locate or download dataset. Please set DATA_DIR environment variable: {e_hf}")
|
| 93 |
|
| 94 |
def find_chest_xray_root(base_dir):
|
| 95 |
for root, dirs, files in os.walk(base_dir):
|
|
|
|
| 446 |
try:
|
| 447 |
from huggingface_hub import HfApi
|
| 448 |
api = HfApi()
|
| 449 |
+
print("\nPushing results CSV and checkpoints to Hugging Face...")
|
| 450 |
+
for repo in HF_REPOS:
|
| 451 |
+
try:
|
| 452 |
+
api.upload_file(
|
| 453 |
+
path_or_fileobj=csv_output_file,
|
| 454 |
+
path_in_repo=f"results/{csv_output_file}",
|
| 455 |
+
repo_id=repo,
|
| 456 |
+
repo_type="model",
|
| 457 |
+
token=HF_TOKEN if HF_TOKEN else None
|
| 458 |
+
)
|
| 459 |
+
print(f"✅ Pushed '{csv_output_file}' directly to {repo}!")
|
| 460 |
+
except Exception as e_repo:
|
| 461 |
+
print(f"Notice pushing to {repo}: {e_repo}")
|
| 462 |
except Exception as e:
|
| 463 |
print(f"Notice pushing to HF: {e}")
|
| 464 |
|