If you are experimenting with AI models locally—whether it's generating images with Stable Diffusion, exploring Diffusers, or running large language models (LLMs) like Llama or Mistral—you've likely noticed your disk space vanishing rapidly. This is often due to the Hugging Face cache.
Hugging Face has migrated its command-line interface to the new hf command (from the older huggingface-cli). This post explains how to use the modern hf tools to reclaim that precious storage space.
Quick Command
To see what's taking up space:
hf cache ls
To delete a specific model (e.g., model/runwayml/stable-diffusion-v1-5):
hf cache rm model/runwayml/stable-diffusion-v1-5
What Are Hugging Face Model Caches?
When you load a model using libraries like transformers, diffusers, or datasets, the library downloads the model files from the Hugging Face Hub.
Instead of downloading these large files every single time you run your script, Hugging Face stores them in a local cache. This speeds up subsequent loads significantly. However, because these models can be massive (often gigabytes in size), this cache can grow indefinitely.
Where Are They Stored?
By default, the cache is stored in your home directory.
- Linux/macOS:
~/.cache/huggingface/hub - Windows:
%USERPROFILE%\.cache\huggingface\hub
How to Check Your Cache Usage
With the new hf CLI, you use the cache ls command to list your cached models.
hf cache ls
Output Example:
ID REPO TYPE SIZE CREATED ACCESSED
model/runwayml/stable-diffusion-v1-5 model 4.2G 2 weeks ago 1 hour ago
model/stabilityai/stable-diffusion-xl model 6.9G 1 month ago 2 days ago
...
You can also sort by size to find the biggest offenders:
hf cache ls --sort size:desc
How to Remove Cached Models
To remove models, use the hf cache rm command followed by the ID of the repository you want to delete (as shown in the ls output).
hf cache rm model/runwayml/stable-diffusion-v1-5
You can also delete specific revisions (snapshots) if you don't want to remove the entire model history.
Legacy Interactive Mode
If you miss the interactive Text User Interface (TUI) from the older version, you might still be able to use the legacy command if it's available in your path, though hf is the recommended way forward.
huggingface-cli delete-cache
This opens the interactive menu where you can select models with arrow keys and delete them with Enter.
Conclusion
Regularly pruning your Hugging Face cache is essential for maintaining a healthy development environment. By using hf cache ls and hf cache rm, you can keep your favorite models ready to go while discarding the ones you no longer need.
