What is ~/.cache/huggingface, and is it safe to delete?

The ~/.cache/huggingface folder holds AI models and datasets downloaded by Python tools such as transformers, and it is safe to clear because they download again when a script needs them.

Shiva ChandraMaker of Clean House · · 2 min read
Short answer

~/.cache/huggingface is where Hugging Face libraries cache AI models and datasets that your Python scripts downloaded. It is safe to clear because everything re-downloads from the Hub when a script needs it. Expect large downloads, and delete selectively with huggingface-cli delete-cache to keep the models you use.

Path
~/.cache/huggingface
What it is
Downloaded AI models, datasets and tokenizers from the Hugging Face Hub
Typical size
One model is often several gigabytes, so this folder is commonly tens of gigabytes or more
Made by
Hugging Face libraries (transformers, diffusers, huggingface_hub)
Safe to delete?
Look first (it all re-downloads, but models can be many gigabytes and slow to fetch again)
Comes back?
Yes, they download again the next time a script uses them (large downloads, and not at all offline)

What is in this folder?

The model files live in ~/.cache/huggingface/hub, in folders named like models--org--name and datasets--org--name. Each holds several revisions, with the large weight files kept once and linked from snapshots. Hugging Face's documentation says the default location can be changed with the HF_HOME or HF_HUB_CACHE environment variables.

Models that you downloaded by hand into another folder are not in this cache.

Is it safe to delete?

Yes, in the sense that nothing here is unique: the Hub still has it. The trade-off is download size. A model that took five minutes to pull will take five minutes again, and if you are offline or the model was removed from the Hub, you cannot get it back.

Models you fine-tuned and saved to the cache only (not pushed or saved elsewhere) exist only here. Check before deleting.

How do I clear it by hand?

  1. Stop any Python script or notebook that is using a model.
  2. Use the interactive cleaner to pick what to delete.
  3. Or delete the whole cache if you want it all back.
huggingface-cli delete-cache
rm -rf ~/.cache/huggingface/hub
Newer huggingface_hub releases replace huggingface-cli with an hf command that has a cache subcommand. Run hf cache --help if the first command is not found.

How do I stop it growing?

Delete models you tried once, and set HF_HOME to an external drive if you want the cache off your Mac.

How Clean House handles it

Clean House recognizes the Hugging Face cache and labels each model or dataset by its name, with the plain note that it downloads again next time it is needed. It groups them under AI models so you can see which are largest. Anything you clear goes to the Trash, and Recently Cleared can put it back.

Questions

Is it safe to delete ~/.cache/huggingface?

Yes, everything re-downloads from the Hub. Models you saved only in the cache, such as fine-tuned ones, would be lost.

How do I delete cached Hugging Face models?

Run huggingface-cli delete-cache and choose which to remove, or delete the folder.

Where does Hugging Face store models?

By default in ~/.cache/huggingface/hub. HF_HOME changes it.

Sources

  1. Hugging Face Docs: Manage huggingface_hub cache-system
  2. Hugging Face Docs: Command Line Interface