Repository navigation
Studio sd.cpp: verify a new bundle starts before it replaces the installed one; Windows ROCm without the HIP SDK uses Vulkan - #15371
Conversation
…alled one; Windows ROCm without the HIP SDK uses Vulkan
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 review |
|
@codex security review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0c935da6a
ℹ️ 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".
| note_accelerator_runtime_failure( | ||
| klass, proven = True, fingerprint = {"bundle": want, **_host_fingerprint()} | ||
| ) |
There was a problem hiding this comment.
Match fallback failure records against the requested pin
When the fallback bundle comes from an upstream release or a latest-release fallback, its actual tag differs from _pinned_tag(). This records the requested pin as bundle, but _accelerator_fingerprint() reads the installed record's actual tag, so _fingerprint_still_applies() immediately treats the proven failure as stale. Subsequent loads therefore request the rejected ROCm build again and repeat the download/install ladder instead of retaining the working fallback. Compare requested pins consistently (the install record already has requested_tag), or update the failure fingerprint to match the successfully installed fallback.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 2155687. The refusal is now recorded after the replacement build installs, with the fingerprint _accelerator_fingerprint() reads back from that build's own install record, so an upstream or latest-release fallback no longer retires the record at once. If no rung installs, the pin is used as before. New test_the_refusal_record_survives_a_fallback_from_another_release fails on the previous head and passes here; all sd.cpp test files: 1498 passed, 1 skipped.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…ts whose ROCm comes only from the torch wheel (unslothai#15430) On a Linux AMD host whose ROCm userspace comes only from the pip torch wheel (no `/opt/rocm`), an image load that wants sd.cpp fetches leejet's ROCm prebuilt (~295 MB), and that build cannot start: it imports `libamdhip64.so.7`, `libhipblas.so.3` and `librocblas.so.5` from the host and bundles none of them. Reported in the Discord help thread (CachyOS, RX 9070): on a slow connection the load spins while that bundle downloads (the 300 s timeout is per read, so a trickling fetch never trips it), and deleting the half-written zip "fixes" it only because the SHA check then fails and the load falls back to the Vulkan build already installed. unslothai#15371 already recovers once the fetch completes: the bundle fails its start check, the load steps down to Vulkan, and ROCm is recorded as unrunnable. Two gaps remain, and this PR closes both: the 295 MB fetch still happens first, and a fetch that stalls or is cut short records nothing, so every later load starts it again. ## Cause The runtime guard, `rocm_runtime_resolvable()`, asks `ctypes.CDLL` in the Unsloth Studio process. By then torch's ROCm wheel has loaded its own copies of those three sonames, so the lookup by soname succeeds and the guard reports a runtime that sd-cli, a separate process, can't see. Measured on Mint 22.1 with `torch 2.11.0+rocm7.13`: | check | libamdhip64.so.7 | libhipblas.so.3 | librocblas.so.5 | |---|---|---|---| | in-process, before `import torch` | missing | missing | missing | | in-process, after `import torch` | ok | ok | ok | | fresh process | missing | missing | missing | ## Change - `rocm_runtime_resolvable` / `rocm_runtime_missing_sonames` ask a fresh `python -X utf8 -I` process (env from `utf8_child_env()`), memoised per process. - `ensure_sd_cpp_binary` / `ensure_sd_server_binary` check that answer before any fetch: a ROCm request on a host whose loader can't find the runtime installs the Vulkan rung instead and records ROCm as proven unrunnable. `preferred_accelerator` is unchanged. - `note_unlaunchable_accelerator_build` marks an exit-127 strike proven when the runtime is absent, so an already-installed ROCm build diverts after one failure, not two. - Tests drive the new probe seam instead of patching in-process `ctypes.CDLL`; the two ambiguous-launch tests pin "runtime loads" so they no longer follow the test machine. ## Testing Mint 22.1, RX 9060 XT (gfx1200), no system ROCm, Unsloth Studio from source with `torch 2.11.0+rocm7.13.0` (HIP 7.13.99004, the reporter's), Images > load `unsloth/MOSS-Image-SFT-GGUF` UD-Q4_K_XL, clean `~/.unsloth/stable-diffusion.cpp` and no recorded fallback before each run. "After" is this PR's diff applied to the same main commit. Before, main `a20b732`: ``` downloading sd-master-0518b34-bin-Linux-Ubuntu-24.04-x86_64-rocm-10.1.0.zip -> ~/.unsloth/stable-diffusion.cpp/... sd_cpp.unrunnable_build: ...rocm-10.1.0.zip: sd-cli cannot start on this host: the dynamic loader refused it ... downloading sd-master-982-0518b34-ud331c66-bin-Linux-Ubuntu-22.04-x86_64-vulkan.zip -> ... verified ...vulkan.zip starts on this host sd_cpp.loaded: repo=unsloth/MOSS-Image-SFT-GGUF ... mode=server ``` After, this PR: ``` sd_cpp.rocm_runtime_absent: the ROCm build needs the host ROCm 7 runtime and the loader cannot find libamdhip64.so.7, libhipblas.so.3, librocblas.so.5 (...); installing the vulkan build instead downloading sd-master-982-0518b34-ud331c66-bin-Linux-Ubuntu-22.04-x86_64-vulkan.zip -> ... verified ...vulkan.zip starts on this host sd_cpp.loaded: repo=unsloth/MOSS-Image-SFT-GGUF ... mode=server ``` Both runs end with MOSS loaded on the GPU; the difference is the 295 MB ROCm fetch, which this PR skips. Mint's link is fast (the fetch took ~8 s), so the reporter's stalled-download case was not reproduced live; it is covered by `test_an_unloadable_rocm_runtime_installs_vulkan_without_fetching_rocm`. | suite | result | |---|---| | every `sd_cpp*`, `diffusion_engine_router`, `diffusion_routes`, `h3_native*` test file, on Mint | 1900 passed, 1 skipped, measured at `e043dbf`; since then only `b3db89b` (probe child env), with `test_chat_text_encoding` + the ROCm files at 378 passed | --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>
…p build when its bin dir is not on PATH (unslothai#15853) Reported on Reddit: [Anyone manage to get MOSS Image to load?](https://www.reddit.com/r/unsloth/comments/1xecbd5/anyone_manage_to_get_moss_image_to_load/). After unslothai#15371 moved Windows AMD hosts without the HIP runtime to Vulkan, the reporter asked what to install to use the HIP build instead. ## Problem On Windows AMD, image generation uses the Vulkan stable-diffusion.cpp build unless `hipblas.dll` is found on `PATH`. The upstream `win-rocm` bundle ships its own `amdhip64_7.dll` but imports `hipblas.dll`, which only the AMD HIP SDK provides. The SDK installer never puts that DLL's folder on `PATH`: HIP SDK 7.2.3's `ROCm_SDK_Core.msi` sets only `HIP_PATH` and `HIP_PATH_72`, and AMD's install guide tells users to add the `bin` folder to `PATH` themselves. As a result, a user who installs the HIP SDK, as the existing log line suggests, still gets Vulkan. Detection (`windows_hip_runtime_missing_dlls()`), the installer's start probe (`_probe_env()`) and every sd-cli/sd-server launch (`runtime_env()`) look only at `PATH`. ## Fix - New `windows_hip_sdk_bin_dirs()` in `install_sd_cpp_prebuilt.py`. It returns the HIP SDK `bin` folders from `HIP_PATH`, then `ROCM_PATH`, then `C:\Program Files\AMD\ROCm\<ver>` (newest first). It keeps only 7.x folders, meaning `hipblas.dll` sits next to `amdhip64_7.dll`. - Detection searches those folders in addition to `PATH`. For a ROCm bundle, `_probe_env()` and `runtime_env()` append them after the caller's `PATH`. - The log line, the fallback reason and the installer hint now say HIP SDK 7.x, mention the `HIP_PATH` lookup, and link AMD's download page. ## Behavior boundaries - Without a HIP SDK, Windows AMD still starts at the Vulkan build, as on main. - A HIP SDK already on `PATH` keeps priority. - Non-ROCm bundles and non-Windows hosts get the same child environment as before. - A 6.x SDK folder is not used: its `hipblas.dll` binds `amdhip64_6.dll`, not the bundle's HIP 7 runtime. - A host with a saved ROCm failure, for example from an earlier forced attempt without the SDK, stays on Vulkan until the record is cleared with `DELETE /api/settings/diffusion-accelerator-fallback`. This is main's existing policy, the same as on Linux ROCm hosts. - No UI changes. ## Verification - 7 new tests in `test_sd_cpp_install_verify.py`. Six of them fail on main, including `preferred_accelerator("rocm")` returning `"vulkan"` when the SDK is found only through `HIP_PATH`. - The sd.cpp, diffusion router, H3 and video suites pass: 2402 passed, 3 skipped. Live A/B on Windows 11 with a Radeon 8060S (gfx1151): - The HIP SDK 7.2.3 files were extracted to the layout its MSIs install, and `HIP_PATH` was set the way the MSI sets it. `PATH` was left unchanged. - Each case used a fresh Studio home, ran Studio's own `preferred_accelerator("rocm")` and `ensure_sd_cpp_binary()`, then generated an SD-Turbo image through `runtime_env()`. | Case | Accelerator chosen | Installed build | Generation | |---|---|---|---| | main, SDK installed | vulkan | win-vulkan | Vulkan0 | | main, SDK installed, `UNSLOTH_SD_CPP_WINDOWS_ROCM=1` | rocm | ROCm refused with `0xC0000135`, fell back to win-vulkan, ROCm recorded as failed | Vulkan0 | | main, SDK `bin` added to `PATH` by hand | rocm | win-rocm-10.1.0 | ROCm0, gfx1151 | | this PR, SDK installed | rocm | win-rocm-10.1.0, start probe passed | ROCm0, gfx1151 | | this PR, no SDK | vulkan | win-vulkan | not run | With this PR the result matches the manual `PATH` edit on main, down to an identical output image. --------- Co-authored-by: Daniel Han <[email protected]>
…sing-DLL box (unslothai#16031) Reported on Reddit in [a reply to "Anyone manage to get MOSS Image to load?"](https://www.reddit.com/r/unsloth/comments/1xecbd5/anyone_manage_to_get_moss_image_to_load/): the hipblas.dll box still pops up on load after switching to Vulkan. ## Problem On Windows, an sd.cpp bundle that cannot load its DLLs (for example a ROCm bundle installed before unslothai#15371 on a host without the HIP SDK) opens a modal "sd-server.exe - System Error: ... hipblas.dll was not found" box when the backend test-launches it. The probes pass only `windows_hidden_subprocess_kwargs()`, which hides the console but not the loader's hard-error box. The installer's `probe_binary_starts` and `_vulkan_probe` already suppress it; the backend's probes did not. The child stays blocked until someone clicks OK, so an unattended probe hits its timeout instead of reading `0xC0000135`: - `_server_binary_runnable` returns True from its timeout branch, so an unrunnable managed binary is kept instead of being reinstalled. - With Vulkan requested, `ensure_sd_server_binary` probes again under `_install_lock`: a second box and another 20 s. - With ROCm still requested (`UNSLOTH_SD_CPP_WINDOWS_ROCM=1`, or `hipblas.dll` present but another HIP DLL missing), the broken binary is returned and later probes open more boxes. ## Fix `windows_loader_error_boxes_suppressed()` in `utils/subprocess_compat.py` ORs `SEM_FAILCRITICALERRORS` into the process error mode around a test-launch, so the child inherits it and exits at once with `0xC0000135`. It wraps the four sd.cpp test-launches: `_server_binary_runnable`, `_sd_cpp_probe_output`, `sd_cpp_binary_identifies` and `SdCppEngine.version`. The error mode is process-wide and these probes can overlap the installer's own probe, so all holders, including the installer's `_windows_error_mode_suppressed` (still `0x8003`), share one record: the mode before the first holder plus the current holders' flags, restored when the last one leaves. The record lives in `sys.modules` because the installer and the backend import this module under different names. ## Boundaries - `windows_hidden_subprocess_kwargs` and its ~95 callers are unchanged; the error mode is parent process state, not a `CreateProcess` argument. - The long-lived spawns are unchanged; the probes gate them. - The installer still runs standalone. ## Verification Windows 11, Radeon 8060S, no HIP SDK, with the upstream ROCm bundle installed without the start check (as v0.1.911-beta did). Each scenario ran against `main` (A) and this PR (B) in the logged-on desktop session: | Scenario | A: `main` | B: this PR | | --- | --- | --- | | `_server_binary_runnable(sd-server)` | box, 20.3 s, returns **True** | no box, 0.56 s, False | | `_sd_cpp_probe_output(sd-cli, --help)` | box, 20.3 s | no box, 0.59 s | | `sd_cpp_binary_identifies` + `version()` | box, 20.3 s | no box, 0.58 s | | Upgrade through both `ensure_*`, Vulkan requested | 2 popups, 42.9 s | no popup, 3.5 s | | ROCm forced | 3 popups, 60.5 s, keeps the broken ROCm binary | no popup, 1.2 s, removes it for reinstall | An installer scope and a probe scope overlapping on the same host, with the installer leaving first, kept the bit for the probe and restored the original mode afterwards. On `main` in the non-interactive service session, the same probe returns in 0.6 s with no box, which is why headless runs never showed this. `tests/test_sd_cpp_probe_error_mode.py` adds 11 tests with a fake `kernel32`, all failing on `main`. The sd.cpp, router, hires and Vulkan probe suites pass (1798 passed, 9 skipped). --------- Co-authored-by: Daniel Han <[email protected]>
Summary
On Windows with an AMD GPU and a ROCm torch, loading a native (stable-diffusion.cpp) image model such as
unsloth/MOSS-Image-SFT-GGUFcould leave Studio with no usable sd.cpp binary at all:master-982-0518b34-ud331c66publishes no Windows ROCm asset (it shipswin-cpu,win-cuda12,win-cuda13,win-vulkan), so a ROCm request falls back to the upstreamleejet/stable-diffusion.cppwin-rocm-10.1.0zip.amdhip64_7.dllbut itsstable-diffusion.dllimportshipblas.dll, which only the AMD HIP SDK provides. Without the SDK on PATH,sd-cli.exeandsd-server.exedie in the Windows loader (exit0xC0000135, "hipblas.dll was not found").sd-cli (stable-diffusion.cpp) binary is unavailable.This PR fixes all three steps.
Changes
studio/install_sd_cpp_prebuilt.pysd-cli/sd-serverare started with--help(bundle directory first on the library path, loader error dialogs suppressed on Windows). If the OS loader refuses one (Windows0xC0000135/0xC0000139/0xC0000142, or the POSIX dynamic loader's "error while loading shared libraries"), the install raisesUnrunnableBuildErrorand the existing install is left exactly as it was. Any other outcome (a normal exit, an exec error, a timeout) is not treated as a refusal.UNSLOTH_SD_CPP_VERIFY_INSTALL=0restores the previous unverified install.libamdhip64.so.7missing) and the Vulkan build is installed, where before the ROCm build was installed and the existing runtime ladder moved the host to Vulkan later.studio/backend/core/inference/sd_cpp_backend.pypreferred_accelerator: on Windows, a ROCm request starts at the Vulkan build unlesshipblas.dllis found in System32 or on PATH. This is a file search only; nothing is loaded into the Studio process.UNSLOTH_SD_CPP_WINDOWS_ROCM=1always takes the ROCm build (the previous behaviour),0never takes it, andUNSLOTH_DIFFUSION_SD_CPP_VULKAN_FALLBACK=0also keeps ROCm.ensure_sd_cpp_binary/ensure_sd_server_binary: when the installer raisesUnrunnableBuildError, the failure is recorded as proven for that accelerator, and the next rung (rocm -> vulkan -> cpu) is installed in the same call, so a fresh host ends up on a working build and later loads start there. The record is keyed on the pinned tag, which the replacement build also carries, so the record holds until the pin moves.MOSS-Image not listed under On Device
That part is #15168 (
moss_imageregistered as an image GGUF architecture). It merged on 2026-10-26, afterv0.1.910-betawas tagged (7dbc8b9ec8, 2026-10-23), so that release still classifies MOSS-Image GGUFs astext-generation. On current main they are listed for Images. No change is needed here.Testing
studio/backend/tests/test_sd_cpp_install_verify.py(14 tests). On the merge base, 8 of them fail: the refused bundle replaces the working build, the Windows ROCm request stays on ROCm, and a fresh ROCm ensure returns the unrunnable build. On this branch all 14 pass. The other 6 are guards that pass on both (kill switches, a bundle that starts still replaces the old one, other hosts and accelerators unchanged).test_sd_cpp_install.py,test_sd_cpp_rocm_vulkan_fallback.py,test_sd_cpp_vulkan_cpu_torch.py,test_sd_cpp_pin_upgrade.py: 567 passed, 1 skipped on this branch.Windows 11 runner (Radeon 8060S, driver DLLs
amdhip64_6.dll/amdhip64_7.dllin System32, no HIP SDK, nohipblas.dllanywhere on the loader path). The merge base and this branch ran in the same job, both with the real mirror Vulkan zip and the real upstreamwin-rocm-10.1.0zip:--helpexit)preferred_accelerator("rocm")ensure_sd_server_binary(accelerator="rocm")sd-cli.exe0xC0000135,sd-server.exe0xC0000135sd-server.exe, exits 0xC0000135UnrunnableBuildError)sd-cli.exe0,sd-server.exe0sd-server.exe, exits 0On the merge base the backend's own
_server_binary_runnablealso returns False for the swept-in server. That is the "is not runnable; removing it so it reinstalls" path that ended the load with no binary.