Repository navigation
select("auto") does not launch the MPS probe twice - #260
Draft
jaredpalmer wants to merge 2 commits into
Draft
jaredpalmer wants to merge 2 commits into
jaredpalmer wants to merge 2 commits into
Conversation
A timeout shorter than the torch import kills the child before it can print kev-probing, so the MPS fallback still ran and the warning named the timeout twice. The child now prints kev-probing auto before the availability check. The parent starts the MPS child only after it has seen that line or kev-probing cuda, and the warning names the device the child reached. TimeoutExpired.output stays bytes when text=True, so the parent decodes it before reading the lines. Co-authored-by: Jared Palmer <hello@jaredpalmer.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--device autoon a machine with no CUDA already asks its probe child to try MPS. If that child fails or times out,selectlaunches a second child with the samempsargument. The CPU fallback then waits out two probe timeouts, 60 seconds with the defaultKEV_DEVICE_PROBE_TIMEOUTwhen the child hangs, and the warning names the failure twice. A timeout shorter thanimport torchdoes the same thing, because the child is killed before it can print anything.kev.train,kev.evaluate,kev.benchmark, andkev.experimentall callselect. Explicit--device mpswas already one child. Reported by @luc-pimentel in #255.The child prints
kev-probing autoonceimport torchhas returned, beforetorch.cuda.is_available(). It printskev-probing mps,cuda, orcpuagain before the allocation, and flushes both lines. The parent starts a second child only when it seesautoorcuda.mpsmeans that allocation is already the one that failed, so it is not started again. Nokev-probingline means the child died during import, and another process would import the same torch.The result line is still
kev-device <device>.kev-probingdoes not start with that prefix, so the announcement cannot make a failed probe look successful. A ROCm banner is ignored unless a whole line is exactly one of these markers.TimeoutExpired.outputstays bytes whentext=True, becausecommunicate()decodes the stream only after it returns. The parent decodes those bytes, then reads the lines. A signal or a Python exception comes back as text onCalledProcessError. The warning names the device the child reached, so a failed MPS attempt shows up once, asmps.A hang inside
torch.cuda.is_available()still tries MPS, becausekev-probing autois already on stdout. A hang insideimport torchis the same work the next child would do, so that child is not started. There is no core file if torch crashes while loading, the probe timeout is stillKEV_DEVICE_PROBE_TIMEOUT, and auto still tries the Apple GPU before CPU when the CUDA child got that far.This does not skip the second child when a CUDA probe reports that this torch has no MPS backend. That child can only fail, and it adds a clause to the warning. It also does not read MPS availability in the parent, the process a driver crash must not kill, and it does not change the MLX serve path, which never runs this probe.
The
kev-probingline before the allocation, and the rule that a child which already saidmpsis not probed again, are @gezerui888's, from #256. This branch keeps that commit. The import-timeout case is the oneKEV_DEVICE_PROBE_TIMEOUT=0.3hits, because the child dies during import, before that line exists. On this machine the torch import takes about 1.0s. Before the follow-up,select("auto", timeout=0.3)took 0.61s and the warning named both timeouts.Test plan
pytest tests/test_device.py tests/test_conventions.py: 100 passed. Covers a real child that sleeps insideimport torch, a real child whose CUDA check sleeps, bytes timeouts with a ROCm banner, a banner line that only contains the marker text, and the signal and dtype-error stand-ins.select("auto", timeout=0.3)on this machine returnedcpuin 0.31s with one warning,auto: ... timed out after 0.3 seconds, and no secondmpsclause. A healthyselect("auto")returnedcpuwith no warning.test_auto_names_cuda_and_mps_failures_oncewas added: 606 passed, 26 skipped.test_resume_is_bit_identical[1-gate0]andtest_snapshots_are_checkpoints_kept_and_completed_on_resume[1]failed once and passed on rerun. Both train with--device cpu, which returns before a probe.Fixes #255.