Repository navigation
Studio: install prebuilt flash-attn, causal-conv1d and mamba-ssm wheels on Windows and ARM - #13262
Conversation
…ls on Windows Windows x64 resolves to our win_amd64 builds on prebuilt-wheels-cu13 (upstream naming, cxx11abiFALSE, cp313, torch 2.13 / 2.14 cu13). Windows on ARM resolves flash-attn to NVIDIA's Flash-Attention-for-WoA wheel for torch 2.14, pinned by a #sha256= fragment that uv and pip both verify. Windows is wheel-only everywhere: no upstream name is ever built (no upstream release has a Windows asset) and a missing or rejected wheel never falls back to a PyPI source build. Setup, long-context training, the causal-conv1d fast path and its lazy hook, SSM inference and install-kernels all take the Windows path; mamba-ssm on Windows first requires an importable triton. Linux URLs are unchanged.
…og says what Windows does
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
# Conflicts: # studio/install_python_stack.py # tests/python/test_flash_attn_install_python_stack.py
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
Addresses the Windows update hang reported on Reddit ([Reddit r/unsloth: "Update install failing"](https://www.reddit.com/r/unsloth/comments/1x7n5jq/update_install_failing/)): it halves the prebuilt-wheel download and shows that the install is still running. A slow connection can still take a while. ## Problem Since unslothai#13262, Studio setup on Windows installs a 427 MB prebuilt flash-attn wheel at step `6/17 flash-attn`. Users reported that the step hangs, and one killed it after 30 minutes. Reporters blamed the torchao fallback warning printed just before the step, but that warning is unrelated: it prints on every Windows CUDA install. Our reproduction completed, but slowly and silently. To install a wheel from a URL, uv normally fetches only the wheel's metadata, using HTTP range requests. For GitHub release assets those range requests fail, so uv downloads the whole wheel just to read its metadata, discards it, and downloads it again to install (related: astral-sh/uv#18998). `install_wheel` captures uv's output, so the progress bar shows nothing for the whole 2 x 427 MB. At 256 KiB/s on `windows-latest`, step 6/17 took about 60 minutes ([job](https://github.com/oobabooga/unsloth/actions/runs/38959270916/job/117169940368)). ## Fix - `install_wheel` (`studio/backend/utils/wheel_utils.py`) supplies the wheel's metadata to uv up front, so uv skips the metadata fetch and downloads the wheel once. It writes the package name and version, taken from the wheel filename, into a `uv.toml` (`[[dependency-metadata]]`) in a temp dir, and points uv at it with `--project`. uv still installs from the URL into its own cache, so a later reinstall reuses the cached copy. The user's and system uv configs still apply, and relative paths such as `UV_CACHE_DIR` still resolve against the working directory. - `_ensure_flash_attn` (`studio/install_python_stack.py`) shows that the install is still running. On a terminal the progress bar shows the elapsed time; when output is captured, a `still installing flash-attn (N min)` note is printed each minute. Every caller of `install_wheel` gets the single download: setup, `unsloth install-kernels`, the on-demand causal-conv1d / mamba-ssm installs, and the training worker. ## What the user sees In a terminal, the progress line now counts up in place, once a second, until the install finishes: ``` deps [=======-------------] 6/17 flash-attn 0:03 ``` When output is captured, from the Windows A/B below at 1 MiB/s. The `[ Ns]` prefix is the CI wrapper's elapsed-time stamp. Before, nothing for 21 minutes: ``` [ 18s] deps [======--------------] 6/18 dependency overrides [ 22s] torch 2.13.0+cu130 detected -- installing torchao==0.18.0 from [ 22s] https://download.pytorch.org/whl/cu130 [ 22s] https://download.pytorch.org/whl/cu130 did not serve torchao==0.18.0 -- retrying [ 22s] from the default index; its kernels may be skipped [ 1,289s] deps [=======-------------] 7/18 flash-attn [ 1,289s] deps [========------------] 8/18 Unsloth Studio deps ``` After: ``` [ 16s] deps [======--------------] 6/18 dependency overrides [ 18s] torch 2.13.0+cu130 detected -- installing torchao==0.18.0 from [ 18s] https://download.pytorch.org/whl/cu130 [ 18s] https://download.pytorch.org/whl/cu130 did not serve torchao==0.18.0 -- retrying [ 18s] from the default index; its kernels may be skipped [ 81s] deps [=======-------------] 7/18 flash-attn [ 81s] still installing flash-attn (1 min) [ 141s] still installing flash-attn (2 min) [ 201s] still installing flash-attn (3 min) [...] [ 621s] still installing flash-attn (10 min) [ 644s] deps [========------------] 8/18 Unsloth Studio deps ``` (The update has 18 steps instead of 17 because it adds a base-packages step. Captured output is block-buffered, so the `7/18` line appears with the first note.) ## Behavior boundaries - uv runs as before when a project config would apply from the working directory (`uv.toml`, or `pyproject.toml` with `[tool.uv`), or when `UV_PROJECT` selects a project, because pointing `--project` elsewhere would make uv ignore that config. It also runs as before when `UV_CONFIG_FILE` or `UV_NO_CONFIG` is set, or when the URL has no parseable wheel filename. - The pip fallback is unchanged; pip already downloads once. ## Verification Windows A/B on `windows-latest`: arm A ([run](https://github.com/oobabooga/unsloth/actions/runs/38972789221)) and two copies of arm B ([run](https://github.com/oobabooga/unsloth/actions/runs/38980373037)). Each installs with the public one-liner, then runs `unsloth studio update` twice, with GitHub downloads throttled to 1 MiB/s. Arm B applies this diff first. - Cold update: flash-attn and the Studio uv cache are deleted first, so the update starts like a fresh install. - Warm update: flash-attn is deleted again but the cache is kept, to check that a reinstall still reuses uv's cached copy. | | Cold update | Warm update | |---|---|---| | A, before ([job](https://github.com/oobabooga/unsloth/actions/runs/38972789221/job/117214948654)) | 856,182,074 B (2 downloads), 1,314 s, silent | 13,105 B, 44 s | | B1, this PR ([job](https://github.com/oobabooga/unsloth/actions/runs/38980373037/job/117239567781)) | 428,140,611 B (1 download), 698 s, a note each minute | 6,938 B, 30 s | | B2, this PR ([job](https://github.com/oobabooga/unsloth/actions/runs/38980373037/job/117239567498)) | 428,192,144 B (1 download), 667 s, a note each minute | 6,938 B, 40 s | In arm B a single `uv --project <temp dir> pip install` process held the wheel URL. One earlier arm B run of the same code ([job](https://github.com/oobabooga/unsloth/actions/runs/38977254602/job/117229573031)) moved 357 MB and then 428 MB: the download was cut off partway and uv retried it from the start. It was not the metadata pass, because the wheel's `METADATA` sits in its last 20 KB. flash-attn imports afterwards in both arms. Tests: - New `studio/backend/tests/test_wheel_download.py` covers when the metadata file is written and how uv and pip are invoked. It also runs real uv against a local server that, like GitHub, does not answer range requests: 2 downloads before, 1 after, none on reinstall, with a relative `UV_CACHE_DIR` that must stay in the working directory. Another checks that a project chosen with `UV_PROJECT` still applies its config. Both pass with uv 0.11.16 and 0.13.1. - `tests/python/test_install_python_stack.py` covers the progress output on a terminal and when captured. - The installer and `wheel_utils` suites pass, and `ruff check` and `scripts/run_ruff_format.py` are clean. --------- Co-authored-by: Daniel Han <[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]>
Studio has always skipped flash-attn, causal-conv1d and mamba-ssm on Windows, because no upstream release has ever published a Windows wheel for any of them. #13261 builds
win_amd64wheels for torch 2.13 and 2.14 onprebuilt-wheels-cu13; this PR makes Studio install them, and on Windows on ARM installs NVIDIA's own flash-attn wheels.What changes
Resolver (
studio/backend/utils/wheel_utils.py)unsloth_prebuilt_wheel_urlnow answers forwin_amd64as well aslinux_x86_64: torch 2.13 / 2.14, CUDA 13, cp313 GIL builds only (the only interpreter published), with the same upstream filename template, e.g.flash_attn-2.8.4+cu13torch2.13cxx11abiTRUE-cp313-cp313-win_amd64.whl. Linux still answers for any interpreter, as before.win_*platform,direct_wheel_urlandflash_attn_wheel_urlnever build a Dao-AILab or state-spaces name, since none of those releases has a Windows asset and the URL could only 404.linux_aarch64torch 2.13 / 2.14 cp313 resolves all three to our release (upstream's aarch64 wheels stop at torch 2.10), andwin_arm64torch 2.14 on CUDA 13.4+ resolves causal-conv1d and mamba-ssm for cp311 to cp313. flash-attn onwin_arm64stays NVIDIA's.wheel_platform_tagreturnswin_arm64on Windows on ARM. flash-attn there resolves to NVIDIA'sFlash-Attention-for-WoArelease (flash-attn 2.8.4 for torch 2.14 + CUDA 13.4, cp311 to cp314 and cp314t; a CUDA 13.0 torch no longer matches), with each file's sha256 pinned through a#sha256=fragment, taken from the release's asset digests. uv and pip both refuse a mismatched file.probe_torch_wheel_envreportsabi_tagso a free-threaded interpreter never gets a GIL wheel, and its Windows opt-in now covers everywin_*tag.Callers
install_python_stack.py): the flash-attn step runs on Windows. Its torch probe is bounded by the same 300 s as the import probe before it, so a wedged driver cannot hang setup. Linux is unchanged.ssm_runtime.py): the blanket win32 causal-conv1d skip is gone.unsloth install-kernelsacceptswin_*.Windows is wheel-only
pip install flash-attnor a mamba-ssm source build, which on a machine with MSVC and the CUDA toolkit could run for hours. This also covers_ensure_mamba_ssm, which had no Windows gate at all.ssm_runtimeandinstall-kernelsall require an importabletritonbefore installing it; a true SSM model without it gets a clear error instead of a crash at load.Tests
studio/backend/tests/test_wheel_utils_windows_kernels.py(28 tests): every Windows URL shape for all three kernels on torch 2.13 and 2.14; the cells that must resolve to nothing (cp312, cp313t, torch 2.11 / 2.10, cu12, no CUDA, the wrong ABI flag); a sweep showing no Windows URL ever names an upstream release; the 5 NVIDIAwin_arm64URLs and hashes including cp314t; Linux unchanged.test_ssm_runtime.py,test_training_worker_flash_attn.py,test_kernel_install.pyandtests/python/test_flash_attn_install_python_stack.py: each caller is reached on Windows, a published wheel installs, a miss, an unreachable check or a rejected wheel never reaches PyPI, and the Triton gate.studio/backend/tests/test_wheel_utils_linux_aarch64_kernels.pyand win_arm64 cases intest_wheel_utils_windows_kernels.py. A sweep of 2,880 cells (4 platforms, 9 torch minors, CUDA 12 / 13.0 / 13.4 / none, both ABI values, 5 interpreters, GIL and free-threaded) moves exactly 17: the linux_aarch64 and win_arm64 cells above plus NVIDIA's flash-attn on a CUDA 13.0 win_arm64 torch, and none on linux_x86_64 or win_amd64.linux_x86_64andlinux_aarch64, 9 torch minors, cu12 / cu13 / none, both ABI values, 5 interpreters) throughflash_attn_wheel_url, the causal-conv1d and mamba-ssm resolvers andresolve_wheel_urlgive the same URLs before and after.test_wheel_utils_windows_kernels.py,test_ssm_runtime.py,test_training_worker_flash_attn.py,test_kernel_install.py,test_flash_attn_install_python_stack.py,test_prebuilt_cuda_wheels.py): 231 + 130 passed. Intests/pythonandtests/studio/installthe same 4test_rocm_support.py::TestProgressStepCountMatchesTotalcases fail on main and on this branch (uv exits in the test environment); nothing new fails.flash_attn_2_cudaimports;unsloth install-kernels causal_conv1dinstalls the causal-conv1d 1.7.0 wheel andcausal_conv1d_cudaimports.Not covered
sys.platformpatched. The wheels themselves are built, imported and signed on windows-2022 in Build the prebuilt CUDA 13 kernel wheels for Windows and ARM (win_amd64, linux_aarch64, win_arm64) #13261.