Repository navigation
Studio sd.cpp: a lost Vulkan device is not a strike; Arc / ROCm keep Vulkan; a UHD iGPU beside a card no longer vetoes Vulkan - #14610
Conversation
… leave Vulkan only on decisive evidence, a UHD iGPU beside a dedicated card no longer vetoes Vulkan, one shared device listing - VK_ERROR_DEVICE_LOST no longer counts toward moving the Vulkan build to CPU (the spec makes it recoverable by recreating the device). Vulkan records written before this rule keep only their decisive evidence. - Ambiguous Vulkan failures move only the CPU-torch host routed to Vulkan to CPU sd.cpp; an XPU host and a ROCm host on its Vulkan rung leave Vulkan only on a decisive failure. - A UHD iGPU beside an AMD card or an Arc no longer keeps a CPU torch off Vulkan: unpinned ggml-vulkan lists only dedicated GPUs when there are any and sd.cpp takes a GPU before an iGPU. GGML_VK_VISIBLE_DEVICES may be space separated, as ggml reads it. - --list-devices readers share one listing keyed by the binary's size and mtime and the device-selection environment; the accelerator verdict still probes afresh.
…PU no longer vetoes 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. |
…he same build; status counts the evidence the runtime does; a UHD beside an Arc needs the Arc's own render node
…in; a replacement stays pending until handed into the load state
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2cf69b51fe
ℹ️ 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".
| # A UHD iGPU beside an AMD card or an Arc: unpinned sd.cpp takes a discrete GPU before an iGPU | ||
| # (get_default_backend_name), so the card renders. Alone, or under a GGML_VK_VISIBLE_DEVICES list | ||
| # (whose ordinals may name the iGPU), the iGPU would. | ||
| if vk_mask is not None or not any(_renders(d) for d in gpus): |
There was a problem hiding this comment.
Require a Vulkan driver for the renderable card
On a CPU-Torch host with an Intel UHD iGPU and an AMD card, this relaxation admits Vulkan whenever either device is considered renderable, but the final driver check accepts an ICD for any vendor in gpus. If both render nodes are mounted while only the Intel ICD is installed or loadable, _hardware_vulkan_driver({"amd", "intel"}) succeeds from that Intel manifest even though the AMD card cannot be enumerated; sd.cpp then sees and selects only the UHD device that this route intentionally treats as slower than CPU. Require the loadable ICD to belong to at least one of the cards for which _renders is true.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4d6d069. The final ICD check in _vulkan_gpu_for_cpu_torch only counts drivers for vendors whose card renders. With a UHD iGPU beside an AMD card, an Intel-only ICD no longer qualifies. When every card renders the vendor set is unchanged. The test covers UHD plus Vega with only an Intel driver (stays on CPU) and with an AMD driver (Vulkan).
… listing cache keyed on the hardware inventory generation; the UHD relaxation needs a driver for the rendering card [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d6d069da0
ℹ️ 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".
| with self._lock: | ||
| self._pending_server = server | ||
| try: | ||
| server.start( |
There was a problem hiding this comment.
Make replacement startup honor generation cancellation
When cancellation or a superseding load sets cancel after the check at the start of _respawn_server_after_device_loss, this blocking server.start() never observes that event; cancel_generate() only sets the event and, unlike unload(), does not stop _pending_server. Consequently the cancelled generation can continue loading the replacement for the full 600-second startup timeout while holding _generate_lock, delaying cancellation and any replacement load. Stop the pending replacement when this generation is cancelled or make the startup wait observe cancel.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 367158185. The replacement start (both the device-loss respawn and the CPU-backend restart) now goes through one helper that runs a small watcher while server.start() blocks. If the generation's cancel event is set, from cancel_generate() or a superseding load, the watcher stops the pending server, its readiness wait returns at once, the pending slot and the replacement mark are cleared, and the generation raises SdCppCancelled instead of loading for the full startup timeout under _generate_lock. A start that fails without a cancel still returns None with the original error, and a successful start is unchanged. The new test cancels during a fake replacement start and checks the generation returns promptly with both servers stopped, no retry posted and nothing left pending.
…instead of loading it for the full timeout [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f3ef3b257
ℹ️ 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".
| published = self._state is not None and self._state.server is not None | ||
| if published: | ||
| self._state = state |
There was a problem hiding this comment.
Verify the original state before replacement handoff
If a superseding begin_load() commits while the generation thread is paused after _start_replacement() returns, this check accepts the new load merely because it has a non-null server and then overwrites it with the old model's replacement state. The superseding server is consequently left alive but untracked, while the cancelled generation becomes the published load again. Require _state.server to still be the original server captured by _begin_replacement() before publishing; otherwise stop the replacement as stale.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b12351521. The generation now passes the server it replaced into _hand_over_replacement, and under the lock the replacement is published only if _state.server is still that exact server. If an unload cleared the state, or a superseding load put its own server there while the replacement was starting, the replacement is stopped and the generation raises SdCppCancelled, leaving the newer load untouched. The replacing mark is cleared only if it still points at that old server. The device-loss respawn and the CPU-backend restart share this handover. The new test swaps in a newer load during a fake replacement start and checks the newer server stays published and alive, the stale replacement is stopped, no retry is posted and nothing is left pending.
| if record.get("cards"): | ||
| kept["cards"] = list(record["cards"]) |
There was a problem hiding this comment.
Retain only cards with decisive evidence
On a multi-card host, if card A has a decisive Vulkan failure and card B has only ambiguous strikes, this filter keeps only A in per_card but copies both names into cards. A later lookup for B then misses the per-card branch in _record_diverts() because B is still a known card and falls through to the record-wide proven=True, incorrectly diverting B to CPU based on A's failure. When no unscoped proof exists, the filtered cards list must be restricted to proven_cards.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b12351521. When an old-rule record has no unscoped proof, _decisive_evidence_only now keeps only the proven cards in cards, so a card with only ambiguous strikes takes the per-card branch of _record_diverts and is not diverted by another card's failure. With unscoped proof every named card stays known as before. The new test builds an old record with card A proven and card B ambiguous only: A still diverts and B stays on Vulkan.
…an old-rule record keeps only its proven cards known [skip ci]
|
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". |
…d on the CPU backend where the CPU rung applies; nothing persisted [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7cd8713e8f
ℹ️ 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".
| and not any(d.get("vendor") == "amd" for d in gpus) | ||
| and not _reachable_intel_arc_render_node() |
There was a problem hiding this comment.
Validate the Arc node even when AMD is inventoried
On Linux with AMD, Arc, and UHD devices in the inventory, this skips the per-device Arc reachability check merely because an AMD card exists. If the container exposes the AMD and UHD render nodes but not the Arc node, and only the Intel ICD is loadable, rendering_vendors still contains Intel because of the inaccessible Arc and the route accepts Vulkan; in reality the Intel ICD can enumerate only the UHD while the AMD card has no driver, so sd.cpp runs on the iGPU this route is meant to reject. The Arc-node check must remain applicable whenever Intel is being counted as a rendering vendor, regardless of an inventoried AMD card.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, fixed in deef88e26. The Arc node check no longer depends on whether an AMD card is in the inventory. When a UHD is also present and this process cannot open the Arc's own render node, the Arc is dropped from the rendering set. After that, Intel only counts as a rendering vendor when its Arc is actually reachable. With AMD + Arc + UHD, an unreachable Arc node and only the Intel ICD loadable, the route now stays on CPU. If the AMD card's own driver loads, it still goes to Vulkan because the AMD card renders. If the Arc node is reachable, the Intel driver can vouch for it as before.
Test: test_an_arc_beside_an_amd_card_and_a_uhd_still_needs_its_own_node covers the four combinations. The (unreachable Arc, Intel ICD only) -> auto case fails on the previous head, which returned vulkan.
…s device cpu; an unreachable Arc node never vouches for the Intel driver, even beside an AMD card [skip ci]
|
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". |
Resolve the sd-server retry block: keep the device-loss recovery loop (same-build respawn, CPU backend after a repeated loss, guarded handover) and restage the hires model upscaler under every replacement server, including the respawn and the CPU fallback. [skip ci]
|
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". |
…ps diverting only those cards [skip ci]
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
Summary
Follow-up to #13697 from a post-merge review. #13697 added a Vulkan to CPU step to the native image engine's fallback ladder for every host, and counted Vulkan "device lost" errors as strikes. Two transient device-lost faults therefore moved Intel Arc hosts (whose image build is always Vulkan) and ROCm hosts already on their Vulkan fallback to the CPU sd.cpp build, and the record persisted across restarts. The Vulkan spec treats a lost device as recoverable by recreating it (Windows TDR and amdgpu recovery reset it routinely), so it is not proof the build cannot run.
What changes
rule: 2now) keep only their decisive evidence, so old device-lost strikes stop diverting to CPU.get_default_backend_name). A UHD iGPU alone, or aGGML_VK_VISIBLE_DEVICESlist (whose ordinals may name the iGPU), keeps today's answer.GGML_VK_VISIBLE_DEVICESseparated by spaces is accepted, as ggml reads it.--list-devicescache for the five readers that only need the listing, keyed by binary path, size, mtime and the device-selection environment (the Vulkan list, ICD variables and CUDA/HIP/ROCR masks). Timeouts and unreadable answers are never cached. The accelerator verdict still probes afresh, since a load's re-check relies on seeing a changed listing, and it refreshes the cache.Tests
tests/test_sd_cpp_vulkan_cpu_torch.py: two lost devices keep Vulkan (CPU torch and GPU torch); ambiguous strikes move only the CPU-torch host while decisive evidence moves every host; an old ambiguous record is ignored and an old proven one holds; UHD + Vega routes to Vulkan (also with both render nodes mounted); a space-separated mask is accepted; three listing reads cost one probe and an environment change re-probes; an unreadable listing is not cached. On main exactly the 10 new or updated tests fail. Related suites (diffusion routes, sd.cpp backend, VRAM budget, ROCm Vulkan fallback, H3 matrix, native GPU decision): 1003 passed on this branch.Not run on real Arc, ROCm-Vulkan or UHD + discrete hardware.
Repeated device loss. A host that loses the Vulkan device on every render (for example a Windows TDR on a slow iGPU) no longer fails every request after the single respawn. If the respawned sd-server loses the device too in the same request, that load moves to the CPU backend (
--backend cpu, same checkpoint, slower) with a warning in the log, and later requests on that load stay there. Nothing is persisted: no strike, no failure record, so the next load resolves and tries the Vulkan build again. This only happens where the Vulkan-to-CPU rung already applied, which is the CPU-torch host routed to Vulkan withUNSLOTH_DIFFUSION_SD_CPP_VULKAN_FALLBACKleft on. A GPU the user picked (agpu_idspool orUNSLOTH_DIFFUSION_SD_CPP_DEVICE) is never moved to CPU, and Arc / ROCm hosts keep Vulkan. In those cases the second loss returns the original error plus a hint (Low VRAM mode, a smaller resolution or quant, or reload to retry on the GPU), and the hint text matches no failure marker, so it records no strike either. A single loss still respawns once on the same device with its pin and LoRAs, as before.