Skip to content

snapshot

snapshot #

snapshot — a model's weights, downloaded once from Hugging Face into the scratch.

  1. Key. The Weights value is the whole cache key, so a snapshot is fetched once per pinned commit and then shared, pinned and evicted like any other object; a driver never touches ~/.cache/huggingface.
  2. Download. huggingface_hub.snapshot_download fills a fresh ManagedDir with the repository's files at that revision.
  3. Hand over. The directory is the value: a driver receives it as its --weights argument.

snapshot(weights) #

The files of weights' repository at its commit.

files = cgr.depth.snapshot(cgr.depth.DA3_LARGE.weights)

Parameters:

Name Type Description Default
weights Weights

The repository and commit to download.

required

Returns:

Type Description
ManagedDir

The directory holding the repository's files.

Raises:

Type Description
HfHubHTTPError

If the repository or revision cannot be fetched.

Source code in capturegraph-recipes/capturegraph_recipes/depth/models/snapshot.py
@cg.pure_function("depth.snapshot/1")
def snapshot(weights: Weights) -> cg.ManagedDir:
    """The files of ``weights``' repository at its commit.

    ```python
    files = cgr.depth.snapshot(cgr.depth.DA3_LARGE.weights)
    ```

    Args:
        weights: The repository and commit to download.

    Returns:
        The directory holding the repository's files.

    Raises:
        huggingface_hub.errors.HfHubHTTPError: If the repository or revision
            cannot be fetched.
    """
    import huggingface_hub

    work = cg.ManagedDir.new()
    huggingface_hub.snapshot_download(weights.repo_id, revision=weights.revision, local_dir=work)
    shutil.rmtree(work / HUB_METADATA, ignore_errors=True)
    cg.logging.info(
        "Downloaded snapshot",
        repo=weights.repo_id,
        revision=weights.revision,
        bytes=_size(work),
    )
    return work