hfutils.repository.clone
This module provides functionality to clone Hugging Face Hub repositories using Git.
It includes a function to clone a repository from Hugging Face Hub to a local directory, with options for authentication, repository type, revision, and other Git clone parameters.
hf_hub_clone
- hfutils.repository.clone.hf_hub_clone(repo_id: str, dst_dir: str, repo_type: Literal['dataset', 'model', 'space'] = 'dataset', revision: str = 'main', endpoint: str | None = None, hf_token: str | None = None, silent: bool = False, no_lfs: bool = False, max_depth: int | None = None)[source]
Clone a repository from Hugging Face Hub.
- Parameters:
repo_id (str) – The ID of the repository to clone.
dst_dir (str) – The local directory to clone the repository into.
repo_type (RepoTypeTyping) – The type of the repository (‘dataset’, ‘model’, or ‘space’). Defaults to ‘dataset’.
revision (str) – The specific revision to clone. Defaults to ‘main’.
endpoint (Optional[str]) – The Hugging Face Hub endpoint. If None, uses the default endpoint.
hf_token (Optional[str]) – The Hugging Face authentication token. If None, attempts to use stored credentials.
silent (bool) – If True, suppresses command output. Defaults to False.
no_lfs (bool) – If True, skips downloading of LFS files. Defaults to False.
max_depth (Optional[int]) – The maximum number of commits to fetch. If None, fetches all commits.
- Raises:
subprocess.CalledProcessError – If the Git clone command fails.
- Usage:
>>> hf_hub_clone('username/repo', '/path/to/local/dir', repo_type='model', revision='v1.0')