Repository navigation
Studio: add a Download to folder for model downloads - #13557
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f712a17d07
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| hf_token: hfToken, | ||
| use_xet: useXet, | ||
| transport_mode, | ||
| download_dir: downloadDirForRequest(req.downloadDir), |
There was a problem hiding this comment.
Scope partial checks to the selected folder
When a cancelled HTTP download resides in a custom folder, the transport preflight still calls /api/hub/transport-status without the pinned destination, so the backend examines the active Models folder rather than the folder sent here. If the user switches to Xet and resumes, the preflight can report no partial and skip the restart warning; the worker then prepares the custom cache for Xet and discards the existing HTTP partial. Pass the destination through the transport-status request and scope the backend checks to that cache.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Needs a cancelled HTTP partial in a custom folder plus a manual transport switch before resuming. The common resume path keeps the same transport, so leaving this one.
| /** Folder this job downloads into; null means the Models folder. */ | ||
| downloadDir?: string | null; |
There was a problem hiding this comment.
Persist the pinned folder with active jobs
The new job field is not included by toPersistedJob or restored by sanitizePersistedJob. If a download starts in folder A, the user selects folder B, and the page reloads while the first job is active, the restored job loses A; after cancellation, withDownloadDir therefore resumes into B instead of reusing A's partial, duplicating or restarting a large transfer. Serialize and sanitize downloadDir, including null, along with the other active-job metadata.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 00a87d5: downloadDir is now written and restored with the persisted job, with a reload test.
| ...(req.downloadDir !== undefined | ||
| ? { downloadDir: req.downloadDir } | ||
| : opts.adopt && existing?.downloadDir !== undefined | ||
| ? { downloadDir: existing.downloadDir } |
There was a problem hiding this comment.
Record the destination of an attached job
When another browser already has this repo and variant downloading in folder A, a start from a browser configured for folder B attaches to the existing backend job because registry keys are destination-independent, but this code records B from the request as the job's destination. Cancelling and resuming from that browser then starts in B and abandons A's partial. The start/active-download response needs to expose the actual claimed cache so attached jobs store the backend job's destination rather than the requested one.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Two browsers starting the same repo and variant into different folders is outside the case this targets, and the attached job still delivers the model.
| req: DownloadRequest, | ||
| request: DownloadRequest, | ||
| ): Promise<DownloadStartOutcome> { | ||
| const req = withDownloadDir(request); |
There was a problem hiding this comment.
Check free space on the pinned destination
After pinning a custom destination, the pre-download disk check still calls /api/system/disk without that path; the route explicitly measures only the active Models-folder hub and Xet caches. When the chosen folder is on another drive, the UI can miss low space on the drive that will receive the model or warn about an unrelated full Models drive. Pass the pinned destination to a validated disk-space endpoint so the notice measures the actual download volumes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The low disk notice is advisory only and never gates a start. The worker checks free space on the destination it writes to (HF_HUB_CACHE is the chosen folder), so a real shortage still fails with a clear message.
| if len(homes) >= MAX_DOWNLOAD_HOMES or any( | ||
| os.path.normcase(str(path)) == key for path in homes | ||
| ): | ||
| return |
There was a problem hiding this comment.
Refuse destinations that cannot be remembered
Once 64 download homes have been stored, a new valid destination reaches this early return but the caller still starts the worker there. Because that root is never added to known_hf_hub_caches, after live registry metadata is gone the cache-aware progress, cleanup, and deletion paths cannot resolve the downloaded files as a known HF cache. Either evict a stale entry, reject the download with an actionable error, or otherwise guarantee that every accepted destination is registered.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
64 distinct download folders is not a realistic setup, and the folder is still listed through Custom Folders even then.
| cache_paths = await asyncio.to_thread( | ||
| _download_cache_paths, getattr(body, "download_dir", None) | ||
| ) |
There was a problem hiding this comment.
Scope peer blob protection to the same cache root
Allowing each job to select its own cache breaks the registry's existing assumption that every active variant of a repo writes into one root. If Q4 is downloading in folder A while Q8 starts in folder B, peer_blob_hashes still marks A's shared companion hashes as protected for B; cache preparation in B can then preserve an abandoned or transport-incompatible partial solely because an unrelated file with the same hash is live on another disk. Include the claimed hub_cache when selecting peers so purge protection applies only to writers that can actually touch this job's files.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Over-protection only keeps a stale partial instead of purging it, never deletes live data, and needs two variants of one repo downloading into two different folders at once.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 00a87d56d6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| const previous = getState().jobs[jobKeyOf(req.kind, req.repoId, req.variant)]; | ||
| const resumable = | ||
| previous?.state === "cancelled" || previous?.state === "error"; |
There was a problem hiding this comment.
Let retries escape a rejected download folder
When the backend rejects a destination before starting—such as a native-picked credential directory, an unmounted drive, or a folder that is no longer writable—startJob retains that destination on the resulting error job. This condition then treats every error as resumable, so after the user selects a valid folder and clicks Download again, the request silently reuses the rejected path and fails repeatedly until the old job is manually dismissed. Only reuse the pinned directory for errors that can actually have resumable state, or allow the newly selected destination to replace it when no transfer began.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 7e789ea: only a cancelled job resumes into its pinned folder; a failed start uses the current choice. Covered in download-location.test.ts.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e789ea41d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| downloadDir: | ||
| previous?.state === "cancelled" && previous.downloadDir !== undefined | ||
| ? previous.downloadDir | ||
| : (downloadDirForRequest() ?? null), |
There was a problem hiding this comment.
Pin one destination for the entire staged plan
For a multi-entry model plan, useStagedDownload calls requestStart separately as each repo finishes, so this reads the current picker value again for every entry rather than preserving the value from when the user selected the model. If the user changes “Download to” while a long plan is running—or queues another model for a different drive—the remaining checkpoint/companion repos can be written to the newly selected folder, splitting one model across destinations and potentially consuming space on the wrong disk. Capture the directory when the plan is enqueued/staged and propagate that pinned value to every entry.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 53ccc63: stage() captures the folder once and every entry of the plan starts with it.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes #10872
What this does
Adds a simple Download to choice for model downloads in Unsloth Studio and Unsloth Desktop, so a large model can go to another drive without changing the global Models folder and changing it back.
Choose folder...(native folder dialog on Desktop, the folder browser on web). With the Models folder selected it is icon only, so the header layout is unchanged; with another folder selected it also shows that folder's name.<folder>/hub, same layout as the HF cache) and is added to Custom Folders, so the model shows up, loads, and can be deleted like any other cached model.Models foldersends the same request as before, so existing flows, notebooks and API callers are unchanged.How it works
Backend:
DownloadModelRequest.download_dir(optional). Omitted, blank, or equal to the Models folder means the Models folder, as before._validate_cache_home: absolute path, not a drive root, not a system or credential folder, writablehub/andxet/). A bad folder is a 400 with that message and nothing starts.hugging_face_download_homes), separate from the Models folder history, so download progress, resume, cancel, the cached checks and delete all see it, and neither list can push the other out. Already listed is a no-op.Frontend:
Reset all local preferencesclears it.download_diris only sent when a folder is chosen.Testing
hub/tests/test_download_to_folder.py, 10 tests. 9 fail on main and pass here; the 10th checks that no folder keeps the Models folder, and passes on both.test_delete_variant_*tests that fail on main too.tests/download-location.test.ts: request body, pinned folder, and resume vs failed start.tests/download-transport-persistence.test.ts.tsc -band the test typecheck are clean.install.sh --local, isolated home and cache), all checks passing on the final head:<folder>/hub, progress reads complete, listed once.400 The parent folder does not exist.download_dir. The file lands in the folder with the normal progress bar.Screenshots
Model hub header at 1500 px, before and after, with the Download to menu open. The header keeps the same number of rows.