Skip to content

[Bug] AMD: Unsloth Studio Images retries the ROCm sd.cpp build on hosts whose ROCm comes only from the torch wheel - #15430

Merged
danielhanchen merged 13 commits into
unslothai:mainfrom
LeoBorcherding:fix/sd-cpp-rocm-fallback-preflight
Oct 28, 2026
Merged

danielhanchen merged 13 commits into
unslothai:mainfrom
LeoBorcherding:fix/sd-cpp-rocm-fallback-preflight

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

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.

#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

@danielhanchen danielhanchen self-assigned this Oct 28, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-28T06:17:11.250705Z
We couldn’t complete this review. Comment @codex review to try again.
30cb592 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

@danielhanchen danielhanchen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review record: this PR was reviewed on its mirror, danielhanchen/unsloth-staging-review#575 (one squashed commit, 63d1102b4, onto upstream main 8222149ee).

  • Automated review: "Didn't find any major issues" on 63d1102b47.
  • Security review: no security issues found on 63d1102b47.

The mirror's tree matches this PR's head 81ccf2c57 merged onto 8222149ee (sd_cpp_backend.py blob b9c228cb on both; the two test files are byte-identical), so the approval covers this head. Nothing from the mirror needs landing.

@danielhanchen
danielhanchen merged commit 8e42faf into unslothai:main Oct 28, 2026
34 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants