Repository navigation
Studio: contain RAG embedder torch allocation crashes - #8609
Conversation
|
Agreed on consolidating here, and thanks for porting the child-process handling across. I am closing #8601 in favour of this one. Your scoping call is the right one. Leaving Your narrower verdict rule is also better than mine, and for the right reason: isolation only needs to cover what cannot be caught in-process. An ordinary Python exception from the child will be raised identically by the loader, which reports it better than a silent CPU downgrade does. The fp16 matmul is a more faithful probe than my Three things I would fix before this lands. The first is the one place I would not follow you. 1. "No information" should fail closed, not open.
I agree with you that an ordinary Python failure from a child that ran and reported should defer to the loader. But a probe that never ran, or whose verdict we could not read, has not told us the device is fine, only that we do not know. Suggest keeping your signal and timeout rule and adding "could not run" and "could not be read" to the unusable side. 2. The post-kill except subprocess.TimeoutExpired:
try:
process.kill()
except OSError:
pass
try:
_, stderr = process.communicate(timeout = _TERMINATE_GRACE_SECONDS)
except subprocess.TimeoutExpired: # an OSError here escapes
_reap_later(process)
except OSError: # sibling, never sees the above
passAn This is the same bug Codex found in #8601 at the last round; the shape came across with the port. I fixed it by escalating terminate and kill through one loop with a single pair of handlers, so no attempt sits in a branch the handlers cannot see, and anything not confirmed dead reaches the reaper: 8101abdde. 3. On POSIX any negative return code counts, so a probe child killed by the OOM killer, by a container stop, or by an operator marks a perfectly healthy GPU unusable for the life of the process. Two smaller notes, neither blocking:
Your scope note is right that a fatal signal during a later |
…atal-signal set Three fixes on top of the probe. A probe that could not be spawned, or whose result could not be read, was treated as proof the device works, so the backend went on to make the in-process allocation this exists to prevent. It is not evidence either way, and the two ways of being wrong are not symmetric: CPU costs embedding speed, the accelerator costs the process. Unknown now means unusable for an accelerator. It keeps meaning usable for CPU, which is the opposite trade. A CPU load cannot fault a GPU driver, and condemning it would send the caller past its CPU fallback to the GGUF backend, changing the embedding space and forcing a reindex over what may be a passing failure to fork. _terminate_and_drain could raise on the path where the device really had failed. The post-kill read sat inside the timeout branch, where the trailing except OSError was a sibling and could not see it, so a pipe failure escaped device_can_allocate: a timed-out device raised instead of returning False, the child never reached the reaper, and since lru_cache does not cache exceptions the next call re-ran the whole probe. Terminate and kill now escalate through one loop with a single pair of handlers. _died_by_signal counted every negative return code, so a probe killed by the OOM killer, a container stop or an operator condemned a healthy GPU for the life of the process. Narrowed to the hard-fault set LlamaCppBackend._is_signal_crash already uses, which excludes SIGKILL and SIGTERM for the same reason.
|
Pushed the three review items to the branch directly (ef49978) since maintainer edits are on, rather than leave you to apply them. Shout if you would rather I had opened a PR against your fork instead. One of them changed shape once I traced it through your fallback chain, and that is worth explaining. Failing closed on "no verdict" is right for an accelerator, but applying it to CPU as well would have been a regression. The other two are as described. Your deferral rule is untouched: a child that RAN and raised an ordinary exception still returns true, so the loader reports it. Verified against a real GPU here, where a bad ordinal exits nonzero without a signal and correctly defers: Tests: your Two things from my earlier comment are still open and both are yours to take or leave: the |
…n the XPU selectors The self-limit was a threading.Timer, which cannot fire in the one case it exists for: a torch hung inside a native call never returns to the interpreter loop, so the GIL is never released and the callback never runs. SIGALRM with no handler installed is enforced by the kernel, runs no Python and needs no GIL, so an orphaned probe stops on time. Windows has no alarm and keeps the timer. The cache key covered the CUDA and ROCm selectors but not the Intel ones, while _TORCH_DEVICE maps DeviceType.XPU to "xpu", so the probe runs there too. A change to ZE_AFFINITY_MASK or ONEAPI_DEVICE_SELECTOR moves the silicon underneath a cached verdict: a stale pass skips the probe on an untested device, a stale failure pins a working one to CPU.
|
Codex Review: Didn't find any major issues. 👍 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". |
|
c74d703 correctly addresses the GIL-dependent deadline and XPU cache identity. Adding Two code details remain:
The module docstring and PR description also still state that spawn failures defer to the in-process loader, which no longer matches For completeness, the XPU identity tuple could also include |
A child that stopped itself hung, and a hang is a device failure, but neither form of it was recognised. SIGALRM is not a hard fault so the kernel-enforced deadline fell through _died_by_signal, and the Windows watchdog status is an ordinary non-zero exit. Both were reported as a healthy device, which then let the parent make the allocation the probe stands in front of. Reachable when the parent did not enforce its own shorter timeout first, such as a suspended backend. Both forms now return False, and the exit status the child writes is pinned against the constant the parent matches on.
hardware.py already counts GPU_DEVICE_ORDINAL as a live ROCm visibility mask, so changing it renames the silicon behind "cuda" exactly as the other masks do. The cache key did not include it, so a verdict taken before the change was reused for a device that was never probed, and a stale pass is the direction that costs the backend. Also pins the cache key against the set hardware.py honours, so the two lists cannot drift apart again.
Two ways the probe reported a device it had not cleared. exec keeps an inherited SIG_IGN and an inherited blocked signal mask, so under a supervisor that ignores or blocks SIGALRM the child deadline was unenforceable and an orphaned probe could sit on a hung driver indefinitely. Verified: with the disposition inherited the child ran to completion and exited 0. It now restores SIG_DFL and unblocks the signal before arming the alarm. A native abort() on Windows leaves the CRT's plain exit status 3 rather than an NTSTATUS, so it read as an ordinary non-zero exit and the crashing device came back usable, which let the parent repeat the crash in its own process. Status 3 is now a hard fault there, matching LlamaCppBackend._is_abort_exit, with a test pinning the two to the same value.
|
Codex Review: Didn't find any major issues. Delightful! 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". |
test_chat_text_encoding enforces that anything spawning a Python child and decoding it as utf-8 also tells the child to write utf-8, and it reads the Popen call itself. The wrapper was applied several lines earlier, so the probe was flagged and the check failed on this branch. Wrapping at the call site keeps the same single application and puts it where the policy test can see it.
A probe killed by SIGKILL or SIGTERM is not a hard fault, so it is no evidence against the device, but it is not the clean run that earns a pass either. It was returning true, and importing torch and building its device context is enough on its own to trip a cgroup or host OOM, so the very condition that killed the probe sent the caller on to a much larger load in the backend process. Unclassified child deaths now take the existing no-verdict path: unusable for an accelerator, still usable for CPU, which cannot fault a driver and whose fallback would otherwise change the embedding backend. The module docstring was describing the older fail-open behaviour and is corrected with it.
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
Problem
#8564 removed the eager RAG embedder warmup, so a mismatched torch build no longer kills Studio during startup. The underlying crash still occurs on the first RAG operation:
embeddings._get()loadsSentenceTransformeron the detected accelerator, and an incompatible ROCm stack can terminate the backend during its first allocation (#7331, gfx1151).Fatal driver signals cannot be caught by the existing Python exception handlers. Lazy loading therefore changed when the crash happens, not whether it happens.
Fix
Probe the selected torch device in a short-lived child before loading sentence-transformers. The probe performs an fp16 allocation and matmul, which also initializes the vendor BLAS library.
A fatal signal or timeout marks the device unusable. Ordinary Python exceptions and spawn failures are left to the existing in-process loader so the probe does not reject a working device based on an incomplete result.
The fallback order is:
TorchDeviceUnusableErrorwhen CPU also fails, allowing the existing llama-server fallback to take over.Probe results are cached per device. Set
UNSLOTH_STUDIO_DISABLE_DEVICE_PROBE=1to restore the previous behavior.Scope
This protects the initial torch allocation and BLAS initialization. A fatal signal during a later
encode()call can still terminate the backend and would require isolating every encode operation.Verification
Closes #8474.