The `delete-cache` command in the Hugging Face CLI (`huggingface-cli`) is used to manage and remove cached files and directories downloaded by the `huggingface_hub` library. This is particularly useful for freeing up disk space or ensuring that you are always using the latest version of models, datasets, or other files.
huggingface-cli delete-cache [OPTIONS]This command allows you to inspect and selectively delete portions of your Hugging Face cache. The cache stores models, datasets, tokenizers, and other files downloaded from the Hugging Face Hub, typically located at `~/.cache/huggingface/hub` by default. You can delete specific files, entire repositories, or prune outdated entries.
* `--dir <PATH>`: Specify the cache directory to inspect/delete. By default, it's `~/.cache/huggingface/hub`.
* `-r, --repo-id <REPO_ID>`: Delete the cache for a specific repository (e.g., `bert-base-uncased`).
* `-k, --repo-type <REPO_TYPE>`: Specify the type of repository (`model`, `dataset`, `space`). Useful when a `repo_id` might exist across different types.
* `-f, --filename <FILENAME>`: Delete a specific file within a repository's cache. Requires `--repo-id`.
* `-e, --etag <ETAG_SHA256>`: Delete a file only if its ETag matches the provided SHA256 hash. Requires `--repo-id` and `--filename`.
* `--revision <REVISION>`: Specify a particular branch, tag, or commit hash to delete from the cache. Requires `--repo-id`.
* `--force`: Skip the confirmation prompt when deleting files or directories.
* `--all`: Delete the entire Hugging Face cache. **Use with extreme caution.**
* `--old-files`: Delete all files that are not linked to any entry in the cache index. This can clean up orphaned files.
* `--scan-with-minimum-age <DAYS>`: Delete all files that are older than a given number of days. (e.g., `30` for files older than 30 days).
* `-v, --verbose`: Increase verbosity of the output.
1. **Delete a specific model from the cache:**
huggingface-cli delete-cache --repo-id bert-base-uncasedThis will prompt you for confirmation before deleting all cached files related to `bert-base-uncased`.
2. **Delete a specific dataset from the cache without confirmation:**
huggingface-cli delete-cache --repo-id mnist --repo-type dataset --force3. **Delete a specific file within a model's cache:**
huggingface-cli delete-cache --repo-id google/flan-t5-small --filename config.json4. **Delete all files in the cache older than 90 days:**
huggingface-cli delete-cache --scan-with-minimum-age 905. **Delete old or orphaned files not linked to the current cache index:**
huggingface-cli delete-cache --old-files6. **Delete a specific revision (e.g., a branch) of a model:**
huggingface-cli delete-cache --repo-id distilbert-base-uncased --revision main7. **Delete the entire Hugging Face cache (use with extreme caution):**
huggingface-cli delete-cache --allThis will delete everything in your `~/.cache/huggingface/hub` directory. You will be prompted for confirmation unless `--force` is also used.
* Always be careful when using `delete-cache`, especially with `--all` or `--force`, as deleted files cannot be recovered easily.
* After deleting, the next time you try to load a model or dataset that was removed, it will be re-downloaded from the Hugging Face Hub.
* You can use `huggingface-cli scan-cache` to inspect the contents of your cache before deciding what to delete.