The `huggingface-cli delete-cache` command is used to remove the Hugging Face cache directory, which stores downloaded models, datasets, tokenizers, and other files from the Hugging Face Hub. This is useful for freeing up disk space or resolving issues with corrupted cache entries.
huggingface-cli delete-cache [OPTIONS]* `--force`: (Optional) Delete the cache without prompting for confirmation. Use with caution.
* `--dir <path>`: (Optional) Specify a different cache directory to delete instead of the default one. The default cache directory is determined by the `HF_HOME` environment variable, which usually defaults to `~/.cache/huggingface`.
1. **Delete the default Hugging Face cache with confirmation:**
This is the safest way to delete the cache. The CLI will ask for confirmation before proceeding.
huggingface-cli delete-cache2. **Delete the default Hugging Face cache without confirmation (forcefully):**
This command will immediately delete the cache without any interactive prompt. Be careful when using `--force` as it bypasses safety checks.
huggingface-cli delete-cache --force3. **Delete a specific custom Hugging Face cache directory:**
If you have configured `HF_HOME` to point to a different location or have a specific cache you want to clear, you can specify its path.
huggingface-cli delete-cache --dir /mnt/data/my_hf_cacheWhen you download models, datasets, or other artifacts using Hugging Face libraries (like `transformers` or `datasets`), they are stored locally in a cache directory to avoid re-downloading them in the future. Over time, this cache can grow significantly, consuming a lot of disk space. It can also sometimes become corrupted, leading to unexpected errors.
The `huggingface-cli delete-cache` command provides a clean way to manage this cache. It targets the main cache directory, which typically contains subdirectories like `hub` (for models, tokenizers, etc.) and `datasets` (for downloaded dataset files).
* **Confirmation Prompt:** By default, the command includes a confirmation step (`Are you sure you want to delete the Hugging Face cache directory [...]? [y/N]`) to prevent accidental deletion. This is crucial as deleting the cache means you'll have to re-download all previously cached files if you need them again.
* **`--force` Option:** Use this when you are absolutely sure you want to clear the cache without interruption, for example, in automated scripts or when you're confident in your action.
* **`--dir` Option:** This is useful for advanced users who manage multiple cache locations or need to clear a specific cache that isn't the default one. If not specified, the command uses the default cache path, which is usually `~/.cache/huggingface/` or the path specified by the `HF_HOME` environment variable.
After running this command, the next time you try to load a model or dataset, the Hugging Face libraries will download the necessary files again.