Repository navigation
Install the Linux CUDA sd-cli, and bump the pin two releases forward - #8208
Conversation
unslothai/stable-diffusion.cpp now publishes a Linux x86_64 CUDA bundle alongside the CPU and Apple ones, so the resolver's Linux GPU branch is about to matter and had no test. Three new cases: a CUDA host asking for cuda gets the accelerated build; a host that did not ask still gets the plain CPU one; and a release without the asset resolves to None rather than handing back a CPU build. The middle one is the reason the fixture lists the CUDA asset ahead of the plain build. That is the order a real release lists them in, since '-cuda12.zip' sorts ahead of '.zip', and it is also the order that would expose auto picking by position rather than by the accelerator-marker filter. The bundle ships the CUDA runtime and is roughly 25x the size of the CPU zip, so handing it to a host that did not ask for it is not a harmless mistake. The last one is what keeps the H3 video path honest: it falls back to the CPU prebuilt and moves the load off the GPU device when the accelerated binary cannot be resolved, and that fallback is only correct because an explicit GPU request returns None on a miss instead of a CPU zip. test_mirror_linux_gpu_accel_is_no_match_not_cpu asserted that cuda was one of the accelerators the mirror does not build. It does now, so cuda comes out of that list and vulkan and rocm stay. Mutation-tested, all four caught: an explicit GPU miss falling through to the CPU build; cuda dropped from the auto exclusion markers; cuda resolving through the wrong marker; vulkan and rocm silently resolving to the CPU zip.
DEFAULT_TAG was master-809-eb7f35c, two releases behind. The new pin,
master-813-bfbef5b-u13b9d92, is the first release to carry a Linux x86_64
CUDA bundle alongside the CPU and Apple assets.
That asset is why this matters rather than being routine housekeeping. The
H3 video path already asks for an accelerated binary:
binary = ensure_h3_sd_cpp_binary(
allow_install = allow_install,
accelerator = _install_accelerator_for(target.backend),
)
and its fallback comment says "Upstream currently publishes no Linux CUDA
archive", so on a CUDA host the request could not be satisfied, the code
dropped to the CPU prebuilt and moved native_device to cpu. MiniMax-H3's
diffusers path wants about 68.5 GB of VRAM, so a consumer card falls back
to the GGUF engine, which means it was falling back to a CPU binary. On one
box that is 65 s/step at 320x192 against 21.5 s/step at 960x544 from a CUDA
build: four and a half hours per clip against eleven minutes.
Checked against the real published asset list rather than only the fixture.
Linux x86_64 cuda takes the cuda12 bundle; Linux x86_64 auto still takes the
plain CPU build; aarch64, both macOS arm64 and x86_64, and Windows are
unchanged; Linux rocm still resolves to None, since the mirror does not build
it and a CPU zip must never be handed back for an explicit GPU request.
I verified the bundle itself on a GPU box before pinning it. Unpacked on a
host with an NVIDIA driver and no CUDA toolkit on the path, it carries
RUNPATH $ORIGIN with libcudart, libcublas and libcublasLt beside the
binaries, correctly does not bundle libcuda.so.1, initialises "NVIDIA B200,
compute capability 10.0", and answers --list-devices with
CUDA0 NVIDIA B200
CPU Intel(R) Xeon(R) Platinum 8559C
which is what sd_cpp_lists_accelerator_device needs to see for the CPU
fallback not to fire.
The pin now carries the mirror's fork suffix, which no upstream release has. Every host the mirror does not build (Linux Vulkan/ROCm, Windows GPU) therefore 404d on the exact pin and settled for upstream latest, so the advertised default stopped being a reproducible install for them. Strip the suffix for the fallback attempt.
A host that installed the managed CPU bundle and later forces the native engine on a GPU kept running the CPU build: both ensure_* return any runnable binary they find, without checking what it was built for, so the CUDA asset this pin adds was never fetched and native generation stayed entirely on CPU. install() now records the accelerator it installed, and ensure_* reinstalls when the request no longer matches. Conservative on every edge: a user-supplied or unmarked build is never replaced, asking for the CPU build back never reinstalls, a failed upgrade keeps the working binary rather than returning none, and it is not retried on every load.
9ed8e4e to
8f90160
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f90160b6a
ℹ️ 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".
| except Exception as exc: # noqa: BLE001 -- download/extract failure -> fall back | ||
| logger.warning("sd-cli auto-install failed: %s", exc) | ||
| return None | ||
| if fallback is not None: | ||
| _note_failed_upgrade(accelerator) |
There was a problem hiding this comment.
Retry accelerator upgrades after transient install failures
When an existing CPU binary is being upgraded and the download or extraction fails transiently, this records the requested accelerator in the process-wide failure set. _accelerator_changed() then suppresses every subsequent attempt for that accelerator until Studio restarts, so later loads keep using the CPU build even after connectivity or disk conditions recover. Cache only definitive “no matching asset” failures, or expire/back off transient failures rather than disabling retries for the process lifetime.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining this one. The suppression is the point of the set: without it a host whose upgrade cannot succeed re-resolves and re-downloads a multi-hundred-MB bundle on every single load, because the binary it keeps still does not match the request. The failure mode you describe is a slower session, not a wrong result: the kept binary generates correctly, the reason is logged, and a restart clears it. Distinguishing transient from definitive here means classifying exceptions out of urllib, zipfile and the filesystem, and a TTL just reintroduces the repeated download on a slower clock. Not worth the complexity for a degraded-but-working path.
The upgrade replaces build/bin/sd-server, and the backend resolves its binary before the load tears the old server down, so the install was opening a file that was still executing: Linux returns ETXTBSY and Windows locks it outright, which made the upgrade fail every time a native model was already loaded. Resolve against what is on disk while a server is resident, then retry the install once the teardown has stopped it, under both locks with no generation able to start. A failed retry keeps the build the load already had.
…ll while a one-shot generation runs
…chever entry point asks
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ea9ee95a9
ℹ️ 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".
| except Exception as exc: # noqa: BLE001 -- download/extract failure -> fall back | ||
| logger.warning("sd-server auto-install failed: %s", exc) | ||
| return None | ||
| return find_sd_server_binary() | ||
| if fallback is not None: | ||
| _note_failed_upgrade(accelerator) | ||
| return fallback |
There was a problem hiding this comment.
Preserve the old bundle until an upgrade commits
If an accelerator upgrade fails after extraction has begun, fallback is no longer guaranteed to be the usable binary that was probed before _install(). For example, on Windows a CPU-to-CUDA upgrade extracts the CUDA executables first and then downloads the separately published cudart archive; if that second download fails, this handler returns the old path even though it now names a CUDA executable with missing DLLs. A disk-full or interrupted extraction can similarly truncate the path, defeating the promised fallback and taking native inference offline; stage the new bundle separately and replace the managed tree only after every extraction step succeeds.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Accurate about the sequence (the Windows cudart archive is fetched after extraction), but declining the remedy. A half-written managed tree is already handled, by usable_or_discard_managed: the next ensure* probes the binary, a CUDA build with missing DLLs does not run, it carries the ownership marker, so it is deleted and reinstalled. That repair loop exists precisely because an interrupted extraction used to leave a present-but-unrunnable binary forever. The cost is the one load that raced the failed install, not native inference offline, and the install record is written only on a complete install, so nothing later trusts the partial one. Staging into a second tree and swapping would double peak disk for a multi-GB bundle and needs a directory rename that Windows refuses while any file under it is open, which is the same lock this deferral works around. That is a rewrite of install() with a worse failure mode than the one it removes.
…unwritable record
|
Verified the mirror prebuilts themselves, not just the resolution logic, on a Linux x86_64 CUDA host at the tag this PR pins ( Assets published at that tag: macOS arm64 and x86_64, Linux Ubuntu 22.04 x86_64, Linux Ubuntu 22.04 x86_64 cuda12, Linux Ubuntu 24.04 aarch64, Windows cpu x64, plus the sha256 manifest. What the installer resolves for a Linux x86_64 host, straight from
Then I downloaded and ran both:
So the Linux CUDA asset this PR adds resolves, verifies, extracts, executes and brings up CUDA on a real card, and the plain CPU asset is unaffected. |
|
Merge-order note, since this PR and #7989 both edit the same This branch pins Whichever lands second wins the line. If #7989 merges after this one it silently reverts the pin to the CPU-only build, and nothing would fail: the tag is a string, so the tests keep passing while the accelerated binary stops being installed. Worth landing this one last, or keeping For scale, measured on a B200 at 960x544 / 124 frames with the same prompt and seed: 410 s through the CPU sd-cli, against 51 s for the int8 diffusers path on the same box. |
|
@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: d5a9fd61eb
ℹ️ 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 _managed_tree_in_use(): | ||
| return fallback |
There was a problem hiding this comment.
Hold generation lock across managed-tree installation
When an accelerator upgrade or serverless upgrade begins while the old one-shot model is idle, this point-in-time check passes and _install() may spend seconds downloading before extraction; during that interval generate() can acquire _generate_lock, set _active_generate_cancel, and launch the existing managed sd-cli because it does not use _install_lock. The installer can therefore overwrite a binary that became active after this check, producing ETXTBSY/locked-file failures or a partially replaced tree. Synchronize generation admission with the entire install span, rather than only sampling _managed_tree_in_use() before the download.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it is the widest window in the whole sequence: the check passed, then the download ran for minutes before the extraction. Fixed in 4ef7b86. Admission and the install are now one decision instead of a sample: a _tree_state condition with installs as writers (_tree_claimed_for_install, held across download AND extraction) and one-shot sd-cli runs as readers (_tree_reader around engine.generate). An install that finds a reader stands down and retries on a later load; a generation that arrives mid-install waits, logging why, up to a generous timeout. No cycle with the existing locks: readers never take _install_lock and the writer never takes _generate_lock, and neither holds _tree_state across the long operation. Regression tests: test_a_generation_cannot_start_inside_the_install_window (a real thread blocked mid-install, then released) and test_an_install_stands_down_while_a_generation_is_running.
| _safe_extractall(zf, target) | ||
| # An archive that carries no sd-server leaves the PREVIOUS accelerator's one in place, and | ||
| # the record written below would then label the whole tree as this accelerator: the backend | ||
| # rediscovers that stale server, trusts the record and runs a CUDA request on the old CPU | ||
| # build forever. Drop what this bundle did not provide, so the tree and its record agree. | ||
| if _may_own and not ships_server: | ||
| _discard_stale_sd_server(target) |
There was a problem hiding this comment.
Remove superseded binaries when archive layouts change
When an accelerator upgrade extracts its binaries into a different supported layout than the previous bundle, this merges the new archive into the managed tree but removes an old server only when the new archive contains no server at all. For example, an old build/bin/sd-server remains higher priority in sd_cpp_engine._layout_candidates() than a newly extracted versioned-subdirectory server; the install record is then updated to the requested accelerator, so _accelerator_changed() trusts the tree and continues launching the old accelerator build indefinitely. The same stale-path problem applies to sd-cli; remove superseded executable copies that were not supplied at their existing paths before recording the completed install.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and the layout-priority detail is the part that makes it stick: build/bin outranks the prebuilt's versioned subdirectory in _layout_candidates, so a stale copy there wins over the one just extracted. Fixed in 4ef7b86 by generalising the sweep: _archive_binary_paths reads from the member list where each executable lands, and _discard_superseded_binaries removes every managed sd-cli AND sd-server that this bundle did not write, at any path, before the record is committed. Removal failure still raises, so the record is withheld and the next load retries. Regression tests: test_a_bundle_drops_the_binaries_it_did_not_supply (old build/bin pair, new versioned subdir) and test_a_bundle_keeps_every_binary_it_wrote.
| val = _INSTALLED_ACCELERATOR_MEMO.get(str(root)) or read_install_record(root).get("accelerator") | ||
| return val if isinstance(val, str) and val else None |
There was a problem hiding this comment.
Let newer on-disk install records override the memo
When this process has installed a bundle once and the same managed root is subsequently updated by the supported installer CLI or another Studio process, this unconditional memo precedence permanently hides the newer on-disk record. For example, after this process memoizes cpu, an external CUDA install leaves the current process reporting cpu; a later CPU selection therefore considers the CUDA binaries a match and silently runs the wrong accelerator build. Reserve the memo fallback for record writes that actually failed, or invalidate it when the record on disk changes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fair, and it reconciles with the previous round rather than reversing it. Fixed in 4ef7b86: the memo is now written ONLY when the record write actually failed, and it is keyed on the record content seen at that moment. So it answers for exactly the stale file it could not replace, and the moment anything else rewrites that file (the installer CLI, another Studio) the snapshot no longer matches, the memo is dropped and the file wins again. A successful write also retires any earlier memo. Regression tests: test_an_external_record_update_retires_the_memo and test_a_successful_record_write_retires_an_earlier_memo.
|
Correcting my earlier note on this PR and finishing the measurement. I said the 410 s GGUF figure was a CPU number. It was not. I read the wrong Studio home, an older one from the previous day holding the CPU build; the home that produced the clip had installed the cuda12 asset from this PR tag and was already running it. The controlled benchmark, both binaries, identical raw sd-cli arguments, 960x544 / 124 frames / 8 steps / cfg 1.0 / seed 11, one B200:
27.5x. The CPU build spends almost 80 minutes on a 5.17 s clip. So this PR is worth more than the earlier note suggested. It is the difference between 3 minutes and 80 for any Linux CUDA host using the native engine, and the failure mode if the pin ever regresses is silent: the tag is a plain string, so nothing turns red, the binary simply stops being accelerated. Frame 40 of the CUDA render is the same red panda scene at the same seed, so this is a real speedup and not a truncated run. |
DEFAULT_TAGwasmaster-809-eb7f35c, two releases behind. The new pin,master-813-bfbef5b-u13b9d92, is the first release to carry a Linux x86_64 CUDA bundle alongside the CPU and Apple assets.Why the CUDA asset matters here
The H3 video path already asks for an accelerated binary:
and the fallback right below it explains itself: "Upstream currently publishes no Linux CUDA archive." So on a CUDA host the request could not be satisfied, the code dropped to the CPU prebuilt and moved
native_devicetocpu.That is not a rare corner. MiniMax-H3's diffusers path wants roughly 68.5 GB of VRAM, so any consumer card falls back to the GGUF engine, which meant falling back to a CPU binary. Measured on one box, same tag, same model:
Verified against the real release, not just the fixture
autostill takes the plain CPU build, which matters because the CUDA bundle ships the CUDA runtime and is about 25x the size.rocmstill resolves toNone, since the mirror does not build it and an explicit GPU request must never be handed a CPU zip.The bundle itself, checked on a GPU box before pinning it
Unpacked on a host with an NVIDIA driver and no CUDA toolkit on the path:
libcuda.so.1is the driver and is deliberately not bundled; everything else resolves out of the bundle's own directory. The--list-devicesoutput is the specific thingsd_cpp_lists_accelerator_deviceneeds to see for the CPU fallback not to fire, and compute capability 10.0 confirms the architecture list reaches Blackwell in practice rather than only in the cmake flags.Tests
The first commit pins the resolver's Linux GPU branch, which had no test at all despite being about to matter: cuda resolves the bundle, a host that did not ask still gets the plain build, and a release without the asset resolves to
Nonerather than a CPU zip. That last one is what makes the video path's fallback correct.The fixture lists the CUDA asset ahead of the plain build. That is the order a real release lists them in, since
-cuda12.zipsorts ahead of.zip, and it is also the order that exposesautopicking by position rather than by the accelerator-marker filter.test_mirror_linux_gpu_accel_is_no_match_not_cpuasserted that cuda was among the accelerators the mirror does not build. It does now, so cuda comes out of that list and vulkan and rocm stay.Four mutations, all caught: an explicit GPU miss falling through to the CPU build; cuda dropped from the auto exclusion markers; cuda resolving through the wrong marker; vulkan and rocm silently resolving to the CPU zip.
studio/backend/tests/test_sd_cpp_install.py: 47 passed.Follow-ups, not blocking
The bundle is 1.15 GiB compressed.
libcublasLt.so.12is 752 MB of that and is unavoidable if we ship the runtime, butsd-cliandsd-serverare 361 MB each and carry near-identical copies of the same fat CUDA kernels; building ggml as a shared library should take roughly 350 MB off. Separately,sd-cli --helpreportsversion unknown, so anything wanting to ask the binary its own age has to infer it. Both are raised on the mirror side.