Repository navigation
Studio: let the download transport be picked in Settings > General - #9272
Conversation
7c38312 to
5b91467
Compare
|
Rebased onto main. The three reds on the previous run were all main's, and each is fixed in the new base:
The revert in #9293 lands in the same files this branch edits ( Local runs also show three |
|
Confirmed the default today is Auto in download-manager/constants.ts and Auto resolves to Xet in download_registry.py, so every new install downloads on a transport it never picked, and the grandfathering seed keeps existing installs on Auto. One small thing: transport-mode-auto.test.ts now refers readers to transport-preference-order.test.ts, which does not exist on this branch. |
4668adf to
fb4d8a8
Compare
|
Right on both counts, thanks. The cross-reference was stale: I also swept every file name the diff mentions in an added line against the tree, and that was the only one that did not resolve. Rebased while I was in there. 4095 frontend tests pass, typecheck clean, and the backend transport and scoped-download suites pass on the new base. |
|
The stale cross-reference is gone, I checked the parts I thought could bite and most of them are fine. The One blocking problem though. The grandfather check reads a table almost anything can write
Your verification is right that a full boot leaves all three tables empty. The problem is what happens after boot. I drove three pristine installs through a real
Opening Images needs no user edit at all. Chatting with an API model before the first download does the same thing through The reason the suite is green on this is that every seed test stubs Two ways out that both look clean to me. Seed eagerly in the lifespan hook at The Hub toggle now writes install-wide
Worth noting Smaller things
A failed PUT is
The new await at
Last one on tests. |
|
Pushed the fixes to this branch in ae4bff0. Answering the questions I was left with after the review, in order. Is this a real problem or a fake oneReal, and I reproduced it rather than argued it. Before this PR the transport preference defaulted to What did not hold was the fix. The seed was lazy, and its only triggers were the first download or the first settings GET. Before and after, same simulation, real
Five of the six ordinary paths were wrong. The fix seeds in the lifespan, before any route can serve, which is the only point where the tables still describe the install rather than what the user has clicked since. Does merging break anythingOld installs, no. Every one of them was already writing to
All four are stable across every one of the six first actions, so no ordering can move them. Scripted callers, no. The The one caller worth naming is New hardware paths, none added. The transport decision reads SimulationsTen suites, all green, run from The real startup path, not a stand-in. Each case runs the actual [Windows, Linux, WSL, macOS] x [NVIDIA, AMD, CPU only], 12 cells, all Robustness: a db held under Browser engines. The repo already drives chromium, firefox and webkit in Dependency weight. The startup seed runs in a clean What I changed
Three things I deliberately left. One note on the tests. Locally: 4096 frontend tests, typecheck clean, |
|
One more, and it goes at the copy rather than the code. CI on ae4bff0 is green, all checks, no failures. HTTP does not resume on the huggingface_hub this branch ships againstThe new Settings copy states, in all 12 locales, that HTTPS resumes:
huggingface_hub 1.18 moved the writer from a shared Studio delegates to huggingface_hub and has no Range writer of its own, and the runtime pin is: So the claim holds only on a Python 3.9 install. Everywhere else it is false:
1.28.0 is current on PyPI. The tree already knows this. The download cards handle it correctly today: Why it matters beyond the wordingResume is the load-bearing argument in the PR description. "A cancelled or dropped transfer starts the file again instead of resuming from the bytes already on disk" is listed first among Xet's drawbacks, but on the pinned hf_hub that is true of HTTPS as well, so the two are level there and the sentence reads as a distinction that does not exist. The rest of the case is untouched and still good: HTTPS works through any proxy, VPN or inspected network, memory stays flat, there is no Suggested shapeI have not touched the copy, because rewording it correctly in 12 languages is your call and
I would take the first. Happy to push either if you tell me which, including the locale edits. Separately, |
|
Opened #9602 for the resume problem, so the copy decision here can wait on it rather than be walked back. Short version: the claim in this branch's copy is false today and true again if #9602 lands. huggingface_hub 1.18 stopped resuming HTTP partials, and Measured on an 800MB GGUF against 1.28.0, killed 8s in and restarted:
Interrupted twice and then allowed to finish, the completed 807.7 MB file's sha256 matches the blob name, so the resumed bytes are correct and not just continuous. If #9602 goes in first, nothing here needs changing: If it does not, the three strings need the distinction, because a network drop and a cancel behave differently even on 1.18+: the retry loop inside One correction to what I wrote earlier in this thread: I said flatly that HTTP does not resume on 1.18+. That is right for cancel and for a killed process, which is the case the copy is about, but too broad, since transient network errors within a single run still resume. |
…ked for Fixes for PR unslothai#9272. Seed the transport in the lifespan, before any route can serve. The seed counted any row in app_settings as prior use, and app_settings is shared by around fifteen subsystems, so on a genuinely new install a single unrelated write decided the transport. Opening the Images page was enough: its preset autosave has no dirty check and PUTs 400ms after mount, so a new user who looked at Images once and then downloaded a model got Xet, permanently. Deciding at startup makes the ordering a property of the code rather than of what the user clicked first. Do not persist a seed decided from evidence that could not be read. An unreadable install answers HTTPS for that process, as before, but no longer writes it, so a locked db at boot cannot freeze an old install onto HTTPS. Persist the seed once under the lock as well: concurrent first reads all saw no stored value and each wrote it. Keep the Hub toggle's automatic xet to http correction browser-local. It predates this branch, but setMode now also PUTs the install setting, so loading the Hub models page on a machine without hf_xet silently rewrote the transport for every other browser and every scripted caller. Fall back to the Hub's capabilities when the settings read fails, so Xet is not offered on a machine that cannot run it, and read xet_available as a strict true. Bound that read with the WebView-safe timeout ponyfill: a download start awaits it, outside the try that tears the runtime down, so a hung settings endpoint left a registered job with no poll and no error. Toast when the install-wide write fails instead of only warning to the console, and import the settings module directly rather than through the barrel that imports this feature back. Tests: the real predicate against a real studio.db rather than a stub, the unreadable-install case, and the Xet availability rule as behaviour instead of a regex over the component source.
Which transport downloads run on was a toggle on the Hub page, so the choice lived in one browser's localStorage and most people never found it. It is a row in Settings > General now, saved for the install through /api/settings/download-transport, with the difference between HTTPS, Xet and Auto spelled out in the copy. No default changes. An install nobody has opened the row on still runs on Auto, and the download request path is untouched: a caller that states nothing gets exactly what it got before.
5531c74 to
9be63ee
Compare
|
Rescoped: the HTTPS default is out, and what is left is the Settings row on its own. Removed:
Kept: the row itself, the An install nobody has opened the row on now behaves identically to main. Verified: 4095 frontend tests, typecheck and build clean, 8 backend transport tests, and the wider backend download and settings suites at 783 and 752 passing. Locale parity passes. Title and description updated. The branch name is left alone, since renaming it would detach this PR. |
|
Before/after from two isolated installs, so the panel is built from each tree rather than one Studio with a checkout in between. BEFORE is this PR's merge base BEFORE goes straight from "Documents & RAG" to "Uploads". AFTER inserts a "Downloads" section between them with the transport row.
Everything else in the panel is byte-for-byte the same neighbourhood on both halves (sidebar, Uploads, Helper LLM, Danger zone), which is what makes the one inserted section readable as the change rather than as two different scroll positions. The scene requires the untouched "Uploads" heading to be present on BOTH sides before it will report anything, so a BEFORE with no transport row is an absence rather than a click that missed. The status line is also a useful confirmation of the default: with nothing configured the setting is Auto, and Auto resolved to Xet on this host, which matches Two notes, neither about the screenshots: The branch is named
This branch is 197 commits behind |
Two conflicts, both in studio/backend/routes/settings.py and both additive: this branch's download-transport models and routes against the xet-notice ones from #9660. Kept both. The download manager auto-merged onto #9660's start-toast work: startJob and requestStart now await resolveTransportMode(), so the install setting is honoured, and the route each start toast is held against is still captured before that await rather than after it.
- the Hub's automatic Xet to HTTP fallback ran through the same setter, so merely opening the Hub without hf_xet rewrote the install-wide choice for every browser, permanently; it stays local now - a download re-reads the install setting instead of trusting a cache held for the life of the tab, which is the whole point of an install-level setting - install-wide writes are serialized, so two quick selections cannot leave the database on the mode the user did not pick - the settings row asks for the free-RAM half of the Auto verdict, which the download path applies and this row skipped, so it no longer says Auto is using Xet on a machine whose next download picks HTTP - HTTPS no longer promises a resume on an install whose huggingface_hub cannot do one; the row reads the capability it already has - the Xet-unavailable reason uses the translated string rather than the backend's English prose, which made the new translations unreachable
…ur ordering fixes - the Hub toggle only falls back to HTTP once Xet is KNOWN unavailable; gating both that and the disabled state on the same flag showed HTTP for a stored Xet during the capability check, with nothing to put it back - the hydration wrapper no longer memoizes past the refresh flag, so the API layer can apply its own freshness rule - a completed write advances the request generation, so a read taken before it cannot land after and republish the replaced mode - the settings row re-reads the install setting on mount - the browser's transport override joins the local preference reset, since it outranks the install-wide setting
…stale one A GET that a PUT or a newer refresh has superseded was kept out of the cache but still resolved with its own payload. Both callers write that value into their own state, so on a browser with localStorage unavailable the late response visibly reverted the mode the user had just picked.
|
Codex Review: Didn't find any major issues. Delightful! 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". |
A download started before the first settings load answers overtakes it with a refresh. When that refresh failed, the catch returned a still-null installMode and the download ran on Auto, even though the request it overtook was about to deliver the install's explicit choice.
Hydrating from the cache on mount showed the old mode in the toggle while the download path, which refreshes, already ran on the one another browser had set.
|
Codex Review: Didn't find any major issues. Swish! 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". |
…9272) * Studio: let the download transport be picked in Settings > General Which transport downloads run on was a toggle on the Hub page, so the choice lived in one browser's localStorage and most people never found it. It is a row in Settings > General now, saved for the install through /api/settings/download-transport, with the difference between HTTPS, Xet and Auto spelled out in the copy. No default changes. An install nobody has opened the row on still runs on Auto, and the download request path is untouched: a caller that states nothing gets exactly what it got before. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix six review findings on the download transport setting - the Hub's automatic Xet to HTTP fallback ran through the same setter, so merely opening the Hub without hf_xet rewrote the install-wide choice for every browser, permanently; it stays local now - a download re-reads the install setting instead of trusting a cache held for the life of the tab, which is the whole point of an install-level setting - install-wide writes are serialized, so two quick selections cannot leave the database on the mode the user did not pick - the settings row asks for the free-RAM half of the Auto verdict, which the download path applies and this row skipped, so it no longer says Auto is using Xet on a machine whose next download picks HTTP - HTTPS no longer promises a resume on an install whose huggingface_hub cannot do one; the row reads the capability it already has - the Xet-unavailable reason uses the translated string rather than the backend's English prose, which made the new translations unreachable * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Save the setting when localStorage is blocked, and stop mixing languages in the Auto line - a browser with storage blocked returned before the install-wide write, so it could not change the transport at all; only a failure at both ends toasts now - the Xet health reason is free-form English from the backend, so it goes on its own line instead of being interpolated into a translated sentence, and the key that interpolated it is removed rather than left unreachable * Fix four follow-on findings on the download transport setting - a failed per-download refresh kept the install mode already loaded instead of falling back to Auto - adopting a job no longer waits on the settings route: that branch ignores the result, and suspending there let two concurrent adoptJob callers replace each other's runtime and leave duplicate poll timers - ram_gate loads the health verdict rather than reading a cache that is empty on a fresh backend, still without the live probe - Xet cannot be selected before its availability is known, and nothing claims hf_xet is missing while that is still pending * Keep the automatic fallback out of storage, report failed install writes, index the row - the Hub's Xet to HTTP fallback wrote localStorage before the opt-out was checked, and a local value outranks the install one, so the browser stayed pinned to HTTP after hf_xet was installed; it is reflected and stored nowhere now - a settings PUT that fails is said out loud even when the local write worked: the row calls this install-wide, and only the console knew otherwise - the Downloads section and its options join SETTINGS_SEARCH_INDEX, so searching Settings for transport, HTTPS or Xet finds the row this PR exists to expose * Do not share a stale settings request, gate Hub Xet on hydration, index with targets - a refreshing caller could ride on a hydration GET already answered with the old mode, which is the value it went to replace; refreshes share only with refreshes now, and a request generation stops an older response caching last - the Hub toggle waits to know whether Xet can run, like the settings row: clicking it first stored a preference every later download quietly ignored - the indexed HTTPS, Xet and Auto labels carry data-settings-label, so a search result has somewhere to scroll to instead of just opening General * Separate 'cannot choose Xet yet' from 'Xet does not run here', and four ordering fixes - the Hub toggle only falls back to HTTP once Xet is KNOWN unavailable; gating both that and the disabled state on the same flag showed HTTP for a stored Xet during the capability check, with nothing to put it back - the hydration wrapper no longer memoizes past the refresh flag, so the API layer can apply its own freshness rule - a completed write advances the request generation, so a read taken before it cannot land after and republish the replaced mode - the settings row re-reads the install setting on mount - the browser's transport override joins the local preference reset, since it outranks the install-wide setting * Hand a superseded settings read the current value instead of its own stale one A GET that a PUT or a newer refresh has superseded was kept out of the cache but still resolved with its own payload. Both callers write that value into their own state, so on a browser with localStorage unavailable the late response visibly reverted the mode the user had just picked. * Shorten the comments added by this PR * Keep the hydration a failed refresh overtook as its fallback A download started before the first settings load answers overtakes it with a refresh. When that refresh failed, the catch returned a still-null installMode and the download ran on Auto, even though the request it overtook was about to deliver the install's explicit choice. * Mount the transport controls on a refreshed install mode Hydrating from the cache on mount showed the old mode in the toggle while the download path, which refreshes, already ran on the one another browser had set. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>
…se the first zoo import with the media import window (#13738) ### Why Right after launch, picking a quant to download in the chat model picker showed nothing for several seconds, up to ~10 s on a slow torch warm, until the download panel and the Xet toast suddenly appeared. The app stayed responsive; there was just no sign the click had landed. `requestStart` runs the whole preflight with no UI: the install transport setting (`GET /api/settings/download-transport`, forced when the browser has no saved choice), the Auto probe (`GET /api/studio/download-transport-capabilities?probe=1`), the sibling and partial checks, then the start itself. The first two compute the transport row with the RAM gate and the probe on, so `hub/utils/download_registry.py` asks `xet_health`, and that imports the whole `unsloth_zoo` package on the request thread: about 5,400 modules, ~3 s idle and +312 MB RSS. Right after launch that import competes with the startup torch warm (7-13 s on the machine this was measured on), neither request has a client timeout, and the only feedback was the panel plus toast, which appear once a job exists. Context: #7742 put the zoo-backed health verdict on the start path, #8564 deliberately dropped the startup zoo warm (312 MB, "optional GPU consumers stay cold"), #9272 added the serial settings request, and #12472 makes the import wait on the warm's dynamo import. A startup prewarm was not an option for the same 312 MB reason. The same import also raced the post-warm worker from a second entry point: the request thread imports triton then `torchao.kernel`, the post-warm worker imports torchao then diffusers, and CPython's import deadlock detector handed one side a partially initialised `torchao.kernel`. That left `unsloth_zoo.hf_xet_health unavailable (... partially initialized module 'torchao.kernel')` memoised as "no verdict" for the rest of the process, plus `torchao is unusable: KeyError: 'torchao'`, in 2 of 5 cold clicks. ### What **Frontend: feedback within a frame of the click.** - `hub/download-manager/pending-starts.ts` is a small display store. `runWithPendingStartGuard` publishes the start after its busy/already-started early returns and retires it in `finally`; retire removes only the entry that guard published, so a session reset mid-preflight plus a re-click cannot drop the second start's feedback. The store resets with the rest of the download manager state. - The downloads panel shows a pending start at once: a row whose key is already listed (a retry inside a finished row's linger) reads "Starting…" in place with its outcome icon hidden and Dismiss disabled until the job exists; a start with no row gets its own row. Both decisions come from one visible set, which hides a start when its job is already active or when a queued plan already shows the same transfer. That match is by job key, so a different quant or a companion plan of the same repo does not hide the feedback, and the queued-entry producers now carry the variant the key needs. The header count includes pending starts and the panel no longer hides itself while one exists. - Measured in the real UI on a cold backend: "Starting…" 0.2 s after the click, instead of nothing until the preflight finished (4.8 s with the backend pinned to two CPUs, ~10 s on a slower warm). **Backend: one import at a time for the torch compile stack.** - `torch_warmup.hold_media_import_window(reason)` holds the existing media import window around a foreground import: non-blocking acquire, then a wait bounded by the dynamo gate timeout with the same info/warning logs as the load-side claim; an expired wait still imports; pass-through for the thread that owns the window and under `UNSLOTH_STUDIO_DISABLE_DYNAMO_IMPORT_GATE=1`. - `utils/hf_xet_fallback.py` takes that window around its `unsloth_zoo` imports in both loaders, after the dynamo gate and outside `_load_lock` (nested, so the window-outer / lock-inner order is explicit): `child_environment_for_spawn` holds `_load_lock` around every worker spawn, so a spawn never waits behind a background import, and the post-warm worker's torchao and diffusers imports now wait behind the zoo import instead of interleaving with it. Each load opens one window, so a failed first attempt keeps the window for its retry rather than waiting twice. - `_dynamo_gate_timeout()` clamps to `threading.TIMEOUT_MAX`: an unbounded setting (`inf`) made `Lock.acquire` raise out of the loaders and silently skipped the existing dynamo gate. - Measured: 0 of 4 cold clicks hit the partially initialised `torchao.kernel` afterwards; a request that lands during the post-warm imports waits for them (1-9 s here) rather than poisoning them. ### Tests - `tests/download-pending-start.test.ts`: the entry is visible from the first held preflight request until the backend accepts; a second click returns busy without a second entry; an unreachable backend and a rejected start (`accepted: false`, error row) both leave no entry; a restart inside a cancelled row's linger keeps that row and marks it starting; the visible set yields to an active job and to a queued plan for the same transfer but not to another plan of the same repo; retire removes only the published entry; the panel derives both row kinds from the same visible set. `download-panel-not-permanent.test.ts` recognises the new list local in the panel's null guard. - `studio/backend/tests/test_xet_import_window.py` (15 tests): both loaders import inside the window as its owner; a load waits for a background media import in flight and still runs when the wait expires; a failed first attempt keeps the window for its retry; an expired wait logs and releases nothing; a failure inside the window releases it; the kill switch and the owner thread pass through; an unbounded timeout setting waits instead of raising; the loaders run unguarded when `torch_warmup` is unavailable; AST pins that every zoo import in the shim sits inside a window, that each loader opens exactly one, and that the gate runs before the window and the window wraps `_load_lock`. - On this tree: frontend suite 12,116 passing, typecheck and ESLint unchanged against `main`; backend shim/warm/hub tests pass in a full venv, with only the pre-existing environment failures elsewhere. ### Notes - Nothing platform-specific: `threading.Lock`, `get_ident`, `perf_counter` and a zustand store, so Windows, macOS, Linux, browsers and the desktop WebView behave the same. - Left as is: there is no Cancel during a preflight (before there was no row at all); a cancelled row's 6 s linger can expire during a cold preflight, in which case its "Starting…" row moves to the bottom where the job row lands anyway; the background side of the window keeps its unbounded wait, so a wedged zoo import would delay the post-warm tail rather than deadlock it. - Follow-up: the companion unsloth-zoo PR "Import the Hub download helpers without unsloth_zoo's package init" moves these helpers to an init-free `unsloth_zoo_downloads` package (20 ms, 119 modules). Once a zoo with it ships, the shim can import that first and fall back to the old names, which removes the init from the first download entirely; the pending-start row then covers a preflight of milliseconds. <!-- studio-ui-evidence:start --> ### Before / after Two isolated Studio installs, BEFORE = merge base `daab3bcd8`, AFTER = this PR. The download preflight is held for 10 s so its window is the same on both sides; the shot is taken 1.5 s after clicking Download on `unsloth/SmolLM2-135M-Instruct-GGUF` (F16), and the start request is aborted so nothing is fetched. Downloads panel corner: BEFORE shows nothing while the preflight runs; AFTER shows the panel with a "Starting…" row for the repo.  Full Model hub page at the same moment (the quant card's own "Starting…" button is unchanged on both sides; only the Downloads panel differs):  <!-- studio-ui-evidence:end --> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>

What this changes
Which transport a download runs on is a real setting now: Settings > General > Downloads > Download transport, offering HTTPS, Xet and Auto.
Before this, the only place to pick one was a small toggle on the Hub page. That put the choice in a single browser's
localStorage, so it did not follow the install, it was invisible to anyone who never opened the Hub, and nothing in the UI said what the two transports actually differ on.What it does not change
No default moves. An install where nobody has touched the row still runs on Auto, exactly as before, and the download request path is untouched: a request that states neither
transport_modenoruse_xetresolves the same way it did on main. The only behaviour that changes is the behaviour someone asks for.The copy
The row explains the trade-off rather than just naming the two, since the difference matters and is not guessable:
hf_xet, uses more RAM, and a cancel discards the file in flight.Xet with no
hf_xetinstalled is shown disabled with the reason, rather than as a selected option that silently downloads over HTTPS. Under Auto the row says which transport is in force on this machine and why.How it is stored
download_transport_modeinapp_settings, read and written throughGET/PUT /api/settings/download-transport. Unset reads as Auto and nothing is written until someone picks.The preference resolves as: this browser's own choice, then the install's setting, then Auto. A download start awaits the install setting rather than reading whatever is cached, so a browser that has never chosen still follows a transport picked elsewhere on the same install.
Tests
studio/backend/tests/test_download_transport_setting.py: the default, junk on disk, an unreadable db, validation, and both routes.studio/frontend/tests/download-transport-setting.test.ts: the resolution order, the default staying Auto, the download start awaiting the setting, the row's options and status line, and that the copy explains the difference.studio/frontend/tests/transport-mode-auto.test.ts: updated for the constant now being a floor rather than the whole answer.12 locales carry the new strings and the parity check passes.
Note: the branch name predates the scope change and no longer describes the PR.