Skip to content

[CLI] Support hf:// URIs in cache rm#4235

Merged
Wauplin merged 2 commits into
huggingface:mainfrom
abhinavgautam01:fix/cache-rm-hf-uri
May 19, 2026
Merged

[CLI] Support hf:// URIs in cache rm#4235
Wauplin merged 2 commits into
huggingface:mainfrom
abhinavgautam01:fix/cache-rm-hf-uri

Conversation

@abhinavgautam01

@abhinavgautam01 abhinavgautam01 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Example:

hf cache rm hf://models/openai-community/gpt2 --dry-run

For now this only supports repo-level URIs like hf://models/openai-community/gpt2. Follow-up PRs can expand this to revisions and filenames...

Validation:
make style
make quality
PYTHONPATH=src python3 -m pytest tests/test_cli.py::TestCacheCommand
tests/test_cli.py::TestCacheCommand passes locally.
Full tests/test_cli.py hits unrelated network/DNS failures in production-style tests.


Note

Medium Risk
Extends cache-deletion target parsing to accept hf:// inputs; while scoped to repo-level URIs and covered by new tests, mistakes could cause unintended cache removals if URI-to-cache-id resolution is wrong.

Overview
hf cache rm now accepts repo-level hf:// URIs (e.g. hf://models/openai-community/gpt2) in addition to model/... IDs and revision hashes by resolving URIs via parse_hf_uri.

The command explicitly rejects non-repo URIs (e.g. buckets) and any hf:// URI that includes a revision (@...) or a path, and the CLI docs/reference plus tests were updated to reflect and validate this behavior.

Reviewed by Cursor Bugbot for commit 08c0c40. Bugbot is set up for automated code reviews on this repo. Configure here.

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.20%. Comparing base (1daa48b) to head (08c0c40).
⚠️ Report is 342 commits behind head on main.

Files with missing lines Patch % Lines
src/huggingface_hub/cli/cache.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4235      +/-   ##
==========================================
+ Coverage   75.00%   77.20%   +2.19%     
==========================================
  Files         145      171      +26     
  Lines       13978    19437    +5459     
==========================================
+ Hits        10484    15006    +4522     
- Misses       3494     4431     +937     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Wauplin

Wauplin commented May 19, 2026

Copy link
Copy Markdown
Collaborator

@bot /style

@Wauplin

Wauplin commented May 19, 2026

Copy link
Copy Markdown
Collaborator

x-linking initial comment #4226 (comment)

Comment thread src/huggingface_hub/serialization/_torch.py Outdated

@Wauplin Wauplin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you :)

Note that for the second PR we've discussed (being able to delete specific file), I'll prefer to handle it myself as I'll be a bit opinionated on how we want to deal with it

@Wauplin Wauplin merged commit 124bc0d into huggingface:main May 19, 2026
16 of 17 checks passed
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.16.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants