Skip to main content

How to Delete a Model from Your Hugging Face Cache with hf cache rm

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Models downloaded from the Hugging Face Hub stay on your disk until you delete them, and a few large ones can fill it up. hf cache rm deletes a model from the cache safely: it shows what it will delete and asks first. This guide removes one model with huggingface_hub 2.5.0.

Syntax​

Syntax
hf cache rm <repo-type>/<repo-id> [--dry-run] [-y]
PartWhat it means
<repo-type>/<repo-id>What to delete, written as hf cache ls shows it, such as model/openai-community/gpt2. You can list several
--dry-runShows what would be deleted and deletes nothing
-yDeletes without asking. Leave it out to be asked first

The command's help text describes it: "Remove cached repositories, revisions or files." A target can also be a single revision, by its commit hash.

The Example​

A small project downloads one file from each of two models, then deletes one of them from the cache.

Prerequisites​

  • uv. This guide uses uv 0.13.10 with Python 3.15.2.

Step 1: Create a Project and Fill the Cache​

Terminal
uv init --python 3.15 cache-cleanup
cd cache-cleanup
uv add huggingface_hub
uv run hf download openai-community/gpt2 config.json
uv run hf download google-t5/t5-small config.json

uv add huggingface_hub installed version 2.5.0 with its hf command, and the two downloads each saved a config.json in the cache.

Step 2: See What's in the Cache​

Terminal
uv run hf cache ls
Output
ID SIZE LAST_ACCESSED LAST_MODIFIED REFS
--------------------------- ----- ----------------- ----------------- ----
model/google-t5/t5-small 1.2K a few seconds ago a few seconds ago main
model/openai-community/gpt2 665.0 a few seconds ago a few seconds ago main

Found 2 repo(s) for a total of 2 revision(s) and 1.9K on disk.

The terminal after uv run hf cache ls: google-t5/t5-small at 1.2K and openai-community/gpt2 at 665.0, then Found 2 repo(s) for a total of 2 revision(s) and 1.9K on disk.

The ID column is exactly what hf cache rm expects.

Step 3: Preview the Deletion​

Terminal
uv run hf cache rm model/openai-community/gpt2 --dry-run
Output
About to delete 1 repo(s) totalling 665.0.
- model/openai-community/gpt2 (entire repo)
✓ Dry run: no files were deleted.
dry_run: True
repos: 1
revisions: 1
size: 665.0

The terminal after the dry run: About to delete 1 repo(s) totalling 665.0, model/openai-community/gpt2 (entire repo), then Dry run: no files were deleted.

Nothing was deleted. The preview shows the whole gpt2 repository would go, and how much space that frees.

Step 4: Delete It​

Run the same command without --dry-run. It asks for confirmation; type y and press Enter:

Terminal
uv run hf cache rm model/openai-community/gpt2
Output
About to delete 1 repo(s) totalling 665.0.
- model/openai-community/gpt2 (entire repo)
Proceed with deletion? [y/N]: y
✓ Deleted 1 repo(s) and 1 revision(s); freed 665.0.
repos_deleted: 1
revisions_deleted: 1
freed: 665.0

The terminal after uv run hf cache rm model/openai-community/gpt2: the list of what will be deleted, the question Proceed with deletion? [y/N] answered with y, then Deleted 1 repo(s) and 1 revision(s); freed 665.0.

The [y/N] means No is the answer if you just press Enter, so nothing is deleted by accident.

Step 5: Check the Cache Again​

Terminal
uv run hf cache ls
Output
ID SIZE LAST_ACCESSED LAST_MODIFIED REFS
------------------------ ---- ----------------- ----------------- ----
model/google-t5/t5-small 1.2K a few seconds ago a few seconds ago main

Found 1 repo(s) for a total of 1 revision(s) and 1.2K on disk.

The terminal after uv run hf cache ls: only google-t5/t5-small is left, with 1 repo and 1.2K on disk.

Only t5-small is left. If a program needs gpt2 again, it downloads it again. The commands work unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Leaving out the repository type: hf cache rm openai-community/gpt2The target doesn't match how the cache names itCopy the ID from hf cache ls, with its model/ prefix
Adding -y while you're still unsureIt deletes at once, without the questionRun --dry-run first
Deleting a model a running program is usingThe program may fail, or download it againStop the program first

FAQ​

Can I delete everything at once?​

hf cache ls -q prints only the IDs, and the command-line guide shows them passed to hf cache rm in one go. List first, so you know what you're about to remove.

Does deleting from the cache delete the model from the Hub?​

No. It only deletes your local copy. The model stays on the Hub, and you can download it again at any time.

Conclusion​

hf cache rm model/openai-community/gpt2 showed what it would delete, asked before deleting, and freed the space. --dry-run previewed it first, and hf cache ls confirmed only t5-small was left.

Additional Resources​