Repository navigation
Studio: validate legacy sd binary discovery - #8560
Conversation
|
Codex Review: Didn't find any major issues. Breezy! 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". |
The legacy PATH probe answers "is this stable-diffusion.cpp". The H3 gate was answering "does this build carry H3" and reporting the result as if it had answered the first, so an unrelated binary reached through SD_CLI_PATH was described as a stable-diffusion.cpp build predating MiniMax-H3 -- true of every program that is not stable-diffusion.cpp, and the sentence that sent unslothai#8507 looking for a newer build of something never installed. - share one predicate, help_text_identifies_sd_cpp, between the two callers - the H3 gate takes ONE --help and derives both answers from it, asking identity first. --ref-video is a plain option name that unrelated reference-video tools also expose, so returning on the marker alone readmitted the same class of program through the override - a user-supplied binary that is not stable-diffusion.cpp gets a message saying so, and the log lines on the managed path name the actual fault - memoize the identity verdict per file revision (path + mtime + ctime + size). Discovery runs on every load and ensure_sd_cpp_binary resolves twice, so an unrelated "sd" was executed once per discovery. Only a verdict the probe produced is cached: a timeout leaves the file unchanged, so caching that "no" would blacklist a genuine build until Studio restarts
ensure_h3_sd_cpp_binary exists to refuse a build that cannot run H3 before the four-file bundle is fetched, and its own error said so. _run_load_h3_native called it after the download loop, so every refusal still cost tens of GB, and a None return -- auto-install off, an unsupported platform, no network, or a managed copy something else is running out of -- was not rejected until later still. - move the preflight and the accelerator fallback above the asset resolution - check cancel_event before it: the preflight may install the prebuilt and takes no cancel_event, so a load cancelled before its worker started paid for an install nobody was waiting for. The download loop used to be the first check - refuse a preflight that produced no binary there, rather than after the downloads. The claimed re-vet keeps its own check; that one guards a replacement arriving mid-download - test_sd_cpp_h3_matrix.py covers platform x GPU vendor x binary state, because the combinations are what broke: a CPU-only prebuilt on a CUDA host reaches its refusal through the fallback, and that path downloaded the bundle on the way to failing
|
Thanks for this - the diagnosis is right and I have pushed two commits on top of it. Confirming the root cause with the real binaryRather than a fixture, I used the actual Ubuntu package:
So the reporter's binary almost certainly is not an old stable-diffusion.cpp at all. macOS is exposed the same way through Worth noting the blast radius was wider than MiniMax-H3: on such a host, plain image generation was also pointed at the wrong program, since The one assumption worth checking against the real artifactThe identity probe is only safe if the binary Studio actually installs identifies itself. That is not stock upstream - it is the Unsloth mirror build, pinned at Both of your acceptance branches match it independently - the banner, and all three of What the two commits add1. Identity and capability are different questions. The gate answered "does this build carry H3" and reported it as if it had answered "is this stable-diffusion.cpp". Every program that is not sd.cpp is missing Asking capability first was also a hole your PATH fix closes and the override path did not: The verdict is now memoized per file revision (path + mtime + ctime + size). Discovery runs on every load and 2. The H3 preflight now runs before the download. TestingEverything is driven against real executables on a real PATH, not mocked
Two pre-existing issues I deliberately left alone, both outside this PR's scope: |
# Conflicts: # studio/backend/core/inference/sd_cpp_backend.py
…es reach it Mutation testing found the one production change in this branch that could be reverted silently: forcing fault back to the H3 wording left every test green. That log line is the same wrong diagnosis unslothai#8507 was reported as, written to the log instead of the user. The comment above it also claimed only an env override reaches that branch. An in-tree developer build and a PATH sd-cli do too, since the identity gate covers only the sd stem.
A binary that cannot load a shared library exits 127 from the dynamic loader with nothing identifying on either stream. That is a CompletedProcess, not an exception, so the previous rule cached it as a definitive "not stable-diffusion.cpp" against a file that never changed, and installing the missing library would not get it re-probed until restart. Memoize a decisive verdict only: identifying output settles it whatever the exit code, and otherwise only a clean exit is evidence of anything. The case this memo exists for is unaffected, since Debian/Ubuntu's sd answers --help with rc 0.
Both found in review of the move itself. Re-check cancellation on the way out of the preflight. The ensure takes no cancel_event and can spend minutes downloading and extracting the prebuilt, so a cancel arriving during it is already late; a CPU or MPS target then skipped the claimed accelerator probe (the only other cancel-aware step) and paid four sequential model_info round trips before the download loop noticed. Re-vet EVERY binary after the download, not only a managed one. The managed-only test was written when the ensure sat right there, so a user-supplied build had been vetted microseconds earlier and only a concurrent install could have moved underneath it. Vetting before the download makes that window the whole download -- long enough to rebuild or repoint an SD_CLI_PATH copy, after which the replacement became the recorded identity that every later generation compares against.
…nswers Both from review of the previous round. The post-download re-vet asked only the capability question. --ref-video is a plain option name that unrelated reference-video tools expose too, so a swap to one of those cleared a marker-only check and was then recorded as the vetted build. It now applies the same identity-and-capability pair the preflight does, off one --help. And the memo key is not a content revision on Windows: st_ctime there is the CREATION time, which an in-place overwrite preserves, so a same-sized write that also restores mtime leaves the whole tuple unchanged. Hashing the binary per lookup would trade the exec this memo avoids for a full read on a path walked every load, so verdicts expire instead. That bounds what the key cannot see on any platform, and a minute is still far longer than the several resolutions inside one load.
native_device is decided on the accelerator reading and then committed for the life of the runtime, and moving that reading before the download made the gap between deciding and committing the whole fetch. The re-check still only ran for a managed binary, so a user's own build rebuilt inside that window committed a GPU device around a CPU executable -- offload policy and an arbiter claim written against hardware nothing is running on. The comparison needs a decisive reading, which is why this adds the verdict form rather than reusing sd_cpp_lists_accelerator_device: that one folds "could not tell" into True, and against a recorded False it would refuse the very CPU fallback that recorded it.
…mpare it to Hoisting the verdict out of the condition made every H3 load spawn --list-devices, including the CPU and MPS targets that deliberately never record a baseline and so cannot use the answer. On a build that hangs on that flag it cost the full probe timeout before readiness, for a value the comparison then discarded.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
The identity gate added in unslothai#8560 reads --help for a stable-diffusion.cpp banner before the H3 capability marker, so these fixtures need one to reach the load path they exercise.
_run_load_h3_native is about assets, and the block that acquires the sd-cli, installs it, probes its device list and decides native_device now sits at the top of it because unslothai#8560 moved that work in front of the download. Nothing in the block reads a resolved path, so it reads better as _h3_native_binary returning the three values the rest of the load needs. Pure move. The behaviour it encodes -- the entry and exit cancellation checks, the accelerator fallback, the refusal when no binary could be produced -- is unchanged, which the 168 platform x GPU vendor cases in test_sd_cpp_h3_matrix.py pin without modification.
…8657) * studio: claim the H3 companion repos before the preflight, not after it asset_repos is what stops the delete-cached guard admitting a delete of the H3 companion repos while a load is pulling from them. #8560 moved the sd-cli preflight ahead of the four-file download, which is right, but the claim stayed below it, so the window the guard is blind to is now the whole prebuilt install: minutes, not microseconds. A delete admitted inside that window is not revoked by claiming the repos afterwards, and it can then remove cached files underneath the load that follows. The base_repo and asset_repos claim moves above the preflight. expected_bytes stays where it is, since the sizes are not known any earlier. * studio: publish the H3 companion claim with the loading state * studio: tighten the H3 companion claim comments * studio: re-read the load guard after reserving the delete scope * studio: tighten the delete re-read comments
… smaller card (#8644) * studio: give minimax-h3 the sd.cpp graph-cut flags so it renders on a smaller card H3 allocates each module whole on the device when its graph runs, so --offload-to-cpu is not enough on its own: the 20.5 GB pruned denoiser and the 17 GB Qwen3-VL encoder ask for the full module at once and cudaMalloc fails on a 12 GB card. The abort lands in the conditioner before any tensor is resident, so VRAM never rises and it presents as a model that never loaded rather than an out-of-memory error. sd.cpp's graph-cut executor is what splits a module into segments that fit, and Studio never asked for it. The H3 native path now adds --max-vram -1 --stream-layers. A negative budget auto-detects free VRAM per device, sparing that many GiB, and a module that already fits merges back into a single segment, so a setup with room pays nothing for this. It is deliberately not gated on the memory mode: auto and fast are what users reach first and are exactly the modes that fail. sd_cpp_supports_graph_cut reads both options out of --help and fails closed, the opposite default to the H3 gate next to it. sd-cli exits non-zero on an option it does not know, so an unreadable probe has to emit nothing rather than break a build that renders today. The CPU runtime never asks, since it allocates from system RAM. Part of #8636. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * carry the sd.cpp project banner in the h3 help fixtures The identity gate added in #8560 reads --help for a stable-diffusion.cpp banner before the H3 capability marker, so these fixtures need one to reach the load path they exercise. * Gate --stream-layers on --offload-to-cpu for PR #8644 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>
Summary
sdexecutables found through PATH before accepting them as stable-diffusion.cppsd-cliinstaller path to continuesd-clidiscovery, genuine legacysdbinaries, and the existing MiniMax-H3 capability gateRoot cause
Native diffusion discovery accepted the first executable named
sdon PATH solely by filename. Unrelated tools using that generic name could therefore be treated as user-supplied stable-diffusion.cpp binaries and suppress managed installation.The legacy PATH fallback now performs a bounded, read-only
--helpidentity probe. It accepts stable-diffusion.cpp project output or the option signature present since the original legacy CLI, and logs a precise rejection for unrelated candidates.Potential impact
This may resolve reports where Studio identifies
/usr/bin/sdas a stable-diffusion.cpp build that predates MiniMax-H3 and consequently skips installing the pinned managedsd-cli. It applies when that PATH executable is an unrelated command; a genuine manually installed legacy stable-diffusion.cpp binary remains subject to the existing capability gate.May resolve issue #8507.
Validation