Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: download files over 50GB from ModelScope over HTTPS (#15989) (#15994)
Indrajit swain3b9ad4d4f809
diff --git a/studio/backend/hub/services/download_lifecycle.py b/studio/backend/hub/services/download_lifecycle.pyindex 05b21807715..c01d84b7c92 100644--- a/studio/backend/hub/services/download_lifecycle.py+++ b/studio/backend/hub/services/download_lifecycle.py@@ -272,7 +272,10 @@ def resolve_requested_use_xet(def resolve_auto_use_xet(*, largest_file_bytes: Optional[int] = None) -> tuple[bool, str]:"""Pick a transport for a download the user left on "Auto". Returns ``(use_xet, reason)``. Server-side on purpose: only the backend can see this machine's RAM, its hf_xet build, and whether Xet has been failing here. Probing IS allowed here, unlike in the capabilities endpoint the UI polls on render, because this runs once per download request and the verdict is memoized."""if not resolve_effective_use_xet(True):- return (False, "hf_xet is not installed")+ reason = download_registry.download_transport_unavailable_reason(+ download_registry.TRANSPORT_XET+ )+ return (False, reason or "hf_xet is not installed")http_ceiling_reason = download_registry.http_size_ceiling_reason(largest_file_bytes)if http_ceiling_reason is not None:# Health and RAM preferences cannot select HTTP when the file exceeds its limit.diff --git a/studio/backend/hub/utils/download_registry.py b/studio/backend/hub/utils/download_registry.pyindex e12c9f0ebf9..c0f86658e37 100644--- a/studio/backend/hub/utils/download_registry.py+++ b/studio/backend/hub/utils/download_registry.py@@ -63,6 +63,8 @@ _HTTP_MAX_FILE_BYTES_FALLBACK = 50 * 1000 * 1000 * 1000_HTTP_SIZE_CEILING_MARKER = "too large to be downloaded using the regular download method"+_MODELSCOPE_XET_REASON = "ModelScope does not offer Xet, so downloads from it use HTTPS"+def http_max_file_bytes() -> int:"""The largest single file the HTTP transport can fetch."""@@ -74,8 +76,16 @@ def http_max_file_bytes() -> int:return value if value > 0 else _HTTP_MAX_FILE_BYTES_FALLBACK+def _modelscope_is_source() -> bool:+ from utils.hub_settings import MODELSCOPE, active_source+ return active_source() == MODELSCOPE++def http_size_ceiling_reason(largest_file_bytes: Optional[int]) -> Optional[str]:- """An unknown size (None or 0) is no evidence, so the transport choice is left exactly as it was."""+ """An unknown size (None or 0) is no evidence, so the transport choice is left exactly as it was.+ ModelScope's CDN serves any size over HTTPS, and its worker lifts the hub's client-side check."""+ if _modelscope_is_source():+ return Nonetry:largest = int(largest_file_bytes or 0)except (TypeError, ValueError):@@ -132,10 +142,15 @@ def get_download_transport_capabilities(largest_file_bytes: Optional[int] = None,) -> DownloadTransportCapabilities:"""probe checks live Xet health, ram_gate applies memory pressure, largest_file_bytes HTTP size limit."""- xet_available = importlib.util.find_spec("hf_xet") is not None+ # A ModelScope "Xet" job is plain HTTP in practice (the adapter sends no Xet headers), under a marker that then purges its partials.+ modelscope_xet_reason = _MODELSCOPE_XET_REASON if _modelscope_is_source() else None+ xet_reason = modelscope_xet_reason+ if xet_reason is None and importlib.util.find_spec("hf_xet") is None:+ xet_reason = "Xet transport is unavailable because hf_xet is not installed."+ xet_available = xet_reason is Nonehttp_reason = http_size_ceiling_reason(largest_file_bytes)auto_transport = TRANSPORT_XET if xet_available else TRANSPORT_HTTP- auto_reason: Optional[str] = None+ auto_reason: Optional[str] = modelscope_xet_reasonauto_forced = Falseif xet_available:try:@@ -177,12 +192,7 @@ def get_download_transport_capabilities(auto_reason = "Xet (HTTPS cannot fetch a file this large)"return DownloadTransportCapabilities(http = DownloadTransportCapability(available = http_reason is None, reason = http_reason),- xet = DownloadTransportCapability(- available = xet_available,- reason = None- if xet_available- else "Xet transport is unavailable because hf_xet is not installed.",- ),+ xet = DownloadTransportCapability(available = xet_available, reason = xet_reason),auto_resolves_to = auto_transport,auto_reason = auto_reason,partials_resumable = hf_partials_are_resumable(),diff --git a/studio/backend/hub/workers/hf_download.py b/studio/backend/hub/workers/hf_download.pyindex e555f052437..a8ece0a5bbb 100644--- a/studio/backend/hub/workers/hf_download.py+++ b/studio/backend/hub/workers/hf_download.py@@ -74,6 +74,15 @@ def _on_signal(signum, frame):sys.exit(130)+def _lift_http_ceiling_on_modelscope() -> None:+ """The hub refuses large HTTP transfers on the client side, for Hugging Face's storage; ModelScope's CDN serves them."""+ from huggingface_hub import constants+ from utils.hub_settings import MODELSCOPE, active_source++ if active_source() == MODELSCOPE:+ constants.MAX_HTTP_DOWNLOAD_SIZE = sys.maxsize++def _install_signal_handlers() -> None:signal.signal(signal.SIGTERM, _on_signal)signal.signal(signal.SIGINT, _on_signal)@@ -1222,6 +1231,7 @@ def main() -> None:_install_parent_death_watchdog(args.parent_pid, args.heartbeat)hf_token = os.environ.get("HF_TOKEN") or None+ _lift_http_ceiling_on_modelscope()if args.transport == "xet" and os.environ.get("UNSLOTH_HF_XET_FORCE_STALL") == "1":_force_stall_for_tests(args.repo_id, "dataset" if args.dataset else "model")diff --git a/studio/backend/tests/test_hub_download_http_size_ceiling.py b/studio/backend/tests/test_hub_download_http_size_ceiling.pyindex 0baecf27056..494cc242c28 100644--- a/studio/backend/tests/test_hub_download_http_size_ceiling.py+++ b/studio/backend/tests/test_hub_download_http_size_ceiling.py@@ -794,6 +794,85 @@ def test_an_ignored_file_list_does_not_refuse_a_download_that_fits(monkeypatch):assert result["transport"] == download_registry.TRANSPORT_HTTP+def modelscope_source(monkeypatch):+ from utils import hub_settings+ monkeypatch.setenv(hub_settings.SOURCE_ENV, hub_settings.MODELSCOPE)+ monkeypatch.setattr(download_registry.importlib.util, "find_spec", lambda name: object())++[email protected]("mode", ["auto", "xet", "http"])+def test_modelscope_fetches_an_oversized_variant_over_http(monkeypatch, modelscope_source, mode):+ model_downloads = _request_path(monkeypatch)+ monkeypatch.setattr(+ dl, "_repo_siblings", lambda *a, **k: (_Sibling("model.safetensors", _OVERSIZED),)+ )++ result = _download(model_downloads, transport_mode = mode)++ assert result["transport"] == download_registry.TRANSPORT_HTTP+++def test_modelscope_keeps_the_http_rung_for_an_oversized_download(modelscope_source):+ assert dl.http_rung_reason("model", "org/M", known_largest_file_bytes = _OVERSIZED) is None+++def test_modelscope_capabilities_offer_http_only(modelscope_source):+ caps = download_registry.get_download_transport_capabilities(largest_file_bytes = _OVERSIZED)+ assert caps.xet.available is False+ assert caps.xet.reason == caps.auto_reason+ assert "ModelScope" in caps.xet.reason+ assert caps.http.available is True+ assert caps.auto_resolves_to == download_registry.TRANSPORT_HTTP+++def _worker_main_exit_code(monkeypatch, tmp_path) -> int:+ """Run the worker's main into the hub's real size check, stopping at the request that follows it."""+ from huggingface_hub import constants, file_download++ from hub.workers import hf_download++ # Registers the undo: the worker overwrites this process-wide constant.+ monkeypatch.setattr(constants, "MAX_HTTP_DOWNLOAD_SIZE", constants.MAX_HTTP_DOWNLOAD_SIZE)++ class _Reached(Exception):+ pass++ def _reached(*_a, **_k):+ raise _Reached++ def _download(*_a):+ with open(tmp_path / "partial", "wb") as handle, pytest.raises(_Reached):+ file_download.http_get("https://example.invalid/f", handle, expected_size = _OVERSIZED)++ monkeypatch.setattr(file_download, "http_stream_backoff", _reached)+ monkeypatch.setattr(hf_download, "_install_signal_handlers", lambda: None)+ monkeypatch.setattr(hf_download, "_download_snapshot", _download)+ monkeypatch.setattr(sys, "argv", ["hf_download", "--repo-id", "org/M"])+ with pytest.raises(SystemExit) as excinfo:+ hf_download.main()+ return excinfo.value.code+++def test_the_modelscope_worker_lifts_the_hubs_client_side_check(+ monkeypatch, tmp_path, modelscope_source+):+ assert _worker_main_exit_code(monkeypatch, tmp_path) == 0+++def test_a_hugging_face_worker_keeps_the_hubs_check(monkeypatch, tmp_path, capfd):+ assert _worker_main_exit_code(monkeypatch, tmp_path) == 1+ assert "too large" in capfd.readouterr().err+++def test_a_hugging_face_install_without_hf_xet_keeps_its_auto_reason(monkeypatch):+ monkeypatch.setattr(download_registry.importlib.util, "find_spec", lambda name: None)+ caps = download_registry.get_download_transport_capabilities()+ assert caps.xet.available is False+ assert "hf_xet is not installed" in caps.xet.reason+ assert caps.auto_reason is None++def test_a_real_scope_is_still_measured_on_its_files(monkeypatch):model_downloads = _request_path(monkeypatch)diff --git a/studio/frontend/src/features/hub/download-manager/api.ts b/studio/frontend/src/features/hub/download-manager/api.tsindex 59a792934e0..34077a3e5ea 100644--- a/studio/frontend/src/features/hub/download-manager/api.ts+++ b/studio/frontend/src/features/hub/download-manager/api.ts@@ -160,6 +160,14 @@ let downloadTransportCapabilitiesCache: {} | null = null;let downloadTransportCapabilitiesInFlight: Promise<DownloadTransportCapabilities> | null =null;+let downloadTransportCapabilitiesGeneration = 0;++/** Xet availability depends on the model source (ModelScope has none), so a source switch drops the verdict. */+export function clearDownloadTransportCapabilitiesCache(): void {+ downloadTransportCapabilitiesGeneration += 1;+ downloadTransportCapabilitiesCache = null;+ downloadTransportCapabilitiesInFlight = null;+}export async function getDownloadTransportCapabilities(options: {force?: boolean;@@ -177,12 +185,16 @@ export async function getDownloadTransportCapabilities(options: {if (!options.force && !options.probe && downloadTransportCapabilitiesInFlight) {return downloadTransportCapabilitiesInFlight;}+ const generation = downloadTransportCapabilitiesGeneration;const request = authFetch(`/api/studio/download-transport-capabilities${options.probe ? "?probe=1" : ""}`,).then(parseJsonOrThrow<unknown>).then(normalizeDownloadTransportCapabilities).then((capabilities) => {+ if (generation !== downloadTransportCapabilitiesGeneration) {+ return capabilities;+ }downloadTransportCapabilitiesCache = {expiresAt: Date.now() + DOWNLOAD_TRANSPORT_CAPABILITIES_TTL_MS,capabilities,diff --git a/studio/frontend/src/features/hub/download-manager/transport-preference.ts b/studio/frontend/src/features/hub/download-manager/transport-preference.tsindex 3de56efd748..7b9aba7ed04 100644--- a/studio/frontend/src/features/hub/download-manager/transport-preference.ts+++ b/studio/frontend/src/features/hub/download-manager/transport-preference.ts@@ -171,21 +171,31 @@ export function useDownloadTransportCapabilities(): TransportCapabilitiesState {useEffect(() => {let cancelled = false;- getDownloadTransportCapabilities()- .then((capabilities) => {- if (cancelled) {- return;- }- setState({ capabilities, isLoading: false });- })- .catch(() => {- if (cancelled) {- return;- }- setState({ capabilities: null, isLoading: false });- });+ let latest = 0;+ const load = () => {+ // A slower answer from before a source switch must not overwrite the newer one.+ const request = ++latest;+ const stale = () => cancelled || request !== latest;+ getDownloadTransportCapabilities()+ .then((capabilities) => {+ if (stale()) {+ return;+ }+ setState({ capabilities, isLoading: false });+ })+ .catch(() => {+ if (stale()) {+ return;+ }+ setState({ capabilities: null, isLoading: false });+ });+ };+ load();+ // A model source switch announces itself here, and Xet availability depends on the source.+ const unsubscribe = subscribeDownloadTransportSettings(load);return () => {cancelled = true;+ unsubscribe();};}, []);diff --git a/studio/frontend/src/features/hub/index.ts b/studio/frontend/src/features/hub/index.tsindex a9badaa802d..b65740197f1 100644--- a/studio/frontend/src/features/hub/index.ts+++ b/studio/frontend/src/features/hub/index.ts@@ -2,6 +2,7 @@// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0export {+ clearDownloadTransportCapabilitiesCache,DOWNLOAD_KIND,DownloadProgressBar,downloadManager,diff --git a/studio/frontend/src/features/settings/api/hub-settings.ts b/studio/frontend/src/features/settings/api/hub-settings.tsindex 74d4360269f..9e919712ef0 100644--- a/studio/frontend/src/features/settings/api/hub-settings.ts+++ b/studio/frontend/src/features/settings/api/hub-settings.ts@@ -3,9 +3,11 @@import { fetchDeviceType } from "@/config/env";import { authFetch } from "@/features/auth";+import { clearDownloadTransportCapabilitiesCache } from "@/features/hub";import { markRemoteNetworkOnline } from "@/features/hub/lib/network";import { readFastApiError } from "@/lib/format-fastapi-error";import type { HubSource } from "@/lib/hf-endpoint";+import { loadDownloadTransportSettings } from "./download-transport";export type HubSettings = {hfEndpoint: string;@@ -59,6 +61,9 @@ export async function updateHubSource(source: HubSource): Promise<HubSettings> {throw new Error(await readFastApiError(res, "Failed to switch the model source"));}const saved = fromApi(await res.json());+ clearDownloadTransportCapabilitiesCache();+ // Its event also refreshes the hub's mounted transport toggle.+ await loadDownloadTransportSettings({ refresh: true }).catch(() => undefined);await followSavedEndpoints();return saved;}diff --git a/studio/frontend/tests/download-transport-source-switch.test.ts b/studio/frontend/tests/download-transport-source-switch.test.tsnew file mode 100644index 00000000000..2045b1bfc65--- /dev/null+++ b/studio/frontend/tests/download-transport-source-switch.test.ts@@ -0,0 +1,112 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import test from "node:test";++import { registerStoreStubResolver } from "./helpers/kit.ts";++registerStoreStubResolver();++// The transport settings store announces changes on window.+(globalThis as { window?: EventTarget }).window ??= new EventTarget();++const { setAuthFetchHandler } = await import("./helpers/store-stubs/auth.ts");+const {+ clearDownloadTransportCapabilitiesCache,+ getDownloadTransportCapabilities,+} = await import("../src/features/hub/download-manager/api.ts");+const { updateHubSource } = await import(+ "../src/features/settings/api/hub-settings.ts"+);+const { subscribeDownloadTransportSettings } = await import(+ "../src/features/settings/api/download-transport.ts"+);++const CAPS_URL = "/api/studio/download-transport-capabilities";+let source: "huggingface" | "modelscope" = "modelscope";+let capsCalls = 0;++function json(body: unknown): Response {+ return new Response(JSON.stringify(body), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ });+}++setAuthFetchHandler((input, init) => {+ const url = String(input);+ if (url.startsWith(CAPS_URL)) {+ capsCalls += 1;+ const xet = source === "huggingface";+ return json({+ http: { available: true, reason: null },+ xet: {+ available: xet,+ reason: xet ? null : "ModelScope does not offer Xet",+ },+ auto_resolves_to: xet ? "xet" : "http",+ auto_reason: null,+ });+ }+ if (url === "/api/settings/download-transport") {+ const xet = source === "huggingface";+ return json({+ mode: "auto",+ xet_available: xet,+ xet_unavailable_reason: xet ? null : "ModelScope does not offer Xet",+ auto_resolves_to: xet ? "xet" : "http",+ auto_reason: null,+ });+ }+ if (url === "/api/settings/hub/source") {+ source = JSON.parse(String(init?.body)).source;+ return json({+ hf_endpoint: "",+ datasets_server_follows_endpoint: false,+ source,+ active_source: source,+ });+ }+ return json({});+});++test("switching the model source drops the cached Xet verdict", async () => {+ clearDownloadTransportCapabilitiesCache();+ source = "modelscope";+ assert.equal((await getDownloadTransportCapabilities()).xet.available, false);++ await updateHubSource("huggingface");+ const before = capsCalls;+ const caps = await getDownloadTransportCapabilities();++ assert.equal(capsCalls, before + 1, "the ModelScope verdict was replayed");+ assert.equal(caps.xet.available, true);+});++test("an answer that lands after the switch is not cached", async () => {+ clearDownloadTransportCapabilitiesCache();+ source = "modelscope";+ const stale = getDownloadTransportCapabilities();+ clearDownloadTransportCapabilitiesCache();+ source = "huggingface";+ await stale;++ assert.equal((await getDownloadTransportCapabilities()).xet.available, true);+});++test("switching the model source refreshes mounted transport controls", async () => {+ source = "modelscope";+ const seen: boolean[] = [];+ const unsubscribe = subscribeDownloadTransportSettings((settings) => {+ seen.push(settings.xetAvailable);+ });+ await updateHubSource("huggingface");+ unsubscribe();++ assert.deepEqual(+ seen,+ [true],+ "the Settings row and hub toggle kept the ModelScope verdict",+ );+});diff --git a/studio/frontend/tests/helpers/hub-inventory-stub.mjs b/studio/frontend/tests/helpers/hub-inventory-stub.mjsindex bec8f5a0913..ebac7128164 100644--- a/studio/frontend/tests/helpers/hub-inventory-stub.mjs+++ b/studio/frontend/tests/helpers/hub-inventory-stub.mjs@@ -3,3 +3,4 @@// The hub barrel re-exports .tsx panels, which bare node cannot parse.export function bumpInventoryVersion() {}+export function clearDownloadTransportCapabilitiesCache() {}diff --git a/studio/frontend/tests/helpers/store-stubs/hub.ts b/studio/frontend/tests/helpers/store-stubs/hub.tsindex b5fbd666d05..fb5ffc5de79 100644--- a/studio/frontend/tests/helpers/store-stubs/hub.ts+++ b/studio/frontend/tests/helpers/store-stubs/hub.ts@@ -2,6 +2,7 @@// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0// Real logic, re-exported: only the barrel it normally comes from needs stubbing.+export { clearDownloadTransportCapabilitiesCache } from "../../../src/features/hub/download-manager/api.ts";export { EMBEDDING_TAGS } from "../../../src/features/hub/lib/hf-model-meta.ts";export { normalizeModelIdentity } from "../../../src/features/hub/lib/model-identity.ts";export { isGgufLike } from "../../../src/features/hub/lib/model-identifiers.ts";