File size: 1,490 Bytes
46e547f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""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)