Repository navigation
Ask the vllm-free import tests in a clean interpreter, not in sys.modules - #10855
Conversation
…ules
test_rl_replacements_imports_without_vllm and
test_empty_model_imports_without_vllm fail on current main, and the thing
they report is not true: neither module imports vllm.
$ python -c "import sys; import unsloth_zoo.rl_replacements;
print('vllm' in sys.modules)"
False
$ python -c "import sys; import unsloth_zoo.empty_model;
print('vllm' in sys.modules)"
False
`"vllm" in sys.modules` is a property of the PROCESS, not of the import
under test. Three tests further down this same file import
vllm_lora_request, vllm_lora_worker_manager and vllm_utils, all of which
hard-import vllm, and once any of them has run, vllm is in sys.modules for
good. Popping the module under test first does not help: its dependencies
stay cached too, so the re-import never re-executes them and the assertion
cannot observe what it claims to. The result passed or failed on test
ordering.
Both checks now run in a fresh interpreter via subprocess, which is the
only place the question has a meaningful answer. The probe re-applies the
same CPU spoof this module applies at import, so CPU-only runners keep
their coverage, and subprocess + sys.executable behaves the same on Linux,
macOS and Windows.
The probe is not vacuous. Pointed at a module that genuinely does import
vllm it reports so:
unsloth_zoo.rl_replacements -> NOVLLM
unsloth_zoo.empty_model -> NOVLLM
unsloth_zoo.vllm_lora_request -> VLLM
File result: 3 failed, 2 passed -> 1 failed, 4 passed. The one that stays
red is test_vllm_utils_imports, which is a true positive and a separate
unsloth_zoo issue: vllm_utils.py hard-imports
vllm.model_executor.layers.quantization.bitsandbytes at module scope, and
vLLM 0.29 removed it.
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: 09ee6c86ce
ℹ️ 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".
| "import _zoo_aggressive_cuda_spoof as s\n" | ||
| "s.apply()\n" | ||
| f"m = __import__({module_name!r}, fromlist=['_'])\n" |
There was a problem hiding this comment.
Recreate the pynvml stub in the child interpreter
In the version-compat CPU workflow, unsloth-zoo is installed with --no-deps and the explicit dependency list does not install pynvml; importing either submodule first executes the unsloth_zoo package initialization, whose NVML access is why this test stubs pynvml above. That stub exists only in the pytest process, so this fresh interpreter can fail with ModuleNotFoundError: pynvml before reporting whether vLLM was imported, making both repaired tests fail on their intended CPU runner. Include the same optional-dependency stub in the probe prelude before importing the target module.
Useful? React with 👍 / 👎.
…10866) #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.
test_rl_replacements_imports_without_vllmandtest_empty_model_imports_without_vllmfail on currentmain, and what they report is not true. Neither module imports vllm:Why the check could not work
"vllm" in sys.modulesis a property of the process, not of the import under test.Three tests further down the same file import
vllm_lora_request,vllm_lora_worker_managerandvllm_utils, all of which hard-import vllm. Once any of them has run, vllm is insys.modulesfor the rest of the process. Popping the module under test first does not help either: its dependencies stay cached, so the re-import never re-executes them, and the assertion cannot observe what it claims to.So the test passed or failed on test ordering, and on this box it was reporting a transitive vllm import that does not exist.
Fix
Both checks run in a fresh interpreter through
subprocess, which is the only place the question has a meaningful answer.The probe re-applies the same CPU spoof this module applies at import time, so CPU-only runners keep their coverage, and
subprocess+sys.executablebehaves the same on Linux, macOS and Windows.The probe is not vacuous
Pointed at a module that genuinely does import vllm, it says so:
So a real transitive vllm import would still fail the test, which is the property that matters.
Result
tests/vllm_compat/test_unsloth_zoo_imports.pygoes from 3 failed, 2 passed to 1 failed, 4 passed, running the whole file in one process, which is the ordering that used to break it.The one that stays red is
test_vllm_utils_imports, and it is a true positive rather than something to paper over.unsloth_zoo/vllm_utils.pyhard-importsvllm.model_executor.layers.quantization.bitsandbytesat module scope, and vLLM 0.29 removed that module, soimport unsloth_zoo.vllm_utilsfails outright on current vllm. That needs a fix in unsloth-zoo and is filed separately.Note for later
The same pattern appears in a few other tests (
test_broken_tf_does_not_break_import.py,test_peft_tensor_parallel_compat.py,test_windows_no_sentencepiece.py). They are green today, so I have left them alone rather than widen this diff, but they are exposed to the same ordering sensitivity. Several other tests in the tree already do the subprocess-probe thing correctly, so the pattern to copy is there.