Repository navigation
Ask the spoof-survival question in a subprocess, not in the worker - #10866
Conversation
#10864 added tests/python/test_accelerator_skip_guards.py to stop tests gating hardware on a probe the aggressive CUDA spoof patches process-wide. One of its own tests then did exactly the thing the file exists to prevent. test_the_recorded_answer_survives_the_spoof called spoof.apply() in-process. That sets torch.cuda.is_available to return True and never restores it, so the rest of the xdist worker runs believing there is a CUDA card. peft's infer_device() opens with `if torch.cuda.is_available(): return "cuda"`, so tests/test_save_lora_without_vllm.py::test_the_saved_adapter_still_loads_back, scheduled onto the same worker, asked safetensors to load an adapter onto CUDA and died with NotImplementedError: Could not run 'aten::empty_strided' with arguments from the 'CUDA' backend Nothing about that names the cause, and the guard test itself passed. Which victim gets hit depends on how xdist distributes work, so it looked like a flake in an unrelated file for two rounds of investigation. Reproduces deterministically in two files, in this order: pytest tests/python/test_accelerator_skip_guards.py \ tests/test_save_lora_without_vllm.py before: 1 failed, 18 passed after: 20 passed The question now goes to a subprocess, the same pattern tests/vllm_compat/test_unsloth_zoo_imports.py uses since #10855, and for the same reason: a question about global state has to be asked somewhere the answer cannot leak back. Coverage is unchanged, it still asserts the spoof really does patch is_available and that the recorded answer does not move. Also adds test_this_file_never_applies_the_spoof_in_process, an ast check that this file never regains an in-process spoof.apply(). Worth pinning structurally because the damage is invisible at its own site and lands on whichever test the scheduler happens to run next. Full Repo tests (CPU) on this branch: 1 failed, 18523 passed, 497 skipped. The one failure is test_lint_exec_literals::test_the_baseline_matches_the_tree_it_ was_recorded_against, which fails identically on clean d7e5c6b and is a separate matter.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 431613c787
ℹ️ 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".
| offenders = [ | ||
| f"line {node.lineno}" | ||
| for node in ast.walk(tree) | ||
| if isinstance(node, ast.Call) and _dotted(node.func)[-2:] == ("spoof", "apply") |
There was a problem hiding this comment.
Detect aliases of the spoof module
This structural guard only rejects calls whose receiver is literally named spoof. If the in-process call is restored using _spoof.apply()—the alias already used by the version/vLLM compatibility tests—or any other import alias, offenders remains empty and the worker-wide CUDA patch can leak again. Resolve the alias imported from _zoo_aggressive_cuda_spoof, or otherwise detect calls to that module independently of the local variable name.
Useful? React with 👍 / 👎.
Why
#10864 added
tests/python/test_accelerator_skip_guards.pyto stop tests gating hardware on a probe thattests/_zoo_aggressive_cuda_spoof.pypatches process-wide. One of its own tests then did exactly the thing the file exists to prevent. My fault, and this is the fix.test_the_recorded_answer_survives_the_spoofcalledspoof.apply()in-process. That setstorch.cuda.is_availableto return True and never restores it, so the rest of the xdist worker runs believing there is a CUDA card.peft.infer_device()opens with:So
tests/test_save_lora_without_vllm.py::test_the_saved_adapter_still_loads_back, scheduled onto the same worker, asked safetensors to load an adapter onto CUDA on a CPU-only box:Nothing in that names the cause, and the guard test itself passed. Which victim gets hit depends on how xdist distributes work, so it presented as a flake in an unrelated file.
Reproduction
Deterministic in two files, in this order:
The fix
The question goes to a subprocess, the same pattern
tests/vllm_compat/test_unsloth_zoo_imports.pyhas used since #10855, and for the same reason: a question about global state has to be asked somewhere the answer cannot leak back. Coverage is unchanged. It still asserts that the spoof really does patchis_available(so the test cannot quietly become vacuous) and that the recorded answer does not move.Also adds
test_this_file_never_applies_the_spoof_in_process, anastcheck that this file never regains an in-processspoof.apply(). Worth pinning structurally rather than trusting: the damage is invisible at its own site and lands on whichever test the scheduler runs next, which is precisely why it took two wrong hypotheses to find.How I got it wrong, since it is relevant to reviewing this
Two bad calls worth recording:
hf-internal-testing/tiny-random-LlamaForCausalLMand I had run two suites concurrently. Plausible, untested, and wrong.Both would have been avoided by capturing the traceback first. The comparison runs used
--tb=no, so the first real diagnostic arrived several rounds late. The runs behind this PR use--tb=short.Checks
1 failed, 18 passedto20 passed.spoof.apply()makes it fail and name the line number.Repo tests (CPU)on this branch: 1 failed, 18523 passed, 497 skipped. The single failure istest_lint_exec_literals::test_the_baseline_matches_the_tree_it_was_recorded_against, which fails identically on cleand7e5c6baawith no changes applied, so it is pre-existing and separate.ruff check --select E9,F63,F7,F82clean; the pinnedruff-format-with-kwargshook is a fixed point.