rag-assignment-processed-bm25 / evaluation /scripts /prepare_colab_artifacts.py
EllaNAM's picture
Add editable evaluation notebooks and their Python source
46e547f verified
Raw History Blame Contribute Delete
1.49 kB
"""Verify the local GPU or build the clean, deduplicated assignment index."""
import argparse
from pathlib import Path
from subprocess import run
import sys
DATA_REVISION = "283fd0013829a405162119cba5a40f53513ba2bb"
def verify_gpu(device):
import torch
available = torch.backends.mps.is_available() if device == "mps" else torch.cuda.is_available()
if not available:
raise RuntimeError(f"GPU device {device} is not accessible")
if device == "cuda":
probe = torch.ones((16, 16), device=device, dtype=torch.float16)
if (probe @ probe)[0, 0].item() != 16:
raise RuntimeError("CUDA FP16 verification failed")
cc = torch.cuda.get_device_capability()
print(f"GPU: {torch.cuda.get_device_name()} (sm_{cc[0]}{cc[1]}), PyTorch CUDA {torch.version.cuda}", flush=True)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--device", choices=["cuda", "mps"], required=True)
parser.add_argument("--verify-gpu-only", action="store_true")
parser.add_argument("--data", type=Path)
parser.add_argument("--output", type=Path)
args = parser.parse_args()
verify_gpu(args.device)
if not args.verify_gpu_only:
if not args.data or not args.output:
parser.error("--data and --output are required")
run([sys.executable, str(Path(__file__).with_name("build_clean_bm25.py")), str(args.output), "--data", str(args.data)], check=True)