unsloth/studio/backend/hub/utils
Daniel Han c72da05741
Studio: clean up empty leftover quant folders so they can be deleted (#6616)
* Studio: clean up empty leftover quant folders so they can be deleted

An interrupted or cancelled split GGUF download leaves snapshots/<rev>/<quant>/
behind with no shards. Such a folder is neither a completed download nor a
tracked partial (no .incomplete blobs, no manifest), so it was invisible in the
variant list and a per-variant delete returned 404, leaving it on disk forever.

- list_empty_gguf_variant_dirs: detect quant folders that are empty in every
  snapshot, excluding any quant that has shards in another snapshot.
- get_gguf_variants_response: surface those quants as partial (cleanable) so the
  UI shows a delete affordance.
- _delete_gguf_variant_from_repos: remove the empty (or just-emptied) quant
  subfolder and count it toward the result so the delete succeeds instead of 404.

Adds hub/tests/test_empty_variant_folder.py.

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

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

* Studio: simplify empty-dir check to any(iterdir())

* Studio: tighten comments on empty-quant-folder cleanup

* Studio: surface empty-folder removal failures and cleanables on local/offline paths

Address review feedback on the empty leftover quant folder cleanup:
- _remove_empty_variant_dirs now returns removal failures (read-only cache or a
  locked dir), and the variant delete raises 409 instead of a misleading 404; a
  concurrent download refilling the dir (ENOTEMPTY) is still treated as a skip.
- Empty leftover folders are surfaced as cleanable on every variant-listing path
  (prefer_local_cache / offline / HF-fallback), not just a remote listing, via a
  single post-process that flips a listed quant to partial or appends an
  unlisted one.

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

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

* Studio: surface empty-folder cleanables even when metadata fetch fails

When the cache holds only an empty leftover snapshots/<rev>/<quant>/ folder
from an interrupted split download and the client is offline or the HF
metadata request fails, _compute() re-raised before cleanables were marked,
leaving the folder undeletable. Now fall back to marking cleanables against an
empty response and return them if any; otherwise re-raise the original error.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-06-25 01:14:21 -07:00
..
__init__.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00
dataset_cache.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00
dataset_format.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00
download_manifest.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00
download_registry.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00
gguf.py Studio: clean up empty leftover quant folders so they can be deleted (#6616) 2026-06-25 01:14:21 -07:00
gguf_plan.py Fix GGUF variant file selection (#6342) 2026-06-16 12:42:58 +02:00
hf_cache_state.py Studio: free chat model VRAM at training start only when the GPU is tight (#6243) 2026-06-18 09:04:01 -07:00
hf_errors.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00
inventory_scan.py Studio: fix Downloaded model list disappearing and order it by last download (#6247) 2026-06-12 05:27:34 -07:00
llm_assist.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00
paths.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00
snapshot_filters.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00
state_dir.py feat(studio): Hub + Download Manager (#5916) 2026-06-09 04:11:24 -07:00