specsr.checkpoints¶
On-demand model weight fetching from the Hugging Face Hub.
Weights are not stored in the git repository. They live in a Hub model repo and are downloaded (and cached) the first time they are requested:
from specsr.checkpoints import get_checkpoint
path = get_checkpoint("sr1")
Set SPECSR_CHECKPOINT_DIR to load from a local directory instead — useful
during training, offline runs, or CI.
Functions
|
Return a local directory holding the named archival chain. |
|
Where the named archive lives, or would live. |
Archive directory names understood by |
|
Logical checkpoint names understood by |
|
|
Materialise the archive containing |
|
Return a local path to the requested checkpoint, downloading if needed. |
|
|
- specsr.checkpoints.get_checkpoint(name, repo_id=None, revision=None)[source]¶
Return a local path to the requested checkpoint, downloading if needed.
- Parameters:
name (str) – Logical name, e.g.
"sr1". Seeavailable_checkpoints().repo_id (str | None) – Override the Hub repo. Defaults to
SPECSR_CHECKPOINT_REPOorDEFAULT_REPO.revision (str | None) – Branch, tag or commit. Defaults to
SPECSR_CHECKPOINT_REVISIONorDEFAULT_REVISION.
- Return type:
- specsr.checkpoints.available_checkpoints()[source]¶
Logical checkpoint names understood by
get_checkpoint().
- specsr.checkpoints.archive_dir(name, repo_id=None)[source]¶
Return a local directory holding the named archival chain.
A checkout that still has
checkpoints/<name>/gets that directory untouched, so restoring the files by hand keeps working and costs no network. Otherwise the chain is fetched from the Hub and assembled under the cache directory as symlinks into the Hub cache – the files are not copied, so a second archive sharing a blob costs nothing.Raises
KeyErrorfor an unknown name and lets the download error propagate. Usetry_archive()where a missing chain should be a skip rather than a failure.
- specsr.checkpoints.archive_path(name)[source]¶
Where the named archive lives, or would live. Never touches the network.
Exists because the archive paths are used as default argument values –
load_pipeline(sr1_ckpt=BASELINE / "best_superres_model.pth")and several argparse defaults – which are evaluated at import. Downloading there would meanimport specsr.evaluationreaches for the Hub, so resolution and materialisation are kept apart: this names the location,archive_dir()fills it in, andensure_archive()bridges the two at the point of use.
- specsr.checkpoints.ensure_archive(path)[source]¶
Materialise the archive containing
path, if it is not there yet.Call it immediately before opening a file whose default came from
archive_path(). An existing path is returned untouched, so this costs nothing in a checkout that still has the directories, and a path belonging to no known archive is returned untouched too – an explicit--sr1-ckpt /some/run/best_superres_model.pthmust not be second-guessed.- Return type:
- specsr.checkpoints.try_archive(name, repo_id=None)[source]¶
archive_dir(), returningNoneinstead of raising.For test guards and figure scripts, where “the weights are not reachable” means skip, not crash. Offline, unauthenticated and missing-file cases all land here.
- specsr.checkpoints.available_archives()[source]¶
Archive directory names understood by
archive_dir().