Skip to content
fn

download

→pathlib.Path
download(url: str, sha256: str, name: str)

Download url to the local cache, verify SHA-256, return the path.

Idempotent — when the file already exists in cache and verifies, it is returned without re-fetching. A cached file that fails verification is treated as corrupt and re-downloaded.

Parameters

urlstr
Remote location of the checkpoint blob.
sha256str
Hex-encoded expected SHA-256 digest. Validated after download and on every cache hit.
name(str, keyword - only)
Short identifier (typically "<model>/<tag>") used to compose the cache subdirectory so different checkpoints never collide.

Returns

pathlib.Path

Local path of the verified checkpoint.

Raises

RuntimeError
If the freshly downloaded file fails SHA-256 verification.
OSError / urllib.error.URLError
From urllib.request.urlopen when the network is unreachable or the URL is invalid.
TimeoutError
If connection or an individual blocking read makes no progress for 60 seconds. This is not a total duration limit for large downloads.

Notes

Cache layout:

{cache_root}/{name}/{sha256[:8]}/{url-basename}

Download is atomic: bytes go to a temp file in the cache directory, the SHA is verified, then the temp file is renamed into place. On failure the temp file is removed; the cache directory is kept for the next attempt.

Used by 2