English
Content on This Page

Downloading Files

The openMind Hub Client controls file download paths through blocklist and trustlist. The absolute path of a file cannot start with a path in the blocklist (except the default cache path ~/.cache/openmind) and must be in the trustlist. The blocklist includes ["/etc", "/var", "/bin", "/boot", "/lib", "~/."], and the trustlist is defaulted as the user's home directory ~/ in Linux and drives D, E, and F in Windows. You can configure the environment variable HUB_WHITE_LIST_PATHS (separated by commas) to configure the trustlist. In addition, the priority of the blocklist permission is higher than that of the trustlist permission.

Downloading a Single File

The om_hub_download function can be used to download files from a remote repository and cache the files locally. It is the most common method for downloading files. The following is an example. Obtain the detailed parameters from the API document.

python
from openmind_hub import om_hub_download

om_hub_download(
    repo_id="PyTorch-NPU/t5_small",
    repo_type=None,
    filename="config.json",
    local_dir="demo/t5_small",
    revision="main",
)
  • repo_id (required): target repository.
  • repo_type: repository type, which can be "model", "dataset", or "space". Default value: None, which indicates the model.
  • filename (required): name of the file to be downloaded.
  • local_dir (optional): local path to which files are downloaded. By default, the symlink file is created only in the cache.
  • revision (optional): branch name.

om_hub_download returns a filepath pointer to the local cache. Do not modify it to avoid cache damage. For details, see Cache.

Downloading an Entire Repository

snapshot_download can download an entire repository at a time. The following is an example.

python
from openmind_hub import snapshot_download
snapshot_download(repo_id="PyTorch-NPU/t5_small")
  • repo_id (required): target repository.
  • repo_type: repository type, which can be "model", "dataset", or "space". Default value: None, which indicates the model.
  • local_dir (optional): local path to which a file is downloaded.
  • revision (optional): branch name.

Similar to uploading a directory, you can choose to download only or ignore a certain type of files. The following is an example.

python
from openmind_hub import snapshot_download
snapshot_download(
    repo_id="PyTorch-NPU/t5_small",
    local_dir="demo/t5_small",
    allow_patterns="*.json",
)
  • allow_patterns: downloads only files of a certain type. For example, allow_patterns="*.json" indicates that only .json files are downloaded.
  • ignore_patterns: ignores files of a certain type during download. For example, ignore_patterns=["*.bin", "*.safetensors"] indicates that .bin and .safetensors files are ignored during download.