Repository navigation
Conversation
A hub connection that is slow rather than failing blocks AutoTokenizer.from_pretrained indefinitely, so this test wedges the whole studio suite (and a self-hosted GPU runner's job budget) instead of skipping as its docstring promises. --timeout cannot interrupt a blocked socket read, and the test is gated on CUDA so it only ever runs where the hub may be slow. Run the fetch on a daemon thread with a wall-clock deadline and skip when it expires; a daemon thread is used because ThreadPoolExecutor joins its workers at interpreter exit, which would move the hang to teardown.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd9bb15374
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if thread.is_alive(): | ||
| raise TimeoutError(f"timed out after {timeout}s") |
There was a problem hiding this comment.
Terminate the model load before reporting the timeout
Whenever this timeout branch is reached, the daemon thread is left running, so the hub fetch is not actually stopped: it can continue writing the cache and, if the connection recovers, proceed to load the model onto CUDA after pytest has already skipped the test. On a long-running self-hosted suite this can leave a cache lock held or consume GPU memory concurrently with later tests. Use a cancellable subprocess or underlying client timeouts so the timed-out load is terminated before returning.
Useful? React with 👍 / 👎.
| try: | ||
| def load(): | ||
| tokenizer = AutoTokenizer.from_pretrained(MODEL_ID) | ||
| model = AutoModelForCausalLM.from_pretrained(MODEL_ID, dtype = dtype).to("cuda") |
There was a problem hiding this comment.
Preserve the selected CUDA device in the loader thread
When a multi-GPU runner selects a nonzero device with torch.cuda.set_device() rather than masking devices with CUDA_VISIBLE_DEVICES, that selection is local to the main host thread; this new loader thread starts with CUDA device 0, so .to("cuda") places the model on GPU 0 while the later main-thread .to("cuda") places inputs on the selected GPU. Generation then fails with a device mismatch, and parallel workers can also pile onto GPU 0. Capture the main thread's device and use an explicit indexed device in both locations.
Useful? React with 👍 / 👎.
|
|
||
| try: | ||
| # offline / gated / slow hub access is not a code defect | ||
| tokenizer, model = _with_deadline(load, FETCH_TIMEOUT_SECONDS) |
There was a problem hiding this comment.
Keep local GPU loading outside the hub timeout
When the model is already cached but deserialization or the CUDA transfer stalls for more than 300 seconds, the entire load callback times out here and the surrounding handler reports the smoke test as skipped for an unreachable model. That converts the model/GPU-loading regression this smoke is intended to detect into a passing CI outcome. Apply the reachability deadline only to the download stage, then perform cached model construction and GPU placement under the normal pytest failure/timeout path.
Useful? React with 👍 / 👎.
The deadline wrapped the whole load on a daemon thread, which had three consequences: - A thread cannot be interrupted, so a stalled fetch kept running after the test had already skipped. It could still write the cache, and once the connection recovered it could still load onto CUDA. - torch.cuda.set_device() is per-thread, so a runner that selected a nonzero device got the model on device 0 while the inputs went to the selected one. - Bounding construction and the CUDA transfer as well turned a stalled local load into a skip, hiding the very regression this smoke exists to catch. The fetch now runs in a child process that is killed at the deadline, and it covers only populating the hub cache. Construction, placement and generation run on the test's own thread, with no deadline, so a local failure fails.
|
Thank you for the PR and for the detailed write-up! After checking it, we will not be merging this one, for these reasons:
The stall you saw on the A100 was probably caused by something in that environment, for example a proxy, or |
What
tests/studio/test_gpu_inference_smoke.pyis CUDA-gated, so it only runs where the hub may be slow,and its fetch had no deadline. A hub connection that is slow rather than failing blocks
AutoTokenizer.from_pretrained(MODEL_ID)indefinitely, which contradicts the docstring's"download failure is not a code defect" skip. On a self-hosted GPU runner that wedges the whole
suite, and
--timeoutcannot interrupt a blocked socket read.Observed on an A100 before the change:
do_poll— blocked on a socket, not computing~/.cache/huggingfacestayed at 0 bytes, so the download was not progressing--timeout=600fired but could not break the blocked readBisecting
tests/studio/in 15-file chunks put the failure in the chunk containing this file, andthe suite's last logged test was
test_gpu_inference_smoke.py::test_gpu_generation_smoke.Fix
Run the fetch on a daemon thread with a wall-clock deadline and skip when it expires. A daemon
thread is used rather than
ThreadPoolExecutor, whose workers are joined at interpreter exit —that would move the hang to teardown instead of removing it.
Verification
On A100-PCIE-40GB:
_with_deadline(lambda: time.sleep(30), 2)raisesTimeoutErrorafter 2.0s, and thenormal return path still returns its value
HF_ENDPOINT=http://10.255.255.1:9) and thedeadline temporarily lowered to 20s:
1 skipped in 20.09swithtimed out after 20s— beforethe change this blocked indefinitely
The rest of
tests/studio/is unaffected: the other nine 15-file chunks pass without it (the onlyfailing chunk was this one).
I searched issues and PRs for this and did not find an existing report.