Repository navigation
feat(install): fall back to CERNET and npmmirror when package hosts are blocked or slow - #11786
Conversation
install_node_prebuilt.py always fetched index.json, SHASUMS256.txt and the archive from nodejs.org. UNSLOTH_NODE_MIRROR now replaces that base for every Node dist URL; archives are still verified against the sha256 pins committed in node_prebuilt_pins.json, so a mirror cannot change what gets installed.
…re blocked or slow install.sh and studio/setup.sh now probe pypi.org, download.pytorch.org, nodejs.org and registry.npmjs.org in parallel (5 s connect, 10 s total) before the first package install. A host that fails the probe while its mirror passes is redirected through the env vars the package tools already read: PyPI to https://mirrors.cernet.edu.cn/pypi/web/simple, PyTorch wheels to UNSLOTH_PYTORCH_MIRROR=https://mirrors.cernet.edu.cn/pytorch/whl, Node.js to UNSLOTH_NODE_MIRROR=https://mirrors.cernet.edu.cn/nodejs-release, and npm to UNSLOTH_NPM_REGISTRY=https://registry.npmmirror.com. When pypi.org still answers but misses the budget, uv gets the mirror first and pypi.org second with UV_INDEX_STRATEGY=unsafe-first-match, and pip gets the mirror as PIP_INDEX_URL with pypi.org as PIP_EXTRA_INDEX_URL, so packages the mirror has not synced yet still resolve. When pypi.org does not answer at all, only the mirror is used: unsafe-first-match fetches every index and fails outright when one is unreachable. A host the user already redirected (UV_* / PIP_* index vars, an index in uv.toml or pip.conf, UNSLOTH_PYTORCH_MIRROR, UNSLOTH_TORCH_INDEX_URL, UNSLOTH_NODE_MIRROR, UNSLOTH_NPM_REGISTRY) is left alone, setup.sh skips the probe when install.sh already ran it, and UNSLOTH_MIRROR_FALLBACK=0 turns the fallback off.
…indows install.ps1 and studio/setup.ps1 get the same fallback as install.sh: pypi.org, download.pytorch.org, nodejs.org and registry.npmjs.org are probed in parallel, and a host that fails while its CERNET or npmmirror counterpart passes is redirected through the same env vars (UV_*/PIP_* index vars, UNSLOTH_PYTORCH_MIRROR, UNSLOTH_NODE_MIRROR, UNSLOTH_NPM_REGISTRY), with the same slow-versus-blocked PyPI split and the same respect for indexes the user already configured. The helpers live in the block shared with setup.ps1. The probe uses WebRequest.GetResponseAsync rather than HttpClient, which would need Add-Type, and sends a User-Agent because the CERNET mirrors answer 403 without one. On a session whose SecurityProtocol excludes TLS 1.2 it pins TLS 1.2 for the probe only. install.ps1 restores every variable the fallback may set when it exits, since under irm | iex they belong to the caller's session. setup.ps1 now computes its npm --registry args after the probe, so a fallback registry reaches every npm and bun install.
…en releases.astral.sh is blocked or slow
…leases.astral.sh is blocked or slow
…ows when releases.astral.sh is blocked or slow
…auncher heredoc The mirror fallback functions sat inside the quoted heredoc that writes the launcher script, so install.sh never defined them and aborted with "_mirror_fallback: not found" right before installing uv. Move the block next to its call and add a check that the block is outside every heredoc in install.sh and studio/setup.sh.
Each default package host is timed alone on a 1 MiB slice of an artifact it serves, and one below 1 MiB/s, or whose index does not answer, is raced against its mirror and swapped for it only when the mirror is faster and its own index answers. CERNET redirects each tree to a different university mirror, so each tree is timed on its own, and releases.astral.sh is timed once for both uv and its Python builds.
Ports the speed probe from install.sh to install.ps1 and studio/setup.ps1: each default host is timed alone on a 1 MiB slice of an artifact it serves, and one below 1 MiB/s, or whose index does not answer, is raced against its mirror and swapped for it only when the mirror is faster and its own index answers. Each probe uses a fresh connection and its own deadline, as a separate curl process would, and the probes raise Windows PowerShell 5.1's two-connections-per-host limit so the race's CERNET requests do not queue. The uv Python-builds mirror is dropped on Windows, where uv is always given a resolved interpreter.
…ough its mirror The mirror probe leaves healthy defaults alone. When a later step fails because the default host stopped answering (a timeout, reset, DNS or TLS error, a 5xx/429, or a download that stalled), the installers now rerun that step once through the host's mirror, after the step's own same-host attempts. The host is read from the failure output, or from the command when a stalled download names no URL; resolution, not-found and other hosts' failures are never retried, so try-then-fallback steps keep their own fallback. A host stays on its mirror for later steps only when the rerun succeeded. Covers install.sh's install commands, setup.sh's npm installs, install_python_stack.py's pip_install and pip_install_try, and the node and pinned uv downloads (only when no source served the file).
…iled through its mirror The Windows mirror fallback now exports the same spare list as the POSIX installers: one mirror per probed host still on its default. install.ps1 reruns a failed package install once through that host's mirror after its own attempts, only when the output shows a transport failure on that host (or a stalled download in a command that uses the default index). A torch mirror rewrites the default torch URLs the command reads, and a mirror is kept for later steps only when the rerun succeeds. studio/setup.ps1 does the same for the frontend and OXC npm installs, and retries the Node download and the pinned uv download (the latter only when no source answered). Every install_python_stack.py run on Windows gets the same retry through the exported list. The shared-helper sync script now also copies a new shared function that has no comment above it.
mirrors.cernet.edu.cn sends the PyPI simple index to a mirror that rate-limits uv's parallel metadata requests (429), failing resolves; tuna.mirrors.cernet.edu.cn serves the index and files from Tsinghua. The Node dist mirror moves to registry.npmmirror.com/-/binary/node, which keeps nodejs.org's layout (index.json, SHASUMS256.txt, archives), and is timed on its own tarball.
…r lacks A switched PyPI host now uses the mirror alone, also when pypi.org was only slow: uv's unsafe-first-match fetched every package from pypi.org too, so a pypi.org that dropped mid-install failed every step. When pypi.org still answered, a failed resolve that reports a version or package as not available (a fresh release the mirror has not synced yet) reruns once with pypi.org behind the mirror, and later steps keep that setup if the rerun works. Commands that pin their own index are left alone. install_python_stack.py classifies its installs the same way.
…irror lacks The Windows installers now match install.sh: a switched PyPI host uses the mirror alone, also when pypi.org was only slow, and when pypi.org still answered, an install whose resolve reports a version or package as not available reruns once with pypi.org behind the mirror, keeping that setup for later steps if it works. Commands that pin their own index or pass --no-index are left alone.
…he PyPI mirror uv reads uv.toml, or pyproject.toml with a [tool.uv] table, from the current directory or the nearest parent, and an exported UV_DEFAULT_INDEX overrides it. The mirror fallback only checked UV_CONFIG_FILE and the user and system uv.toml, so launching the installer from a project that configures its own index would redirect uv to the mirror. It now also checks the nearest project config, as install_python_stack.py's _uv_config_files does, and recognizes [[tool.uv.index]].
…ackages setup.sh and setup.ps1 ran the mirror speed probe at startup, so every unsloth studio update, even one with nothing to install, fetched a 1 MiB sample from each default package host. The probe now runs right before the Python dependency pass and before a Transformers sidecar is rebuilt, the update steps that download from PyPI and PyTorch. install.sh and install.ps1 still probe up front and pass the result on, so fresh installs are unchanged; a standalone update's Node, npm and uv steps use the default hosts, as before the mirror fallback.
pip_install now wraps _pip_install_once with the mirror retry, and the install itself, including its _effective_requirements call, lives in _pip_install_once.
…pip config pip also reads site config from the venv it runs in (<venv>/pip.conf, pip.ini on Windows). The mirror fallback only checked PIP_CONFIG_FILE and the user and global files, so a private index set in the Unsloth Studio venv was overridden by the exported PIP_INDEX_URL whenever the install fell back from uv to pip. The check now includes the venv's site config.
The mirror retry reads a failed command's output, so the verbose install arm copied it to a log with tee. install.sh otherwise needs no tee, and on a minimal image without it the pipe closed and the command died of SIGPIPE. The arm now falls back to cat there, which only costs that host the retry. The tests that lift run_install_cmd out of install.sh also lift the functions it now calls, and stub the mirror retry.
… skip the probe on a --local re-overlay With the probe moved to the Python dependency pass, a standalone setup reached its Node and npm downloads with no mirror retry armed. setup.sh and setup.ps1 now arm every host's one-shot mirror retry at startup without probing (_mirror_fallback spare / Invoke-MirrorFallback -SpareOnly), and still probe lazily before the first package download. setup.sh arms it from the directory its installs run in, once VENV_DIR is set, so the retry respects the same uv and pip config they do. A --local update runs the dependency pass every time to re-overlay the checkout, almost entirely from uv's cache, so on an existing venv that pass relies on the armed retries instead of probing every host first.
|
Codex review on the staging copy converged on head Staging CI on the same head (https://github.com/Lyxot/unsloth/pull/87/checks): 27 workflows passed, 1 skipped (Kaggle T4 GPU), 1 failed.
|
… race A registry set through NPM_CONFIG_REGISTRY / npm_config_registry outranks the frontend .npmrc today; the fallback exported UNSLOTH_NPM_REGISTRY, which becomes --registry and overrode it. Treat it as user configuration. The race re-timed the default artifact but reused the first-round default index result, so one index answer lost in the first round forced a healthy host into blocked mode. Probe the default index again beside the mirror's.
Outside mainland China the installers now behave as before the fallback: no probe, no mirror retries armed, nothing exported. Location is read without a network call: a mainland time zone (Asia/Shanghai and its aliases, Windows "China Standard Time"), or a resolver from a mainland public DNS or cloud (AliDNS, DNSPod, 114DNS, Baidu, CNNIC, Alibaba Cloud and Tencent Cloud internal resolvers), which covers UTC cloud VMs there. UNSLOTH_MIRROR_FALLBACK=1 opts in anywhere; =0 still opts out.
With no mirror retry armed (outside mainland China, or opted out): - run_install_cmd runs the plain runner, so set -e stops the installer where a command fails as before, and verbose output is not copied to a temp file through tee. - The PowerShell runners stream verbose output without buffering it, and the npm / install retries return before reading any output. - _mirror_retry in install_python_stack.py returns before decoding and scanning the failed output (183 ms for 1 MB of output before). - A retry state inherited from a parent process is dropped, so neither a stale _UNSLOTH_MIRROR_SPARE nor UNSLOTH_MIRROR_FALLBACK=0 can be bypassed. - setup.sh no longer changes directory (and OLDPWD) to arm the retries. The location is read once per process, resolvers come from .NET instead of Get-DnsClientServerAddress (no module or CIM load on Windows), and the 114DNS filtering resolvers plus DNSPod 182.254.116.116 / 119.28.28.28 count as mainland China. An interrupted install also removes a kept output copy.
…try sidecars - pip and uv read an index from every directory in XDG_CONFIG_DIRS; an index configured there now counts as user configuration, so the fallback no longer overrides it. - The Node install no longer retries through the mirror on exit 4 (permission denied), matching setup.ps1. - Transformers sidecar installs rerun once with pypi.org behind the mirror when the probe switched a slow pypi.org, as the dependency pass already does for a pin the mirror has not synced. All three only act when the fallback is on (mainland China or UNSLOTH_MIRROR_FALLBACK=1).
uv's own no-network switch (its spellings: 1, t, true, y, yes, on) now skips the speed probes and the mirror race; the one-shot retries stay armed, as they only follow a failed network command.
|
Review record for #11786, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#111. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
tests/studio/test_installer_av_shapes.py bans vendor names in shipped scripts, which are handed whole to scanners; the location check comment now describes the resolvers without naming the clouds.
…re blocked or slow (unslothai#11786) * feat(studio): let UNSLOTH_NODE_MIRROR rebase the Node.js dist downloads install_node_prebuilt.py always fetched index.json, SHASUMS256.txt and the archive from nodejs.org. UNSLOTH_NODE_MIRROR now replaces that base for every Node dist URL; archives are still verified against the sha256 pins committed in node_prebuilt_pins.json, so a mirror cannot change what gets installed. * feat(install): fall back to CERNET and npmmirror when package hosts are blocked or slow install.sh and studio/setup.sh now probe pypi.org, download.pytorch.org, nodejs.org and registry.npmjs.org in parallel (5 s connect, 10 s total) before the first package install. A host that fails the probe while its mirror passes is redirected through the env vars the package tools already read: PyPI to https://mirrors.cernet.edu.cn/pypi/web/simple, PyTorch wheels to UNSLOTH_PYTORCH_MIRROR=https://mirrors.cernet.edu.cn/pytorch/whl, Node.js to UNSLOTH_NODE_MIRROR=https://mirrors.cernet.edu.cn/nodejs-release, and npm to UNSLOTH_NPM_REGISTRY=https://registry.npmmirror.com. When pypi.org still answers but misses the budget, uv gets the mirror first and pypi.org second with UV_INDEX_STRATEGY=unsafe-first-match, and pip gets the mirror as PIP_INDEX_URL with pypi.org as PIP_EXTRA_INDEX_URL, so packages the mirror has not synced yet still resolve. When pypi.org does not answer at all, only the mirror is used: unsafe-first-match fetches every index and fails outright when one is unreachable. A host the user already redirected (UV_* / PIP_* index vars, an index in uv.toml or pip.conf, UNSLOTH_PYTORCH_MIRROR, UNSLOTH_TORCH_INDEX_URL, UNSLOTH_NODE_MIRROR, UNSLOTH_NPM_REGISTRY) is left alone, setup.sh skips the probe when install.sh already ran it, and UNSLOTH_MIRROR_FALLBACK=0 turns the fallback off. * feat(install): mirror fallback for blocked or slow package hosts on Windows install.ps1 and studio/setup.ps1 get the same fallback as install.sh: pypi.org, download.pytorch.org, nodejs.org and registry.npmjs.org are probed in parallel, and a host that fails while its CERNET or npmmirror counterpart passes is redirected through the same env vars (UV_*/PIP_* index vars, UNSLOTH_PYTORCH_MIRROR, UNSLOTH_NODE_MIRROR, UNSLOTH_NPM_REGISTRY), with the same slow-versus-blocked PyPI split and the same respect for indexes the user already configured. The helpers live in the block shared with setup.ps1. The probe uses WebRequest.GetResponseAsync rather than HttpClient, which would need Add-Type, and sends a User-Agent because the CERNET mirrors answer 403 without one. On a session whose SecurityProtocol excludes TLS 1.2 it pins TLS 1.2 for the probe only. install.ps1 restores every variable the fallback may set when it exits, since under irm | iex they belong to the caller's session. setup.ps1 now computes its npm --registry args after the probe, so a fallback registry reaches every npm and bun install. * feat(install): fall back to npmmirror for uv-managed Python builds when releases.astral.sh is blocked or slow * feat(install): install the pinned uv from a PyPI mirror wheel when releases.astral.sh is blocked or slow * feat(install): install the pinned uv from a PyPI mirror wheel on Windows when releases.astral.sh is blocked or slow * fix(install): define the mirror fallback outside the Unsloth Studio launcher heredoc The mirror fallback functions sat inside the quoted heredoc that writes the launcher script, so install.sh never defined them and aborted with "_mirror_fallback: not found" right before installing uv. Move the block next to its call and add a check that the block is outside every heredoc in install.sh and studio/setup.sh. * feat(install): pick mirrors by measured speed on real artifacts Each default package host is timed alone on a 1 MiB slice of an artifact it serves, and one below 1 MiB/s, or whose index does not answer, is raced against its mirror and swapped for it only when the mirror is faster and its own index answers. CERNET redirects each tree to a different university mirror, so each tree is timed on its own, and releases.astral.sh is timed once for both uv and its Python builds. * feat(install): pick Windows mirrors by measured speed on real artifacts Ports the speed probe from install.sh to install.ps1 and studio/setup.ps1: each default host is timed alone on a 1 MiB slice of an artifact it serves, and one below 1 MiB/s, or whose index does not answer, is raced against its mirror and swapped for it only when the mirror is faster and its own index answers. Each probe uses a fresh connection and its own deadline, as a separate curl process would, and the probes raise Windows PowerShell 5.1's two-connections-per-host limit so the race's CERNET requests do not queue. The uv Python-builds mirror is dropped on Windows, where uv is always given a resolved interpreter. * feat(install): retry a step whose default host's transport failed through its mirror The mirror probe leaves healthy defaults alone. When a later step fails because the default host stopped answering (a timeout, reset, DNS or TLS error, a 5xx/429, or a download that stalled), the installers now rerun that step once through the host's mirror, after the step's own same-host attempts. The host is read from the failure output, or from the command when a stalled download names no URL; resolution, not-found and other hosts' failures are never retried, so try-then-fallback steps keep their own fallback. A host stays on its mirror for later steps only when the rerun succeeded. Covers install.sh's install commands, setup.sh's npm installs, install_python_stack.py's pip_install and pip_install_try, and the node and pinned uv downloads (only when no source served the file). * feat(install): retry a Windows step whose default host's transport failed through its mirror The Windows mirror fallback now exports the same spare list as the POSIX installers: one mirror per probed host still on its default. install.ps1 reruns a failed package install once through that host's mirror after its own attempts, only when the output shows a transport failure on that host (or a stalled download in a command that uses the default index). A torch mirror rewrites the default torch URLs the command reads, and a mirror is kept for later steps only when the rerun succeeds. studio/setup.ps1 does the same for the frontend and OXC npm installs, and retries the Node download and the pinned uv download (the latter only when no source answered). Every install_python_stack.py run on Windows gets the same retry through the exported list. The shared-helper sync script now also copies a new shared function that has no comment above it. * fix(install): use TUNA's CERNET mirror and npmmirror for Node mirrors.cernet.edu.cn sends the PyPI simple index to a mirror that rate-limits uv's parallel metadata requests (429), failing resolves; tuna.mirrors.cernet.edu.cn serves the index and files from Tsinghua. The Node dist mirror moves to registry.npmmirror.com/-/binary/node, which keeps nodejs.org's layout (index.json, SHASUMS256.txt, archives), and is timed on its own tarball. * feat(install): fall back to pypi.org only for releases the PyPI mirror lacks A switched PyPI host now uses the mirror alone, also when pypi.org was only slow: uv's unsafe-first-match fetched every package from pypi.org too, so a pypi.org that dropped mid-install failed every step. When pypi.org still answered, a failed resolve that reports a version or package as not available (a fresh release the mirror has not synced yet) reruns once with pypi.org behind the mirror, and later steps keep that setup if the rerun works. Commands that pin their own index are left alone. install_python_stack.py classifies its installs the same way. * feat(install.ps1): fall back to pypi.org only for releases the PyPI mirror lacks The Windows installers now match install.sh: a switched PyPI host uses the mirror alone, also when pypi.org was only slow, and when pypi.org still answered, an install whose resolve reports a version or package as not available reruns once with pypi.org behind the mirror, keeping that setup for later steps if it works. Commands that pin their own index or pass --no-index are left alone. * fix(install): keep uv on a project-level index when falling back to the PyPI mirror uv reads uv.toml, or pyproject.toml with a [tool.uv] table, from the current directory or the nearest parent, and an exported UV_DEFAULT_INDEX overrides it. The mirror fallback only checked UV_CONFIG_FILE and the user and system uv.toml, so launching the installer from a project that configures its own index would redirect uv to the mirror. It now also checks the nearest project config, as install_python_stack.py's _uv_config_files does, and recognizes [[tool.uv.index]]. * fix(studio): probe package hosts only before a setup step downloads packages setup.sh and setup.ps1 ran the mirror speed probe at startup, so every unsloth studio update, even one with nothing to install, fetched a 1 MiB sample from each default package host. The probe now runs right before the Python dependency pass and before a Transformers sidecar is rebuilt, the update steps that download from PyPI and PyTorch. install.sh and install.ps1 still probe up front and pass the result on, so fresh installs are unchanged; a standalone update's Node, npm and uv steps use the default hosts, as before the mirror fallback. * test: expect _pip_install_once among the requirements-filter callers pip_install now wraps _pip_install_once with the mirror retry, and the install itself, including its _effective_requirements call, lives in _pip_install_once. * fix(install): leave pip on an index set in the Unsloth Studio venv's pip config pip also reads site config from the venv it runs in (<venv>/pip.conf, pip.ini on Windows). The mirror fallback only checked PIP_CONFIG_FILE and the user and global files, so a private index set in the Unsloth Studio venv was overridden by the exported PIP_INDEX_URL whenever the install fell back from uv to pip. The check now includes the venv's site config. * fix(install): keep a verbose install working on a host without tee The mirror retry reads a failed command's output, so the verbose install arm copied it to a log with tee. install.sh otherwise needs no tee, and on a minimal image without it the pipe closed and the command died of SIGPIPE. The arm now falls back to cat there, which only costs that host the retry. The tests that lift run_install_cmd out of install.sh also lift the functions it now calls, and stub the mirror retry. * fix(studio): arm the mirror retries before setup's first download and skip the probe on a --local re-overlay With the probe moved to the Python dependency pass, a standalone setup reached its Node and npm downloads with no mirror retry armed. setup.sh and setup.ps1 now arm every host's one-shot mirror retry at startup without probing (_mirror_fallback spare / Invoke-MirrorFallback -SpareOnly), and still probe lazily before the first package download. setup.sh arms it from the directory its installs run in, once VENV_DIR is set, so the retry respects the same uv and pip config they do. A --local update runs the dependency pass every time to re-overlay the checkout, almost entirely from uv's cache, so on an existing venv that pass relies on the armed retries instead of probing every host first. * Trim installer mirror fallback comments * Respect NPM_CONFIG_REGISTRY and recheck default indexes in the mirror race A registry set through NPM_CONFIG_REGISTRY / npm_config_registry outranks the frontend .npmrc today; the fallback exported UNSLOTH_NPM_REGISTRY, which becomes --registry and overrode it. Treat it as user configuration. The race re-timed the default artifact but reused the first-round default index result, so one index answer lost in the first round forced a healthy host into blocked mode. Probe the default index again beside the mirror's. * Only use the mirror fallback in mainland China Outside mainland China the installers now behave as before the fallback: no probe, no mirror retries armed, nothing exported. Location is read without a network call: a mainland time zone (Asia/Shanghai and its aliases, Windows "China Standard Time"), or a resolver from a mainland public DNS or cloud (AliDNS, DNSPod, 114DNS, Baidu, CNNIC, Alibaba Cloud and Tencent Cloud internal resolvers), which covers UTC cloud VMs there. UNSLOTH_MIRROR_FALLBACK=1 opts in anywhere; =0 still opts out. * Keep the installers byte-identical to before outside mainland China With no mirror retry armed (outside mainland China, or opted out): - run_install_cmd runs the plain runner, so set -e stops the installer where a command fails as before, and verbose output is not copied to a temp file through tee. - The PowerShell runners stream verbose output without buffering it, and the npm / install retries return before reading any output. - _mirror_retry in install_python_stack.py returns before decoding and scanning the failed output (183 ms for 1 MB of output before). - A retry state inherited from a parent process is dropped, so neither a stale _UNSLOTH_MIRROR_SPARE nor UNSLOTH_MIRROR_FALLBACK=0 can be bypassed. - setup.sh no longer changes directory (and OLDPWD) to arm the retries. The location is read once per process, resolvers come from .NET instead of Get-DnsClientServerAddress (no module or CIM load on Windows), and the 114DNS filtering resolvers plus DNSPod 182.254.116.116 / 119.28.28.28 count as mainland China. An interrupted install also removes a kept output copy. * Mirror fallback: honour XDG_CONFIG_DIRS, skip permission failures, retry sidecars - pip and uv read an index from every directory in XDG_CONFIG_DIRS; an index configured there now counts as user configuration, so the fallback no longer overrides it. - The Node install no longer retries through the mirror on exit 4 (permission denied), matching setup.ps1. - Transformers sidecar installs rerun once with pypi.org behind the mirror when the probe switched a slow pypi.org, as the dependency pass already does for a pin the mirror has not synced. All three only act when the fallback is on (mainland China or UNSLOTH_MIRROR_FALLBACK=1). * Trim mirror fallback comments * Mirror fallback: probe nothing when UV_OFFLINE is set uv's own no-network switch (its spellings: 1, t, true, y, yes, on) now skips the speed probes and the mirror race; the one-shot retries stay armed, as they only follow a failed network command. * Keep vendor names out of the installer comments tests/studio/test_installer_av_shapes.py bans vendor names in shipped scripts, which are handed whole to scanners; the location check comment now describes the resolvers without naming the clouds. --------- Co-authored-by: danielhanchen <[email protected]> Co-authored-by: Daniel Han <[email protected]>
Get-BlockSource took the Node exit handling from the first `$nodeExit = $LASTEXITCODE` to the next closing brace at that indent. unslothai#11786 put the mirror retry between the two, `if ($nodeExit -notin 0, 3, 4 -and (Use-MirrorSpare node)) { ... }`, so the slice ended at the retry's own brace. Merged with main, four of the five tests on a kept Node failed against a setup.ps1 that still has the branch they look for. The marker is now `$nodeExit -eq 3`, the chain's first line, once in setup.ps1. Against main's setup.ps1 the file still fails 11 of 22 (4, 3, 1, 3 and 0 by block), as it did at a09f376; with this branch's it passes 22.
…unslothai#10075) * studio: report a denied Node rename as a possible ACL fault, not a scanner _replace_with_retry retries `os.replace` on WinError 5, 32 and 145 and logs one message for all three: "a scanner is likely still holding the extracted files". WinError 5 is not only a scanner. It is equally what a tree with unreadable ACLs looks like, and that is a permission fault no backoff can clear. It matters most because `_swap_into_place` also uses this helper to move the EXISTING install aside, the tree a user is likeliest to have broken permissions on. In unslothai#9928 the same rename in the llama.cpp installer failed with (5) on every attempt and reported a scanner. The reporter's cause was corrupt ACLs -- icacls and Get-Acl both returned access-denied for the directory -- and `takeown /F ... /R /D Y` followed by `icacls ... /reset /T /C` fixed it. The Node helper carries the same three codes and the same message. 5 stays in the retry set: a scanner does raise it right after extraction. Only the reporting changes: the per-retry line offers both causes, and the takeown/icacls recovery prints once, when the budget is exhausted rather than on every attempt. WinError 32 and 145 keep their wording. The two commands go on separate lines for the reason tests/studio/install/test_setup_denied_install_tree.py pins -- on one line takeown swallows icacls as an argument. The constant and the recovery lines live in this module because it imports nothing outside the stdlib on purpose. Three tests extend the suite that already covers the helper. Two fail without the change: test_replace_names_acl_recovery_when_access_denied_persists and test_replace_does_not_blame_a_scanner_for_access_denied. test_replace_keeps_the_scanner_message_for_a_sharing_violation is a parity guard: 32 keeps its wording and prints no ACL guidance. One consequence worth naming: a 5 that really was a scanner now prints ACL guidance that does not apply to it, at the point the rename has already failed. Refs unslothai#9928. * studio: make ACL rename recovery actionable * studio: address ACL recovery review feedback * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * studio: stop reporting every blocked llama.cpp install as an active process setup.ps1 exits 3 when the existing llama.cpp install could not be replaced, and both sites that report it asserted an active llama.cpp process as the cause. Windows raises WinError 5 for a file another process holds open and for a tree whose ACLs are unreadable alike; is_busy_lock_error in studio/prebuilt_core.py classifies 5 as busy for exactly that reason, and _access_denied_recovery_lines prints takeown/icacls guidance for the ACL case. Write-LlamaFailureLog relays that guidance into the same block, so an ACL-denied user read repair commands bracketed by a headline and a retry hint that both named a process instead. Two sites, not one. The prebuilt exit-3 branch is the reported one; the local-directory link path carries the same three lines and says in its own comment that it mirrors the prebuilt handling, and that "Denied counts as surviving: unreadable is not gone" -- so it reaches the message by the same route and had to move with it. The classification is unchanged: exit 3 still means blocked, is_busy_lock_error still treats WinError 5 as busy, and the user is still told to close other llama.cpp users. Only the claim about which cause it was is dropped, in favour of naming both recoveries. whisper.cpp's exit-3 branch already reads "install busy; keeping existing runtime" and is the cause-neutral precedent followed here. Studio.Setup.BlockedInstallCause.Tests.ps1 pins it: 15 tests, 5 of which fail without this change, including a file-wide guard that neither phrase reappears at a third site and that every blocked-install site offers ACL repair. One consequence worth naming: the local-link path names the directory but cannot print the takeown/icacls lines, because it has no installer output to relay. It points at the ACLs on that path and leaves the commands to Write-PathAccessDenied, which already prints them wherever setup detects a denial up front. * studio: gate ACL retry guidance on helper output * studio: keep a running Node when its replacement stays denied The re-raise of a reported access denial sat ahead of install_prebuilt's keep-existing check, so a WinError 5 rename that outlasted the retries failed setup even when the Node already on disk still ran: exit 1, which setup.ps1 and setup.sh turn into "Could not install an isolated Node runtime". The re-raise was there for a real reason -- both scripts show the installer's output only on a non-zero exit, so a plain keep-existing return would have swallowed the takeown/icacls lines -- but the two goals conflicted only because exit 0 was silent. It no longer is. install_llama_prebuilt.py already exits 0 when it keeps the tree on disk after a transient failure, and setup.ps1 and setup.sh match its "keeping the existing complete install" line to warn "update unavailable, existing prebuilt kept". Node now takes the same shape: the reported denial reaches the keep-existing check like any other failure, a Node that still runs is kept with exit 0 on a line ending "keeping existing isolated Node", as the download-failure case already logs, and both scripts match that line, warn "update not applied, existing isolated Node kept", and relay the installer output when it carries takeown lines. The line names the rename instead of "Node download failed" when that is what failed. The warning is not llama.cpp's text, which test_pr10648_offline_and_status.py holds to exactly two keep arms. No new exit code, and nothing else moves: a Node that does not run, a forced reinstall, and a same-version install whose digest is not the pin still raise, exactly as they do for a failed download. setup.sh gets the arm for parity; its takeown branch can only fire on Windows output. test_install_prebuilt_keeps_existing_when_a_reported_denial_blocks_the_swap replaces test_install_prebuilt_does_not_hide_reported_acl_denial and fails without this change, when the swap's OSError escapes. The three cases of test_install_prebuilt_reraises_a_reported_denial_it_cannot_keep_existing_through are parity guards. Studio.Setup.BlockedInstallCause.Tests.ps1 gains a block on the setup.ps1 arm, four of its five tests failing without it, and tests/sh/test_setup_node_kept_existing.sh runs the real setup.sh block against a stand-in installer, three of its thirteen checks failing without it. One consequence worth naming: setup now carries on with a Node it could not replace, so a user can stay on an older runtime while setup succeeds, and the warning prints once per run. Refs unslothai#9928. * studio: offer the Node ACL repair only where the caller names the paths _replace_with_retry printed takeown/icacls for its source whenever a WinError 5 outlasted the retries, and flagged the exception as a reported denial, whoever called it. Since unslothai#10648 that includes atomic_replace_from_tempfile, which renames a temp file onto the downloaded archive and onto the install marker. A denial there named a temp file that is removed moments later, and the flag made the keep-existing line say the existing Node "could not be replaced" when the swap had never run. The repair lines and the flag now need access_denied_paths, which only _swap_into_place passes, for its three renames. A temp-file rename still retries the same budget and still raises; it only stops naming a path that will not exist, and a Node kept after it is logged as "Node download failed", as before. test_a_denied_marker_write_offers_no_repair_for_its_temp_file drives atomic_replace_from_tempfile into an exhausted 5 and fails without this change. test_replace_names_acl_recovery_when_access_denied_persists now passes its paths, as the callers that get the lines do. Refs unslothai#9928. * studio: describe the llama.cpp exit-3 repair gate by what it checks The comment above setup.ps1's llama.cpp exit-3 branch said "The helper prints takeown guidance only when access was denied", and the header of Studio.Setup.BlockedInstallCause.Tests.ps1 named _access_denied_recovery_lines as the source of llama.cpp's repair commands. Both described the installer half this PR carried before the llama.cpp message was left to unslothai#10182. On main no installer prints those lines: install_llama_prebuilt.py and prebuilt_core.py contain no takeown at all, and _access_denied_recovery_lines exists only in install_node_prebuilt.py. So the branch's `-match 'takeown /F'` arm is correct but cannot fire until unslothai#10182 lands, and both comments said it could. The gate stays, because it is what unslothai#10182's output needs, and without it the ACL repair hint would be offered to every busy install. Only the text changes: both comments now describe the check rather than a producer. Comments only, no assertion changes. Refs unslothai#9928 * tests: anchor the Node exit-chain Pester block on the chain itself Get-BlockSource took the Node exit handling from the first `$nodeExit = $LASTEXITCODE` to the next closing brace at that indent. unslothai#11786 put the mirror retry between the two, `if ($nodeExit -notin 0, 3, 4 -and (Use-MirrorSpare node)) { ... }`, so the slice ended at the retry's own brace. Merged with main, four of the five tests on a kept Node failed against a setup.ps1 that still has the branch they look for. The marker is now `$nodeExit -eq 3`, the chain's first line, once in setup.ps1. Against main's setup.ps1 the file still fails 11 of 22 (4, 3, 1, 3 and 0 by block), as it did at a09f376; with this branch's it passes 22. * studio: print the Node ACL repair only when the existing Node is kept Since unslothai#10533, a denied swap that cannot keep the existing Node reaches main() as a PermissionError and exits 4, and setup.ps1 answers exit 4 with Exit-PathAccessDenied: its own elevated takeown/icacls for the refused path and a note that antivirus can deny it too. _replace_with_retry had already printed ours, so that path showed two sets of repair commands for the same folder, with different icacls flags, around unslothai#10533's advice that elevation may not clear a security-software block. The lines now ride on the error and install_prebuilt logs them only in the branch that keeps a Node that still runs. That is exit 0, where setup.ps1 and setup.sh relay them on `takeown /F` and nothing else names a repair. "rename still blocked (5) after N attempts" still prints at the retry, so the exit-4 output keeps the rename's own record. Measured through main() with the real swap and a refused rename: exit 4 printed our four repair commands ahead of unslothai#10533's message, and now prints none, with the denied-path and denied-scope markers unchanged. A kept Node prints the same lines as before, ahead of "existing Node could not be replaced". test_a_denial_that_cannot_keep_node_leaves_the_repair_to_setup fails without this change; test_a_kept_node_prints_the_repair_setup_relays is a parity guard for the kept path. Four tests that read the lines from the log or checked the old flag, and the swap stand-in that set it, now use the error. One consequence worth naming: when the rollback of a failed forward rename is denied too, the repair lines naming the backup no longer print. The line "could not restore the previous Node install from <backup>" still names it, and the run exits 4. * Trim comments in the denied-rename reporting --------- Co-authored-by: Etherll <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>
@($null.Keys) is a one-item array holding $null, so the restore loop ran once with a null key and indexing threw, stopping the finally before the overrides file and UNSLOTH_KEPT_TORCH were cleaned up. Guard it the same way as the WoA resolver restore just above it. Production initialises MirrorEnvSaved before the try, so this only hardens the path. test_unsloth_torch_override.ps1 replays that finally and had been failing since #11786 added the restore, unnoticed because no CI job ran it. Cover both the nothing-saved and the saved-variables cases and run the test in the Windows inference smoke job with the other installer .ps1 tests.
Summary
In mainland China, pypi.org, download.pytorch.org, nodejs.org, registry.npmjs.org and releases.astral.sh are often blocked or run at a few hundred KB/s. A fresh Unsloth Studio install there either times out or takes hours downloading torch, Node, uv and Python builds. This PR makes
install.sh,studio/setup.sh,install.ps1andstudio/setup.ps1detect that and switch each affected host to a mirror. Healthy hosts are left untouched. The switch goes through the environment variables the package tools already read.https://tuna.mirrors.cernet.edu.cn/pypi/web/simplehttps://tuna.mirrors.cernet.edu.cn/pytorch/whl(UNSLOTH_PYTORCH_MIRROR)https://registry.npmmirror.com/-/binary/node(UNSLOTH_NODE_MIRROR)https://registry.npmmirror.com(UNSLOTH_NPM_REGISTRY)https://registry.npmmirror.com/-/binary/python-build-standaloneCERNET's
tuna.mirrors.cernet.edu.cnis a redirector. It sends each tree to a healthy university mirror, which gives failover beyond a single mirror.How it works
install.sh/install.ps1probe up front and pass the result tosetup.sh/setup.ps1. When setup runs on its own (unsloth studio update), it arms the one-shot mirror retries at startup without touching the network, and probes only right before a step that downloads Python packages (the dependency pass or a Transformers sidecar rebuild), so an update with nothing to install contacts no package host. A--localupdate, which re-runs the dependency pass from uv's cache every time, relies on the armed retries instead of probing.UV_DEFAULT_INDEX/PIP_INDEX_URL). pypi.org is deliberately not kept alongside it: uv'sunsafe-first-matchqueries every index for every package, so a pypi.org that drops mid-install would fail every later step.--index-url,--default-index,--no-index) never take this rerun.install.shinstall commands,setup.shnpm installs,install_python_stack.py'spip_install/pip_install_try, the Node download and the pinned uv download, plus the Windows equivalents.UV_*/PIP_*index vars, an index in anypip.confpip would read, including the Unsloth Studio venv's own, or in anyuv.toml/[tool.uv]uv would read, including the project config in the current directory or its nearest parent,UNSLOTH_PYTORCH_MIRROR,UNSLOTH_TORCH_INDEX_URL,UNSLOTH_NODE_MIRROR,UNSLOTH_NPM_REGISTRY) is never touched.UNSLOTH_MIRROR_FALLBACK=0disables the whole feature.install_node_prebuilt.pyhonoursUNSLOTH_NODE_MIRRORforindex.json,SHASUMS256.txtand the archive, but archives are still checked against the committednode_prebuilt_pins.jsonsha256 pins. A mirror therefore cannot change what gets installed.WebRequest.GetResponseAsync, which needs noAdd-Type.install.ps1restores every variable the fallback may set when it exits, because underirm | iexthey belong to the caller's session.setup.ps1byscripts/sync_shared_ps1_helpers.py.Risks and tradeoffs
unsloth studio updateswitches slow hosts only for its Python package downloads; its Node, npm and uv steps stay on the default hosts and fall back to a mirror only when a download fails.install.shandstudio/setup.shis byte-identical, and a test enforces it.Validation
Unit and contract tests (macOS; the PowerShell suite on pwsh 7 and on Windows PowerShell 5.1):
The two
test_dependency_pass_skips.pypip-bootstrap tests fail identically onmainin a uv-created venv without pip. They are unrelated to this change.End-to-end fresh installs from mainland China, each with an isolated home (
UNSLOTH_STUDIO_HOME) and run from outside any checkout, then an/api/healthcheck on the installed Unsloth Studio:--local--localchat_only: false--local --no-torch--localchat_only: false