CLI Companion

  • Hugging Face CLI
    • login
    • whoami
    • repo create
    • upload
    • download
    • lfs-enable-largefiles
    • scan-cache
    • delete-cache
  • Hapi CLI
    • new
    • start
    • build
    • test
    • plugin create
    • route add
  • Cloudflared
    • tunnel
    • tunnel run
    • tunnel list
    • tunnel delete
    • access
    • access tcp
    • update

    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.

    Basic Syntax

    bash
    huggingface-cli delete-cache [OPTIONS]

    Description

    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.

    Common Options

    * `--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.

    Usage Examples

    1. **Delete a specific model from the cache:**

    bash
    huggingface-cli delete-cache --repo-id bert-base-uncased

    This 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:**

    bash
    huggingface-cli delete-cache --repo-id mnist --repo-type dataset --force

    3. **Delete a specific file within a model's cache:**

    bash
    huggingface-cli delete-cache --repo-id google/flan-t5-small --filename config.json

    4. **Delete all files in the cache older than 90 days:**

    bash
    huggingface-cli delete-cache --scan-with-minimum-age 90

    5. **Delete old or orphaned files not linked to the current cache index:**

    bash
    huggingface-cli delete-cache --old-files

    6. **Delete a specific revision (e.g., a branch) of a model:**

    bash
    huggingface-cli delete-cache --repo-id distilbert-base-uncased --revision main

    7. **Delete the entire Hugging Face cache (use with extreme caution):**

    bash
    huggingface-cli delete-cache --all

    This will delete everything in your `~/.cache/huggingface/hub` directory. You will be prompted for confirmation unless `--force` is also used.

    Important Notes

    * 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.