Skip to content

Studio: add multi-drive model libraries with per-library downloads - #11246

Closed
ItsRoy69 wants to merge 21 commits into
unslothai:mainfrom
ItsRoy69:studio-model-libraries
Closed

ItsRoy69 wants to merge 21 commits into
unslothai:mainfrom
ItsRoy69:studio-model-libraries

Conversation

@ItsRoy69

@ItsRoy69 ItsRoy69 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Multi-drive model libraries for Unsloth Studio: register cache-home folders on any drive, keep one default (always the active HF cache), pick a download destination per job, and move a cached model between libraries without re-downloading.

This PR is backend-only for #10872. Studio UI (settings manager, download “Download to” picker, move in the UI) is a follow-up.

Linked issue

Backend for #10872 (UI follow-up).

Summary

  • Fixes a bug
  • Adds a feature
  • Refactors code
  • Documentation only
  • Other

Backend changes

Libraries storage (hub/storage/model_libraries.py)

  • Owner-scoped CRUD in studio.db (model_libraries table, additive DDL).
  • Registration reuses _validate_cache_home: rejects drive roots, denied system paths, credential/config folders, uncreatable parents; reports free/writable status per volume. Windows-only COLLATE NOCASE dedupe mirrors scan_folders. Removing the default is refused.
  • is_default is derived (path == active cache home), never stored, so exactly one default always exists and promotion is just set_hf_cache_home.

Scan unification (utils/hf_cache_settings.py)

  • known_hf_cache_homes() now includes model_library_homes(), so inventory scans, the model list, delete scoping, the folder browser and tool confinement span every library with no further wiring.
  • Library probe failures are logged at debug and do not break scans.

Downloads (hub/schemas/downloads.py, hub/services/models/downloads.py)

  • New library_id on DownloadModelRequest ("default" | row id).
  • Transport, baseline/resume and cancel probes scope to the selected hub; the worker gets that library's cache env. Omitted library_id = active cache = current behavior.

Move (hub/services/models/libraries.py)

  • POST /api/hub/libraries/move relocates the cached hub/ repo dir across libraries (blobs + snapshots travel with it; no re-download).
  • Whole-repo only: a non-null variant is rejected with 400.
  • Shared xet/ store is left in place on purpose (content-addressed, shared across repos); response includes an optional note explaining that.
  • Refuses while a download or load is in flight (409).
  • On failed cross-volume move: source stays intact, partial dest is cleaned, source manifest is not purged.
  • Multi-copy: if the same repo is cached in more than one library, a warning is logged; copies not already in the target are moved.
  • Successful move purges the old hub’s manifest state and invalidates cache scans.

Routes (hub/routes/inventory.py)

  • GET/POST /api/hub/libraries
  • DELETE /api/hub/libraries/{library_id}
  • POST /api/hub/libraries/{library_id}/default
  • POST /api/hub/libraries/move

Migration: none — the default library is the existing Models folder; no backfill.

Behavior changes

  • Existing flows are unchanged when library_id is omitted.
  • Registered model libraries appear in the existing model inventory / Downloaded tab automatically (new UI is a follow-up).

Security

  • Library mutations are owner-scoped, exactly like the HF cache setting.
  • Paths validated as cache homes (sensitive/credential directories denied).
  • Move blocks in-flight downloads/loads and refuses the default library's removal.

Testing

  • hub/tests/test_model_libraries.py: validate/register/dedupe, Windows NOCASE, default derivation + dedupe, refuse-remove-default, promote, scan unification, library_cache_paths + 404s, move success / no-op / missing model, variant reject (400), XET left in place + note, failed-move cleanup, 409 while download/load active, non-default library env + manifest scoping, library probe log, HTTP mappings.
  • Re-ran adjacent suites: test_hf_cache_settings, test_download_lifecycle, test_download_manifest_scoping, test_model_services (pre-existing failures on main only — Windows symlink-privilege and ntpath decode). Refactor guard: inventory, golden outputs and patch targets match.
  • Manual smoke: register → dedupe → promote default → per-library download → 409 while downloading → move → already_in_library no-op.

Test plan

  1. pytest hub/tests/test_model_libraries.py
  2. pytest tests/test_hf_cache_settings.py hub/tests/test_download_lifecycle.py
  3. python tests/tools/refactor_guard.py

Rollout

  • Release without downtime
  • Requires manual verification (backend only; no schema migration)
  • Requires rollout monitoring

Docker / packaging checks

  • No image size increase
  • Backend-only change

@ItsRoy69

Copy link
Copy Markdown
Contributor Author

This PR is backend only for #10872. Libraries, default selection, per-download library_id, free space on the API, scan coverage, and move between libraries are in . UI is not in this PR (settings manager, download destination picker, move in the UI). Happy to do that as a follow-up once this is reviewed.

@lonexreb

Copy link
Copy Markdown
Contributor

Owning the model-library side of the inventory for a bit (#8798 export/import is next, then #4660), so I'll build the per-type folder ask from #8568 as the UI follow-up on top of this once it lands rather than in parallel. Two things that would help it along: the seven red legs are mostly the zoo/Core families and the studio pin that were red on main itself around Sep 18–25, so a rebase onto current main should clear most of them and show what is really yours; and a line in the description on how the default library interacts with an existing Custom Folder pointing at the same drive (does discovery dedupe, or does the model list show it twice) is the first question a reviewer here will ask.

@danielhanchen danielhanchen self-assigned this Oct 5, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for the PR - we won't be adding this at this time

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