Skip to content

Studio: free the disk space when a GGUF quant is deleted or replaced - #11599

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
NilayYadav:studio-free-xet-blob-on-quant-delete
Sep 23, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
NilayYadav:studio-free-xet-blob-on-quant-delete

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

With huggingface_hub 1.32 or newer, deleting a GGUF quant from the Models page, or replacing it with an update, removes only a link. The file stays on disk, while the log says the space was freed.

After removing the link, Studio now asks huggingface_hub to remove the stored file. The file is kept if another model still uses it. Older huggingface_hub versions work as before.

Before / after in Studio

Same real huggingface_hub 1.32 cache on both sides (SmolLM2-135M-Instruct-GGUF, Q2_K and Q3_K_M), Q2_K deleted from the Model hub. The dialog promises 88 MB on both sides; only the PR actually frees it. Settings, System, Cache files then shows the Hugging Face model cache at 182 MB before the PR and 94 MB after (88,201,907 bytes left the disk on head, 0 on the merge base).

PR 11599 before and after

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Review + GitHub Actions evidence

Reviewed c23613aba4. The only later commit, e947611001, is pre-commit.ci reformatting a test signature, so deletion.py is byte-identical at head. Codex review (mirror) found no major issues, and there are no blocking code findings.

Actions A/B. Real huggingface_hub==1.32.0 download of two SmolLM2-135M quants, then Studio's _delete_cached_model_blocking(..., "Q2_K"), then the bytes that actually left the disk are measured. The two branches differ only in deletion.py, and the shared blob store was active in every job.

Runner Fix reverted (run) PR head (run)
ubuntu-latest 155 B freed, Q2_K payload 638f37… still on disk ❌ 88,202,062 B freed ✅
macos-14 155 B freed ❌ 88,202,062 B freed ✅
windows-latest 0 B freed ❌ 88,201,908 B freed ✅

Both sides log Deleted 1 file(s) … Q2_K: 84.1 MB freed. On the base, that log line is the only thing that changes.

Studio UI, same real cache, merge base vs head. Deleted Q2_K from the Model hub quant menu, where the dialog reads "Frees 88 MB". Settings → System → Cache files then shows the Hugging Face model cache at 182 MB before the fix and 94 MB after. Studio's hf_hub size went 181,712,463 → 181,712,463 B on the base and 181,712,463 → 93,510,556 B on head.

PR 11599 before/after

Tests. With huggingface_hub 1.32, the three new tests fail on the base code and pass on head, and 385 hub tests pass. With 1.31, 382 pass and the three new tests skip cleanly. The older non-shared path still frees the full 88.2 MB.

Conclusion. The leak and its fix are both verified on Linux, macOS and Windows. The one red on the fork CI run (Chat UI Tests (extra): "Context Length did not persist across reload") is in model-picker config persistence and is unrelated to this change; it is being rerun.

…ge shape

huggingface_hub.utils._shared_blobs is private and unsloth sets no
upper bound on huggingface_hub. A release that keeps both names but
changes their arguments would raise TypeError after the snapshot links
are already removed, which the OSError handler does not catch, so the
delete would stop part way and return a 500.

Check at import that both helpers accept the arguments Studio passes.
If they do not, disable them and use the previous plain unlink. No
per-call cost, and nothing changes on huggingface_hub 1.32.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 23, 2026
huggingface_hub compares the blob path and the cache root lexically.
Studio passes a resolved cache root, so a blob reached through a
symlinked cache directory, or a Windows 8.3 short name such as
C:\Users\RUNNER~1, no longer matches. The shared payload is then not
collected and the old "freed" size is reported, which is the leak this
PR fixes.

Try the cache root in the blob's own form first (the grandparent of
<repo>/blobs/<etag>), then the root Studio passed. This fixes
test_delete_variant_keeps_shared_xet_blob_referenced_by_other_repo on
windows-latest and adds a test that reproduces the mismatch with a
symlinked cache on every OS.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 23, 2026
…text

test_delete_variant_keeps_shared_xet_blob_referenced_by_other_repo
failed on windows-latest. huggingface_hub 1.32 rewrites the .refs
manifest with os.fsync on a handle opened read-only, which Windows
rejects with EBADF; the sweep catches it and keeps the payload, so the
stale line for the removed link stays. It names nothing on disk and
huggingface_hub already ignores it.

Assert the manifest's live entries instead, then delete the other
repo's copy and assert the payload and manifest are gone. That last
step still fails on the merge base (the payload is never collected)
and now passes on Linux, macOS and Windows.
@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #11599, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#73.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror b4ad1c0df3 (this PR's 6d4b1db86)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: b4ad1c0df3

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror b4ad1c0df3 (this PR's 6d4b1db86).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 23, 2026
@danielhanchen
danielhanchen merged commit 9b31882 into unslothai:main Sep 23, 2026
39 of 44 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…nslothai#11599)

* Studio: free the disk space when a GGUF quant is deleted or replaced

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: fall back to the plain unlink if the shared-blob helpers change shape

huggingface_hub.utils._shared_blobs is private and unsloth sets no
upper bound on huggingface_hub. A release that keeps both names but
changes their arguments would raise TypeError after the snapshot links
are already removed, which the OSError handler does not catch, so the
delete would stop part way and return a 500.

Check at import that both helpers accept the arguments Studio passes.
If they do not, disable them and use the previous plain unlink. No
per-call cost, and nothing changes on huggingface_hub 1.32.

* Studio: match the shared-blob cache root to the blob's own path form

huggingface_hub compares the blob path and the cache root lexically.
Studio passes a resolved cache root, so a blob reached through a
symlinked cache directory, or a Windows 8.3 short name such as
C:\Users\RUNNER~1, no longer matches. The shared payload is then not
collected and the old "freed" size is reported, which is the leak this
PR fixes.

Try the cache root in the blob's own form first (the grandparent of
<repo>/blobs/<etag>), then the root Studio passed. This fixes
test_delete_variant_keeps_shared_xet_blob_referenced_by_other_repo on
windows-latest and adds a test that reproduces the mismatch with a
symlinked cache on every OS.

* Studio: test the shared-blob outcome, not huggingface_hub's manifest text

test_delete_variant_keeps_shared_xet_blob_referenced_by_other_repo
failed on windows-latest. huggingface_hub 1.32 rewrites the .refs
manifest with os.fsync on a handle opened read-only, which Windows
rejects with EBADF; the sweep catches it and keeps the payload, so the
stale line for the removed link stays. It names nothing on disk and
huggingface_hub already ignores it.

Assert the manifest's live entries instead, then delete the other
repo's copy and assert the payload and manifest are gone. That last
step still fails on the merge base (the payload is never collected)
and now passes on Linux, macOS and Windows.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants