Repository navigation
Make install.ps1 work with the user's PowerShell profile loaded - #8161
Conversation
Installing from a normal console failed where the same install from a console started with -NoProfile succeeded. A profile runs before `irm https://unsloth.ai/install.ps1 | iex` does and shares its scope, and that entry point has no script file to re-launch without it, so the individual couplings are cut instead. install.ps1, at the top of Install-UnslothStudio: - Set-StrictMode -Off. The script tests environment variables that are legitimately unset and reads $script: state only some branches assign, both of which a profile's `Set-StrictMode -Version Latest` turns into terminating errors. - $PSDefaultParameterValues is filtered down to proxy keys. An entry like 'Start-Process:WindowStyle' silently rebinds cmdlets here and fails the install with an error naming none of it. Proxy entries are kept because they can only ever enable a download, and on a locked-down host may be the only route to python.org and the uv release. - $PSNativeCommandUseErrorActionPreference = $false. With a profile turning it on, the "Stop" preference makes a failing native command throw out of the `unsloth studio setup` handoff instead of reaching Exit-InstallFailure, skipping rollback and the Tauri error record. All three assign without a scope qualifier, so they apply to the installer and everything it calls and leave the caller's session alone. uv is resolved once through Resolve-UvExecutable, which uses `Get-Command uv -CommandType Application -All` and falls back to the bare token when nothing is on PATH. PowerShell ranks aliases and functions above PATH, so a profile `Set-Alias uv ...` was answering the version probe and ending the install at "uv could not be installed" on machines that had a working uv. Test-UvVersionOk pins the executable that answered in $script:UvExe, and the 27 install scriptblocks invoke that path. $script:UvExe and $script:UvInstallDestDir are reset per invocation, since $script: is the caller's session under irm | iex. unsloth_cli/commands/studio.py passes -NoProfile to setup.ps1 unconditionally. It was only added when stdout was not a tty, which is never the case for the console install this fixes, so setup.ps1 ran under the profile with its own bare uv calls exposed. tests/test_installer_profile_hardening.py runs the extracted prologue and uv probe under a hostile profile and checks the caller's session is left intact. The four existing tests that anchored on the literal `uv venv $VenvDir` are re-anchored past the command token.
test_a_real_profile_reproduces_the_same_state failed on ubuntu-latest with every probed setting at its default, meaning the planted profile never loaded. It passed here and on macos-14. PowerShell resolves $PROFILE from $XDG_CONFIG_HOME when that is set and only falls back to $HOME/.config when it is not, and GitHub's ubuntu image writes XDG_CONFIG_HOME into /etc/environment. The fixture redirected HOME alone, so on a hosted runner the inherited value went on naming the real account and the profile was written to a path pwsh never opened. Setting XDG_CONFIG_HOME to the same directory HOME already implies reproduces the CI failure exactly on this machine, and removing it makes the failure go away. _hostile_env now redirects XDG_CONFIG_HOME alongside HOME, so the two rules agree whichever one the host applies, and the test asks pwsh for the path instead of hardcoding the fallback branch. The two guards are precise rather than blanket: a machine-wide profile loads into the real leg only, and a $PROFILE that lands outside the fixture cannot be planted into. Neither is reachable on Linux or macOS with the redirect in place. The other tests in the file never shared the premise; every other pwsh launch there passes -NoProfile and dot-sources the profile explicitly.
…gh $script:UvExe Deep validation of this branch turned up one merge hazard and four comments that do not survive checking against the live indexes. The install call was the only bare `uv` left in install.ps1 once #8161 lands. That branch rewrites every other invocation to `& $script:UvExe` so a profile alias named uv cannot capture them, and the two branches merge cleanly with zero conflict markers -- so git would silently reintroduce the one hole #8161 exists to close. Resolve through the variable when something has set it, and fall back to the bare name otherwise, so the call is correct on this branch alone and correct after the merge. Get-Variable rather than a bare read keeps the lookup safe under a profile's Set-StrictMode. The comment claiming no cu118 / cu121 / cu124 win_amd64 xFormers wheel exists is wrong; cu124/xformers-0.0.28.post1-cp312-cp312-win_amd64.whl is live. The real reason those families are absent is that they all stop before the cp39-abi3 switch at 0.0.31, so their wheels are one file per interpreter and the single filename template cannot name them. "Every cuXXX-torchYYY extra has carried win_amd64 rows since cu124-torch240" is likewise wrong: the cu118 and cu121 rows carry none and cu130onlytorch280 is empty. And the suggested `pip install "unsloth[cu130-torch2100]"` is not enough on its own -- the extra pins xFormers by URL but pins no torch, and PyPI's Windows torch is 2.10.0+cpu with cuda None, so without --index-url it lands a cu130 extension beside a CPU torch: the same mismatch, inverted. Linux aarch64 gets a platform tag, so it never reaches the "this platform has no xFormers wheel" refusal that names it. It lands on the other one, which reported only torch and CUDA and so read as "upstream never built this pair" when the truth is "not for this arch". Name the platform there and stop claiming aarch64 in the branch it cannot reach. Finally, record why a mismatched xFormers that is ALREADY installed is not repaired here: find_spec sees it and returns before the matched-wheel block. Repairing under _generate_lock would mean a 100 MB download blocking unload and cancel, on a package the user may have pinned deliberately. install.ps1 does that repair outside any request. What this path prevents is Studio creating the mismatch, which is how it was made.
…dule autoloading
Validating the profile hardening against real pwsh turned up three things the
first pass missed. Six of the nineteen hostile-profile scenarios I exercised
are genuinely broken on main and genuinely fixed by this branch, so the shape
of the fix is right -- these are gaps in its coverage, not a change of
direction.
Resolve-UvExecutable still handed back the bare token when nothing named uv
was on PATH. That was meant to keep a working non-Application uv working, but
it reopens the exact hole the function exists to close: a profile
`function uv { Write-Output "uv 99.0.0" }` clears the version gate, gets
pinned into $script:UvExe, and then receives every install command the script
runs, with the user's torch, index URL and venv path as arguments. The
existing test missed it because its hostile alias reports no version at all,
and an alias to a missing file fails loudly. Follow an alias as far as an
Application and return that resolved path, since aliasing uv at a specific
build is a legitimate thing to do; return $null for anything else, which puts
the caller back on its install-uv branch and the gate re-probes against the
real thing.
winget had the identical defect and was left untouched. It is detected with a
bare Get-Command and invoked as a bare token at five sites, and it is what
installs both Python and uv -- so a `function winget` wrapper, which people
write to inject --accept-* or pin a source, owns the whole bootstrap. Same
treatment: resolve once to an Application and invoke through the path.
A profile setting $PSModuleAutoLoadingPreference to 'None' is fatal here and
was not covered. PowerShell 7 loads no modules at startup, so that one line
removes Test-Path, Write-Host, Select-Object, ConvertFrom-Json, Get-FileHash,
Invoke-WebRequest, Expand-Archive, Start-Process and Get-Content, and the
script dies on its first step naming a cmdlet the reader assumes is always
there. Windows PowerShell 5.1 preloads Utility and Management and survives,
which is exactly what makes this reproduce on one machine and not another.
Also: use [regex]::IsMatch in the defaults filter so it leaves no $Matches
behind; add -NoProfile unconditionally in _refresh_desktop_shortcuts, which
launches install.ps1 and had it gated on the hidden branch, so the visible
console path -- the one where a profile IS loaded -- was the one that missed
it; and record that the preserved proxy defaults do not reach setup.ps1,
which is launched with -NoProfile, along with why that trade is accepted.
Tests: the assertion that the bare token must come back now asserts the
opposite, and there are new ones for a convincing uv function, an alias to a
real uv, the winget call sites and the autoloading reset. The two new pwsh
tests execute against a genuinely planted profile rather than reading source.
…tall.ps1 install.ps1 deliberately keeps proxy-shaped $PSDefaultParameterValues entries out of the profile table it discards, because on a locked-down corporate host that entry can be the only route out. Adding -NoProfile to the setup launch unconditionally then threw them away one process later, and setup.ps1 downloads on its own: the VC++ runtime through Invoke-WebRequest and the uv installer through Invoke-RestMethod. A PowerShell variable does not cross a process boundary, so the kept entries travel as JSON in _UNSLOTH_PS_PROXY_DEFAULTS and the child re-applies them before running setup.ps1. Nothing else from the profile comes with them. A credential is left behind on purpose: PSCredential does not survive ConvertTo-Json, and the environment is the wrong place for one. A stale variable is cleared when there is nothing to hand off. Three tests, one static and two driving real pwsh, covering the round trip, the credential and non-proxy keys being dropped, and the prelude staying silent when the variable is absent, empty or corrupt.
…d the standalone update Five follow-ups, all on the handoff added last round. The handoff serializes with ConvertTo-Json, from Microsoft.PowerShell.Utility, and ran before the module-autoloading reset. Under a profile's $PSModuleAutoLoadingPreference = 'None' a fresh PowerShell 7 session therefore died right there, taking out the one configuration the handoff exists to support. The reset moves to the front of the prologue. The key filter was a case-sensitive .NET regex, but cmdlet and parameter names bind case-insensitively, so 'invoke-webrequest:proxy' was dropped. And [uri] is the type the Proxy parameter actually takes, so a careful profile assigns one; the serializer accepted only string and bool, and it disappeared at the process boundary. Both are accepted now, a uri by its AbsoluteUri. A PSCredential is still deliberately left behind. Under "irm ... | iex" the prologue runs in the caller's own session, so writing the environment variable there outlived the install on every path, early returns included, and a later `unsloth studio update` from that console would reapply stale JSON over a proxy that had since changed. The prologue now holds the value and it is published around the setup child only, saved and restored beside the other child-scoped variables. A standalone `unsloth studio update` has no installer above it, so there was nothing to restore and -NoProfile left it with no route out. It now asks: a throwaway PowerShell that does load the profile prints just the proxy-shaped defaults as JSON, validated before use, entirely best effort. Same filter as install.ps1's. Five tests, two driving real pwsh, including one against a profile with strict mode on, autoloading off, a lowercase key and a uri value.
- the standalone update probed powershell.exe only, so a proxy living in the PowerShell 7 profile never reached the -NoProfile child; both editions are asked now, the caller's first, and their answers merged. - Resolve-UvExecutable checked PATH before the alias, which is the reverse of PowerShell's own resolution and made the alias branch unreachable on any machine with some uv on PATH. - the parity workflow did not run this suite when unsloth_cli/commands/studio.py changed, though the suite asserts that module directly. Its own path-filter parser also treated a comment inside the list as the end of it, which would have hidden the addition.
… PowerShell does Three tests in the profile-hardening suite import unsloth_cli.commands.studio to drive the profile probe directly, and that pulls typer, pyyaml, pydantic and click. The job installed pip and pytest only, so on a clean setup-python both matrix legs died with ModuleNotFoundError before a single test ran. Installed, with a test that keeps the step in step with what the suite imports. $PSDefaultParameterValues keys are case-insensitive and a Python dict is not, so "Invoke-WebRequest:Proxy" from the caller's own host and "invoke-webrequest:proxy" from the other one both crossed over; the prelude then replayed them in order and the lower-priority host's value landed last, reversing the earlier-host-wins rule this merge exists for. Keys are folded now, first spelling seen wins, within one profile's answer as well as across two.
# Conflicts: # .github/workflows/cross-platform-parity-ci.yml # install.ps1
…erves (#8156) * Bound the Windows xFormers pin and document the CUDA-matched route The `windows` extra resolved `xformers>=0.0.22.post7` from PyPI with no upper bound and no index. PyPI publishes exactly one win_amd64 flavour of xFormers, built against CUDA 12.8 (0.0.34's cpp_lib.json reads `torch 2.10.0+cu128`), so next to the cu130 torch install.ps1 pulls from download.pytorch.org the xformers/_C.pyd fails torch.ops.load_library and _cpp_lib.py turns that into a warning: memory-efficient attention, SwiGLU and the sparse ops all disappear while the import still reports success. Unbounded, the same spec now resolves to 0.0.35, which is published as a py39-none wheel with no compiled extension at all (2.6 MB vs 103 MB) and whose torch>=2.10 floor lets pip drag a pinned torch forward. Bound the fallback and document the route that IS CUDA-matched on Windows: the cuXXX-torchYYY extras, every one of which has carried win_amd64 rows since cu124-torch240. Verified live on download.pytorch.org (HTTP 200) for cu126/cu128/cu130 x xformers 0.0.33.post1 / 0.0.33.post2 / 0.0.34, and read cpp_lib.json back out of the cu128 and cu130 0.0.34 wheels to confirm they really are built for 2.10.0+cu128 and 2.10.0+cu130 respectively. * install.ps1: install the xFormers wheel built for the torch it installed install.ps1 never mentioned xFormers. It installed torch from a cu126 / cu128 / cu130 index and then plain `unsloth`, leaving xFormers to whatever pip resolved later -- and PyPI publishes exactly one win_amd64 flavour, built against CUDA 12.8. On a cu130 host that is the NVIDIA QA report verbatim: "xFormers was built for PyTorch 2.10.0+cu128 with CUDA 1208 (you have 2.10.0+cu130)", after which xformers/_cpp_lib.py logs a warning and drops memory-efficient attention, SwiGLU and the sparse ops while the import still succeeds. Select the wheel from the CUDA family the resident torch actually carries and install it from the same index the torch install used, so UNSLOTH_TORCH_INDEX_URL / UNSLOTH_TORCH_INDEX_FAMILY / UNSLOTH_PYTORCH_MIRROR keep working unchanged. Additive and best-effort: no wheel for this (torch, CUDA) pair means install nothing rather than a mismatch, a failed install warns and the run continues on torch SDPA, and UNSLOTH_SKIP_XFORMERS=1 opts out. Three details that are easy to get wrong: - The step runs after the torch flavor repair, which can itself reinstall torch from a different index. - xFormers publishes one wheel per exact torch PATCH (2.9.0 -> 0.0.33.post1, 2.9.1 -> 0.0.33.post2, 2.10.0 -> 0.0.34), so the table is keyed on the full release, not the minor. - cu126, cu128 and cu130 all publish the SAME xformers version string, so a wrong-CUDA wheel is invisible to a version check. The repair reads the resident xformers/cpp_lib.json (the same metadata xFormers quotes in its own error) and force-replaces the package when it disagrees. Every row in the table was HEAD-verified live on download.pytorch.org and its cpp_lib.json read back. install.ps1 parses clean under [System.Management.Automation.Language.Parser]::ParseFile, and the new selector tests execute the extracted helpers under pwsh. * wheel_utils: resolve CUDA-matched xFormers wheels, Windows included linux_wheel_platform_tag() returned None for Windows, so nothing in the backend could resolve a Windows wheel URL at all. Rename it to wheel_platform_tag() and emit win_amd64, since download.pytorch.org does publish CUDA-matched win_amd64 xFormers wheels. Both call sites were inside this module, but probe_torch_wheel_env() is a real behaviour risk: its three production callers all resolve flash-attn / causal-conv1d / mamba-ssm assets, and those upstreams publish no win_amd64 wheels, so returning an env on Windows would only build 404s. Windows is therefore opt-in there via include_windows, leaving every existing caller byte-identical. Add the resolver: torch release + torch.version.cuda -> the exact download.pytorch.org wheel. The probe payload grows torch_version and cuda_version because neither existing key can pick the right wheel -- xFormers publishes one wheel per torch PATCH (2.9.0 -> 0.0.33.post1, 2.9.1 -> 0.0.33.post2) and per CUDA MINOR (cu126 and cu128 are different builds carrying the same version string). Unlisted pairs resolve to None so callers install nothing; serving a neighbouring CUDA family is the bug, not the fallback. * diffusion: stop installing an unpinned xFormers on demand The on-demand backend installer ran `pip install --only-binary :all: --no-deps xformers`, with no version and no index. Three things then line up badly: - PyPI publishes exactly one win_amd64 xFormers flavour, built against CUDA 12.8, so a cu130 host installs a mismatched extension every time. - --no-deps deliberately stops pip from ever reading the wheel's `Requires-Dist: torch==X`, so nothing checks the pairing. - the failure is SILENT. torch.ops.load_library raises, xformers/_cpp_lib.py catches it and logs a warning, and the import still succeeds -- so find_spec reports the backend as present while memory-efficient attention, SwiGLU and the sparse ops are all gone. The old comment ("An ABI mismatch just fails to import") described the flash-attn case, not this one. Unbounded also means 0.0.35 today, which ships no compiled extension at all. Resolve the exact download.pytorch.org wheel for the running torch build and install that URL, or refuse. Refusing is the point: no matched wheel means no install, the caller stays on torch SDPA, and the reason comes back from _ensure_attention_backend_installed (previously -> None) so it is reportable rather than only logged. Like the kernels/hub gate this is a policy refusal, so it records nothing in _INSTALL_ATTEMPTED. This changes Linux too, and deliberately: the same PyPI cu128 build lands beside a cu130 Linux torch. Torch versions with no published wheel (2.11, 2.12) now refuse instead of installing 0.0.35, which diffusers would accept at set time and then fail inside the denoise loop. Verified end to end against the real torch in this checkout (2.9.1+cu128 -> cu128/xformers-0.0.33.post2-cp39-abi3-manylinux_2_28_x86_64.whl, live HEAD). * wheel_utils: do not build xFormers URLs that 404 on pre-abi3 rows Self-review caught this: enumerating every URL the matrix can produce and HEAD-checking all 44 found 4 dead ones. xFormers only switched to a single cp39-abi3 wheel at 0.0.31; the 0.0.30 row (torch 2.7.0) publishes one wheel per interpreter and stops at cp312, so a 3.13 host built a URL that does not exist. Gate the pre-abi3 branch on the interpreter range those wheels actually cover. diffusion_attention already url_exists-gated before installing, so this was not user visible, but xformers_wheel_url is a public helper and should not hand a caller a dead link. Add the enumerate-and-HEAD check as a test so no future row can be added without a live wheel behind it: a 404 fails (that row is wrong), a network outage skips, matching tests/version_compat/_fetch.py. * Fix issues found in review: two false claims and three real defects Two things I had written down were wrong. I inferred both from wheel sizes instead of opening the wheels; a reviewer opened them. - xFormers 0.0.35 DOES ship a compiled extension. cu130's py39-none wheel carries a 19.4 MB xformers/_C.pyd and a cpp_lib.json reading {"cuda":1300,"torch":"2.10.0+cu130"}; cu128's carries an 8.4 MB one. The 103 MB -> 2.6 MB drop is the bundled flash_attn_3/_C.pyd going away, not the extension. The real hazard is narrower and still worth the pin: 0.0.35's extension is built for torch 2.10.0 while its metadata asks only for torch>=2.10, so pip may pair it with a torch it cannot load. 0.0.34 declares torch==2.10.0, an exact pair. - PyPI's WINDOWS torch has no CUDA at all. torch 2.10.0's win_amd64 wheel reports __version__ '2.10.0+cpu' with cuda = None; only the Linux wheel is +cu128. So `unsloth[windows]` cannot produce a working CUDA xFormers on any PyPI-only install, which strengthens rather than weakens the case for the cuXXX-torchYYY route. Real defects: - install.ps1 keyed the index leaf off $TorchIndexUrl, and the comment claimed the flavor repair had already reconciled it with the resident torch. It has not: the repair is skipped when the expected tag is 'cpu' or unrecognised, so a migrated venv can hold a +cu128 torch while the leaf says /cpu -- and whl/cpu serves only xformers 0.0.22.post4, with --default-index leaving no fallback. Derive the leaf from the resident torch, reusing $TorchIndexUrl (and any custom mirror) only when it already points at that family. - Get-InstalledXformersBuild compared only the build tag, so a resident 0.0.35 matching the torch made the step print "xFormers 0.0.34 already matches" and skip. Compare version AND build tag. - The torch 2.7.0 / xFormers 0.0.30 row predates the abi3 switch: one wheel per interpreter, stopping at cp312, while this installer defaults to Python 3.13. wheel_utils had a guard for it, install.ps1 did not. Drop the row from both rather than carry two per-interpreter gates for a torch that resolves to nothing on the default install. Also from review: resolution no longer HEAD-checks the URL (it can run under _generate_lock, since the video loader has no out-of-lock pre-install hop), the probe timeout drops 120s -> 30s to match the other probe_torch_wheel_env callers, only DETERMINISTIC refusals are memoised so one probe timeout cannot disable xFormers for a whole session, the memo takes a lock, the wheel filename tag is a verified range instead of an open-ended floor, and the backend test suite pins UNSLOTH_DIFFUSION_ATTENTION_INSTALL=0 so no future test can shell out to a real pip. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Correct four wheel-matrix claims and route the xFormers install through $script:UvExe Deep validation of this branch turned up one merge hazard and four comments that do not survive checking against the live indexes. The install call was the only bare `uv` left in install.ps1 once #8161 lands. That branch rewrites every other invocation to `& $script:UvExe` so a profile alias named uv cannot capture them, and the two branches merge cleanly with zero conflict markers -- so git would silently reintroduce the one hole #8161 exists to close. Resolve through the variable when something has set it, and fall back to the bare name otherwise, so the call is correct on this branch alone and correct after the merge. Get-Variable rather than a bare read keeps the lookup safe under a profile's Set-StrictMode. The comment claiming no cu118 / cu121 / cu124 win_amd64 xFormers wheel exists is wrong; cu124/xformers-0.0.28.post1-cp312-cp312-win_amd64.whl is live. The real reason those families are absent is that they all stop before the cp39-abi3 switch at 0.0.31, so their wheels are one file per interpreter and the single filename template cannot name them. "Every cuXXX-torchYYY extra has carried win_amd64 rows since cu124-torch240" is likewise wrong: the cu118 and cu121 rows carry none and cu130onlytorch280 is empty. And the suggested `pip install "unsloth[cu130-torch2100]"` is not enough on its own -- the extra pins xFormers by URL but pins no torch, and PyPI's Windows torch is 2.10.0+cpu with cuda None, so without --index-url it lands a cu130 extension beside a CPU torch: the same mismatch, inverted. Linux aarch64 gets a platform tag, so it never reaches the "this platform has no xFormers wheel" refusal that names it. It lands on the other one, which reported only torch and CUDA and so read as "upstream never built this pair" when the truth is "not for this arch". Name the platform there and stop claiming aarch64 in the branch it cannot reach. Finally, record why a mismatched xFormers that is ALREADY installed is not repaired here: find_spec sees it and returns before the matched-wheel block. Repairing under _generate_lock would mean a 100 MB download blocking unload and cancel, on a package the user may have pinned deliberately. install.ps1 does that repair outside any request. What this path prevents is Studio creating the mismatch, which is how it was made. * Record what the wheel matrix over-approximates, and correct the 0.0.35 history Three more comments that do not survive checking against the published artifacts. All comment-only; no behaviour changes. "PyPI publishes only the CUDA-12.8 flavour" is true of 0.0.34 and 0.0.35 but reads as an invariant, and it is not one: the single PyPI win_amd64 wheel has been cu124 at 0.0.29.post2, cu126 at 0.0.30, cu128 at 0.0.32, cu130 at 0.0.33 and cu128 again from 0.0.33.post1. That churn is a better argument for resolving a URL than the fixed-flavour version was. Worth recording too that cpp_lib.json's `cuda` is the NVCC toolkit version and not torch's family -- the cu126 0.0.34 wheel also reports 1208, so only the `torch` field separates the flavours, which is the field this resolver already keys on. 0.0.35 did not move its extension behind torch.ops.load_library; 0.0.34 loads through exactly the same call, and the two _cpp_lib.py files are identical. What changed is setup.py dropping py_limited_api=True in favour of a custom bdist_wheel that force-tags py39-none, on the stated grounds that the extension never bound the CPython ABI at all -- which holds up: its _C.so defines no PyInit and references no Py* symbol. Finally, name the two places the table is deliberately stricter or narrower than the ABI requires, so neither gets "fixed" by interpolation. Keying on the CUDA minor is stricter than needed -- the cu126 and cu128 extensions have identical undefined-symbol sets and both link libcudart.so.12, and only a major bump changes that -- but the minor names a real index directory, so an exact hit is what guarantees the URL exists. And the table stops at torch 2.10.0 because upstream does: 2.11 through 2.13 are released, 0.0.35 declares torch>=2.10 yet every published 0.0.35 wheel was compiled against 2.10.0, and only the unreleased 0.0.35.dev1130 targets 2.11. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Stop capping xFormers below 0.0.35, and map torch 2.11+ onto it The cap was wrong. I bounded the windows extra at <0.0.35 on the reasoning that 0.0.35 declares torch>=2.10 while its extension is built for 2.10.0, so pip could pair it with torch 2.11 and recreate the mismatch this branch exists to fix. Upstream says that pairing is supported. v0.0.34's notes record the migration to the PyTorch stable API/ABI, "which means that binary builds targeting PyTorch 2.10+ will be compatible with any later version", and 0.0.35's loosened pin plus its py39-none tag are both consequences of that, not oversights. The cap also cost more than it bought. 0.0.34 pins torch==2.10.0 exactly, so anyone on 2.10.1 could install no xFormers at all. The axis that has to match is the CUDA family, which the extra cannot see and install.ps1 already handles. Verified from the wheels rather than inferred: every PyPI wheel, 0.0.34 and 0.0.35 alike, reports cuda 1208 / torch 2.10.0+cu128, while the cu130 wheels report cuda 1300. Only the cu130 build carries Blackwell SASS -- cu126 and cu128 stop at 9.0a, so on sm_100 or sm_120 they have no native kernels and fall back to PTX JIT from 8.0+PTX. Both selector tables gain 2.11.0, 2.12.0 and 2.13.0 rows mapping to 0.0.35, keyed per release so an unknown torch still resolves to nothing rather than borrowing a neighbour's wheel. All six 0.0.35 URLs the tables can emit return 200. Two test docstrings asserted 0.0.35 was extension-less and shipped no cpp_lib.json. Both are false: the PyPI wheel carries an 8.2 MB _C.pyd and the cu130 wheel a 19 MB one, and every release from 0.0.31 on ships cpp_lib.json. The 103 MB to 2.6 MB drop was the bundled flash_attn_3 kernels going away. * Resolve xFormers for the torch that is actually installed, not just the listed ones - an exact-key matrix refuses every patch release published after it ships, so 2.10.1 / 2.11.1 / 2.12.1 got no xFormers at all; above the stable-ABI floor the answer is known without a row, in both selectors. - the direct wheel URL hard-coded download.pytorch.org, the one path in the installer stack that ignored UNSLOTH_PYTORCH_MIRROR. - install.ps1 threw away an explicitly pinned index whose leaf did not happen to name the CUDA family, which is exactly what a documented full-URL override looks like. - an unpinned install now goes through the direct wheel URL: --default-index does not make an index exclusive, and cu126 / cu128 / cu130 share a version string, so UV_INDEX could still supply the wrong-CUDA artifact. - the already-installed check compared the wheel's recorded build target against the resident torch, so a correct 0.0.35 was force-reinstalled on every run. - the live wheel sweep treated any HTTP status as a dead row, failing the suite on a 429 from the CDN. - and the two torch 2.11 refusal cases were stale as of the new matrix. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Build the direct wheel URL for a family pin, and keep mirror credentials out of the log UNSLOTH_TORCH_INDEX_FAMILY sets $TorchIndexPinned as well, so a plain cu130 pin took the --default-index path. uv's --index / UV_INDEX are used "in addition to" the default index, and cu126 / cu128 / cu130 publish the same xFormers version string, so a machine-level UV_INDEX could satisfy the pin with a wheel from the wrong CUDA family -- the silent extension failure this step exists to prevent. A family pin names a leaf, so it can have a direct URL; only a full UNSLOTH_TORCH_INDEX_URL override, which may be an authenticated mirror nothing here can rebuild, still goes through the index. And UNSLOTH_PYTORCH_MIRROR is allowed to carry userinfo or a token. The Studio on-demand path bakes it into the wheel URL and then logged that URL verbatim as the package name, so the first install (or failed install) wrote the secret into the backend log. pip still gets the real URL; the log gets a redacted one, and pip's stderr is put through the same filter because pip echoes back what it was handed. Same rule as the installer's Remove-IndexUrlCredentials: no userinfo, no query, no fragment. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address the wheel URL under a full-URL override, and keep a query-token mirror usable Two ways the wrong wheel could still be installed, or none at all. A full UNSLOTH_TORCH_INDEX_URL override went to --default-index, which uv does not treat as exclusive: --index / UV_INDEX are used "in addition to" it, and cu126 / cu128 / cu130 all publish the same xFormers version, so a machine-level index could satisfy the pin from the wrong family. When the override names a CUDA leaf -- the documented shape -- the wheel is addressed under it directly instead. A mirror root whose leaf is not a family still has to be resolved, and for that one call UV_INDEX and UV_EXTRA_INDEX_URL are cleared, in a finally, so the chosen index really is the only one. And a mirror may authenticate by query string. Appending "/cu130/..." after the query put the wheel path inside the token value, leaving the request path at /whl -- so the tokenized private mirror UNSLOTH_PYTORCH_MIRROR exists for was the one shape that could not resolve a wheel at all. Both sides join before the ?/# now: join_wheel_url in Python, Join-UrlPath in the installer, with the PowerShell one exercised through pwsh. --------- Co-authored-by: Daniel Han <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…amily Three fixes from the review round: The serialized handoff lived in $script:, which under the documented irm | iex path is the caller's session scope, and the only cleanup ran after the setup child. Dozens of exits return earlier -- ShortcutsOnly, an argument error, lock contention, a failed dependency install -- so an authenticated proxy URI stayed readable in that console. It is a function-local now, which dies with the frame on every path including a throw. install.ps1 serialized that record through a bare ConvertTo-Json, which a profile alias or function shadows exactly as it does in the probe. Module qualified. The cmdlet-ownership check compared two wildcard patterns as strings, and Invoke-Web* and *-WebRequest both apply to Invoke-WebRequest while neither matches the other. Two patterns are now assumed to overlap: the cost is a second host's unrelated wildcard entry going unmerged, against handing setup a credential setting from a profile that never asked for one.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e865593b39
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "if ($__unslothHostProfileName) { " | ||
| "$__unslothProfiles += (Join-Path (Split-Path -Parent $PROFILE.AllUsersCurrentHost) " | ||
| "$__unslothHostProfileName) }; " | ||
| "$__unslothProfiles += $PROFILE.AllUsersCurrentHost; " |
There was a problem hiding this comment.
Load only the caller's current-host profile
When _UNSLOTH_PS_HOST_PROFILE identifies a VS Code caller, the probe first adds Microsoft.VSCode_profile.ps1 and then also adds $PROFILE.AllUsersCurrentHost, which belongs to the spawned ConsoleHost rather than the caller. The same duplication occurs for the current-user profiles below. In a PowerShell Extension console this can let an unrelated ConsoleHost profile overwrite the caller's proxy, call exit before framing, or contribute ProxyUseDefaultCredentials beside the VS Code profile's proxy, producing a configuration the caller never had. The probe needs to select the identified host profile instead of loading both mutually exclusive current-host profiles.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one: TERM_PROGRAM cannot identify the host, so "select the identified host profile" has nothing reliable to select on. VS Code sets TERM_PROGRAM=vscode on every integrated terminal, not only the PowerShell extension's console (https://code.visualstudio.com/docs/terminal/shell-integration recommends gating on exactly that variable for pwsh, bash and zsh alike), and Microsoft.VSCode_profile.ps1 is not created by default (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles). So the two profiles are not mutually exclusive from where the probe stands: they are two candidates, one of which usually does not exist.
I ran the four cases against pwsh 7.6.0 with planted profiles setting different proxies, head (add both, current-host last) versus the substitution this asks for:
| case | head | substitute |
|---|---|---|
| caller really is the extension console, both profiles exist | console proxy | vscode proxy |
| plain pwsh terminal in VS Code, only Microsoft.PowerShell_profile.ps1 exists | console proxy | nothing |
| plain pwsh terminal in VS Code, both profiles exist | console proxy | vscode proxy |
| no VS Code, only Microsoft.PowerShell_profile.ps1 | console proxy | console proxy |
Substitution is right in row 1 and wrong in rows 2 and 3, and row 2 is the common one: it returns no proxy at all, which is the failure the probe exists to prevent. Add-both is wrong only in row 1, and even there it returns a real proxy from the same user's own profiles rather than none.
On which value should win when both exist: the profile that actually matters is the one the download host would load, and that host is the spawned ConsoleHost, so CurrentUserCurrentHost running last is the conservative order, matching PowerShell's own precedence for the process doing the work. The other harms need both files to exist and to disagree, and both are then the same user's own settings.
Test-only change in 55b7a5a: the guard was still named test_the_probe_loads_only_the_callers_own_host_profile and documented as exclusive, which is the opposite of what the code does. Renamed, redocumented, and it now pins that each current-host profile is appended unconditionally and after the named one, so the substitution above fails the suite instead of passing it.
Comments, docstrings and whitespace only; no code changes. Each comment keeps the reason it records and drops the retelling.
|
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". |
Comments, docstrings and whitespace only. The install.ps1 prologue and the studio.py proxy probe kept one causal claim per decision, with the probe's profile-loading essay split into a short note beside each line it justifies.
|
Ran this against a real hostile profile on the pwsh installed on the box, 7.6.0 on Linux. Two profile files in a throwaway HOME, in the scopes pwsh loads them from: # CurrentUserAllHosts (profile.ps1) -- the machine's outbound proxy
$PSDefaultParameterValues['Invoke-WebRequest:Proxy'] = 'http://proxy.corp.invalid:3128'# CurrentUserCurrentHost (Microsoft.PowerShell_profile.ps1)
Write-Host "[profile] corp profile loaded, 4 modules"
Set-StrictMode -Version Latest
Set-Alias uv '<a uv 0.5.0 build>'
$PSDefaultParameterValues['ConvertTo-Json:AsArray'] = $true
function ConvertTo-Json { param([Parameter(ValueFromPipeline=$true)]$InputObject) process { "wrapped by the profile" } }
[Console]::OutputEncoding = [System.Text.Encoding]::UnicodeThe proxy sits one scope earlier than the hostility on purpose. It belongs in AllUsersAllHosts, but that is A. the proxy. The naive dump fails twice in one line. The profile's The proxy survives the round trip into a B. uv. install.ps1's version gate, the function text lifted verbatim out of each tree, run under the same profile with a uv 0.12.1 on PATH and the alias pointing at 0.5.0. The floor is 0.8.16.
Two gaps worth naming. The |
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
* Read PSModulePath under the key Windows actually exports os.environ upper-cases keys on Windows, so dict(os.environ) carries PSMODULEPATH and a plain dict is case-sensitive. _profile_probe_env read "PSModulePath", always got the empty default, and wrote back a second key differing only by case, so the probe child lost the caller's module entries instead of having them reordered behind Windows PowerShell's own. Resolve the key case-insensitively and update it in place. This is what has failed parity (windows-latest) on every branch since #8161: the five PSModulePath tests read the same missing key out of the returned dict. * Tighten the comments on the module-path key lookup

Summary
Installing on Windows failed from a normal console but succeeded from one started with
-NoProfile. A profile runs beforeirm https://unsloth.ai/install.ps1 | iexdoes and shares its scope, and that entry point has no script file to re-launch without a profile, so the individual couplings have to be cut instead.The script already handles two of them:
PSModulePathreordering and console encoding. Four were unhandled.What changed
At the top of
Install-UnslothStudio, all scope-shadowed so the caller's session is untouched:Set-StrictMode -Off. The script tests environment variables that are legitimately unset and reads$script:state only some branches assign, both of which a profile'sSet-StrictMode -Version Latestturns into terminating errors.$PSDefaultParameterValuesfiltered down to proxy keys. An entry likeStart-Process:WindowStylesilently rebinds cmdlets and fails the install with an error naming none of it. Proxy entries are deliberately kept: they can only ever enable a download, and on a locked-down corporate host may be the only route to python.org and the uv release. Clearing it wholesale would break exactly the users who never run-NoProfile.$PSNativeCommandUseErrorActionPreference = $false. A fourth coupling not in the original report: with a profile turning it on, theStoppreference makes a failing native command throw out of theunsloth studio setuphandoff instead of reachingExit-InstallFailure, skipping rollback and the Tauri error record.uv resolution: PowerShell ranks aliases and functions above PATH, so a profile
Set-Alias uv ...was answering the version probe and ending the install at "uv could not be installed" on machines that had a working uv. NewResolve-UvExecutableusesGet-Command uv -CommandType Application -Alland falls back to the bare token when nothing is on PATH, so behaviour is byte-identical with no interference.Test-UvVersionOkpins the executable that answered into$script:UvExe, and the 27 install scriptblocks invoke that path.$script:UvExeand$script:UvInstallDestDirreset per invocation, since$script:is the caller's session underirm | iex. I audited the other three named globals:UnslothVerbose,WingetAvailableandCondaSkipPatternare already unconditionally assigned before first read, so that is documented rather than adding no-op resets. NullingCondaSkipPatternwould leave a null regex live.unsloth_cli/commands/studio.pynow passes-NoProfiletosetup.ps1unconditionally. It was added only when stdout is not a tty, which is never true for the console install, sosetup.ps1, which has bareuvcalls and no prologue, still ran under the profile. This is a child-process launch, the pattern already used atinstall.ps1:1061and:1216, not a self re-exec.Testing
pwsh 7.6.0 was available, so this was executed rather than only written.
Parser::ParseFileoninstall.ps1: clean$nullinstall.ps1orstudio.py: one failure,test_studio_runtime_gate.py::test_terminal_update_holds_the_gate_through_environment_mutation, confirmed pre-existing on a clean treeinstall.ps1under a hostile profile end to end; both reach the identical Windows-only stop point, so no earlier failure was introducedrelease-desktop.ymlAuthenticode-signs this filetest_installer_interactive_prompts.pypassesCross-platform CI on ubuntu, macOS and Windows: no new failures. The 12 Windows failures in
test_studio_install_workspace_guard.pyare byte-identical on a pristine-main baseline run of the same selection.One test needed a fix after CI.
test_a_real_profile_reproduces_the_same_statepassed locally and failed on the ubuntu runner. PowerShell on Unix does not derive$PROFILEfrom$HOME:XDG_CONFIG_HOMEwins outright and$HOME/.config/powershellis only the fallback, and the GitHub ubuntu image setsXDG_CONFIG_HOMEin/etc/environment, so the fixture wrote the profile somewhere pwsh never read. The fixture now setsXDG_CONFIG_HOMEalongsideHOMEand asks pwsh for the real$PROFILEpaths instead of hardcoding one.install.shis unchanged: bash non-interactive shells do not source rc files and do not expand aliases, so there is no shared behaviour requiring it.Behaviour changes worth knowing
Set-Alias uv <newer>while an olderuv.exeis on PATH now loses to the PATH copy, and auv.ps1on PATH is now ignored. Both match the-NoProfileconsole.studio/setup.ps1is not itself hardened. It still has bareuvand(Get-Command python).Source. The reachable path is closed by forcing-NoProfileon the launch; a user invokingsetup.ps1by hand is still exposed, and the test docstring says so.assert src.count("{ & $script:UvExe ") >= 27is a floor, so legitimately removing a uv call site needs the number bumped.Reported in an external QA pass.