File size: 1,308 Bytes
15c46ce | 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 | """Fetch the pinned CUDA wheel in parallel and verify the official index digest."""
import html
import re
import urllib.request
from pathlib import Path
from range_download import download
ROOT = Path(__file__).resolve().parents[1]
NAME = "torch-1.13.1%2Bcu117-cp310-cp310-win_amd64.whl"
if __name__ == '__main__':
index = urllib.request.urlopen("https://download.pytorch.org/whl/cu117/torch/", timeout=30).read().decode()
pattern = r'href="([^"#]*torch-1\.13\.1%2Bcu117-cp310-cp310-win_amd64\.whl)#sha256=([a-f0-9]+)"'
match = re.search(pattern, index, re.I)
if not match:
raise RuntimeError("Pinned CUDA wheel not found in the official index")
url, digest = html.unescape(match.group(1)), match.group(2)
with urllib.request.urlopen(urllib.request.Request(url, method="HEAD"), timeout=30) as response:
size = int(response.headers['Content-Length'])
candidates = list((Path.home() / "AppData/Local/Temp").glob("pip-unpack-*/torch-1.13.1*cu117*win_amd64.whl"))
prefix = max(candidates, key=lambda p: p.stat().st_size) if candidates else None
target = ROOT / ".downloads" / NAME.replace("%2B", "+")
print("Trusted SHA256:", digest, "Size:", size, "Resume prefix:", prefix, flush=True)
download(url, target, size, sha256=digest, seed_prefix=prefix)
|