Skip to content

Repair the four checks that are red on main itself - #11216

Closed
danielhanchen wants to merge 3 commits into
mainfrom
fix/cpu-python-shard-red-on-main
Closed

danielhanchen wants to merge 3 commits into
mainfrom
fix/cpu-python-shard-red-on-main

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Four checks are red on main itself: Repo tests (CPU, python), Repo tests (CPU, rest), Repo tests (CPU, studio) and workflow-trigger lint. Every open PR inherits all four. Same shape as #11139 and #11207; every cause below landed on main today, and none of it belongs to any PR that is now failing because of it.

Reproduced on a clean checkout of main with no PR content at all, which is how each was attributed:

8 failed, 286 passed, 1 skipped
  5x tests/test_st_save_merged_signature.py            KeyError: "'__name__' not in globals"
  2x tests/studio/test_installer_av_shapes.py          install.ps1 / studio/setup.ps1 contain 'bitdefender'
  1x tests/python/test_accelerator_skip_guards.py      two skip guards read a spoofed probe

1. Two skip guards read a probe the spoof patches process-wide

test_no_skip_guard_reads_a_spoofable_accelerator_probe:

E       test_apply_qkv_fallback.py:235: torch.cuda.is_available()
E       test_lora_dropout_patch_summary.py:104: torch.cuda.is_available()

Both files came in with #11038. tests/_zoo_aggressive_cuda_spoof.py patches that probe to True process-wide, so on a CPU-only runner both tests un-skip and try to load a real checkpoint through FastLanguageModel.

Gated on the probes that failing test names, and on the distinction its sibling test_no_cuda_only_test_is_gated_on_the_broad_accelerator_probe enforces: has_real_cuda() for test_apply_qkv_fallback_end_to_end, which asks for a cuda device, and has_real_accelerator() for the other, which does not. Gating the first on the broad probe instead trips that sibling, correctly, since it is also true on an XPU-only or Ascend-only host.

2. A launcher test takes the real, shared runtime lock

Observed red on #11126, job 104949989945:

unsloth_cli/_studio_runtime_gate.py:224: in studio_runtime_launch_guard
    fcntl.flock(lock_file.fileno(), flags)
E   BlockingIOError: [Errno 11] Resource temporarily unavailable
E   StudioRuntimeGateBusy: /home/runner/.unsloth/studio/.studio-runtime.lock
E   typer._click.exceptions.Exit: 1
[gw3]

unsloth_cli/commands/studio.py resolves STUDIO_HOME once, at import, and _studio_runtime_launch_guard takes a non-blocking flock on the one .studio-runtime.lock beneath it. Left at the real ~/.unsloth/studio that file is shared by every xdist worker, so two tests in this shard that reach update() together collide and the loser exits 1 on a machine where nothing is wrong. Confirmed rather than inferred:

STUDIO_HOME (module-level, resolved at import): ~/.unsloth/studio
lock file: ~/.unsloth/studio/.studio-runtime.lock
while parent holds it -> CHILD REFUSED

_configure_windows already redirected it to tmp_path; the tests that build their own environment, including the one that failed, did not. Moved into the studio fixture. Measured either side, with the real lock deleted first:

~/.unsloth/studio/.studio-runtime.lock after the file runs
before created
after never appears

3. A vendor name in two shipped PowerShell scripts

#10533 put Bitdefender in install.ps1 and studio/setup.ps1. test_installer_av_shapes.py refuses that, and the reason is in its own header: PowerShell hands the entire top-level script block to AMSI at compile time, so comments are classifier input, and VirusTotal's analysis of install.ps1 quoted one of our own comments back as grounds for suspicion.

The comment keeps the part that matters, that controlled folder access is not Defender-only and the user cannot act on advice that does not name the product holding the lock, and points at the record. The vendor name moves into AV_SHAPES_RECORD with #10533 as the anchor, which is what test_the_record_survives_and_keeps_its_evidence exists to require: the ban must be satisfied by moving the knowledge, not deleting it.

4. The sentence-transformers probe cannot resolve a deferred relative import

Every behavioural test in test_st_save_merged_signature.py died with KeyError: "'__name__' not in globals" at <string>:21.

#11067 deferred from ..save import _is_adapter_save_method into _save_pretrained_merged, to keep the unsloth.save import cycle closed. The harness execs that closure into a bare dict, on purpose, so that calling it imports no unsloth. A relative import then has no __name__ or __package__ to resolve against.

Given a synthetic package to be relative to, and the real predicate lifted out of unsloth/save.py by the same source extraction the file already uses for _normalize_save_method. Nothing is stubbed: anything else the closure defers later still fails loudly on a missing attribute rather than passing against a fake.

That unmasked a stale expectation the KeyError had been hiding. test_the_forwarding_path_still_accepts_lora asserted that "lora" is forwarded when modules.json is present; #11067 deliberately made it an error on that path too, for a different reason than the no_modules branch, and said so in the source:

Refused because nothing here writes base weights ... Before unsloth#11067 "lora" matched no branch in merge_and_overwrite_lora and fell through to a 16bit merge, which happened to write something loadable; an error is the honest replacement.

The test now asserts the refusal it actually has, and that it refuses before merging the adapters away, before writing a half-finished directory, and without forwarding the request on. Worth noting on its own: the file was red for a harness reason, so the disagreement underneath it was never reached by anybody.

Checks

  • tests/python/test_accelerator_skip_guards.py: 24 passed.
  • tests/test_apply_qkv_fallback.py tests/test_lora_dropout_patch_summary.py: still collect, 76 passed, 2 deselected.
  • tests/studio/test_installer_av_shapes.py: 242 passed, 1 skipped.
  • tests/test_st_save_merged_signature.py: 28 passed.
  • the four tests/python files that touch the runtime gate, -n 8: 99 passed, 32 skipped.
  • the whole Repo tests (CPU, rest) selection, -n 12: 7788 passed, 162 skipped, 0 failed.

… the shared lock

Repo tests (CPU, python) is red on main. Two causes, neither of them a PR's.

test_accelerator_skip_guards fails on the two files #11038 added: both gate on
a bare torch.cuda.is_available(), which tests/_zoo_aggressive_cuda_spoof.py
patches to True process-wide, so they un-skip on a CPU-only box and try to load
a real checkpoint. Gated on the probes that test names, has_real_cuda() for the
one that asks for a cuda device and has_real_accelerator() for the one that does
not. All 24 guard tests pass; the two files still collect, 76 passed.

The second is a flake, and it is the one that cost this job a red run.
studio.py resolves STUDIO_HOME once at import, and update() takes a
NON-BLOCKING flock on the single .studio-runtime.lock beneath it. Left at the
real ~/.unsloth/studio that file is shared by every xdist worker:

  STUDIO_HOME: ~/.unsloth/studio
  lock:        ~/.unsloth/studio/.studio-runtime.lock
  second holder -> StudioRuntimeGateBusy -> typer.Exit(1)

which is exactly how test_non_windows_preserves_call_order_without_launcher_operations
died on gw3 with nothing wrong. _configure_windows already redirected it; the
tests that build their own environment did not. Redirecting in the fixture
covers both. Measured: before, the run creates the real lock file; after, it
never appears.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-17T15:49:50.752337Z 62e291b PR opened
🔒 Security Review ✅ Completed 2026-09-17T15:49:51.851346Z 62e291b PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…esolve its import

Two more checks that are red on main itself, both from PRs that landed today.

Repo tests (CPU, studio) and workflow-trigger lint: #10533 put 'Bitdefender' in
install.ps1 and studio/setup.ps1. test_installer_av_shapes refuses that, and the
reason is in its own header: PowerShell hands the entire top-level script block
to AMSI at compile time, so comments are classifier input, and VirusTotal quoted
one of our own comments back as grounds for suspicion. The comment still says
the thing that matters, that the feature is not Defender-only and the user has
to be told which product to open; the vendor name moves to AV_SHAPES_RECORD
where the file's own rule says it belongs, with #10533 as the anchor, so the
knowledge is moved rather than deleted.

Repo tests (CPU, rest): every behavioural test in test_st_save_merged_signature
died with KeyError: "'__name__' not in globals". #11067 deferred the relative
import of _is_adapter_save_method into _save_pretrained_merged, and
the harness execs that closure into a bare dict, which a relative import has
nothing to resolve against. Given a package to be relative to, and the real
predicate lifted out of unsloth/save.py by the same source extraction the file
already uses for _normalize_save_method.

That unmasked a stale expectation the KeyError had been hiding:
test_the_forwarding_path_still_accepts_lora asserted that "lora" is forwarded
when modules.json is present, and #11067 deliberately made it an error on that
path too, for a different reason than the no_modules branch. Rewritten to assert
the refusal it actually has, and to check it refuses before merging, before
writing, and without forwarding.
@danielhanchen
danielhanchen force-pushed the fix/cpu-python-shard-red-on-main branch from c0f97e3 to 6840c66 Compare September 17, 2026 17:24
@danielhanchen danielhanchen changed the title Repair the two things making Repo tests (CPU, python) red on main Repair the four checks that are red on main itself Sep 17, 2026
Source lint: HOISTED-IMPORT-UNUSED 'torch' was used before, now unused.
torch.cuda.is_available() in the skipif was the file's only use of it, and that
call is what the guard fix replaced.
@danielhanchen

Copy link
Copy Markdown
Member Author

Windows Unsloth GGUF CI is red here and it is not this PR. Three checks in tests/studio/test_path_probe_access_denied.ps1 fail:

FAIL  a denied cache that can be renamed is moved aside, not reported
FAIL  the moved cache leaves the original path free for the reinstall
FAIL  the unmovable cache is not left half-renamed

All three are behavioural assertions about the llama.cpp cache preflight that #10533 added today, and they sit inside the CAN_DENY: True branch, so the runner did reach them. The neighbouring checks of the same feature pass, including an unreadable llama.cpp cache that cannot be moved stops the install, so the preflight runs; the recover-by-rename half is what does not do what the test says.

The only reason this PR sees it is that it edits install.ps1, which is what triggers that workflow. The edit is a comment, and provably nothing else:

$ diff <(git show origin/main:install.ps1     | strip-comments) <(strip-comments install.ps1)
IDENTICAL once comments are stripped
$ diff <(git show origin/main:studio/setup.ps1 | strip-comments) <(strip-comments studio/setup.ps1)
IDENTICAL once comments are stripped

So it needs a fix of its own, on a Windows host where the rename path can actually be exercised, rather than a guess from here. Flagging it rather than folding it in: this PR is the four checks that are red on every PR, and that one is red only on a PR that touches the installer.

@danielhanchen

Copy link
Copy Markdown
Member Author

Result on this branch. The four this PR is about:

job before after
Repo tests (CPU, rest) 5 failed pass, 10m34s
Repo tests (CPU, studio) 2 failed pass, 21m8s
workflow-trigger lint 2 failed pass, 3m45s
Source lint - pass, 1m41s
Repo tests (CPU, python) test_accelerator_skip_guards failed that failure is gone, see below

Repo tests (CPU, python) is red again, on something that arrived after this branch was cut:

FAILED tests/python/test_docker_hub_readme.py::test_the_repo_readme_run_command_matches_the_image
  AssertionError: assert 'unsloth/unsloth:core' in '#### Docker\n\nThe [Unsloth Docker image](...)
  `unsloth/unsloth` is available on Docker. [Read guide.](...)\n\n'
1 failed, 5216 passed, 122 skipped

062e643 Update README.md shortened the Docker section and dropped the run command the test pins to the image. Reproduces on a clean checkout of main at 1d5210d, so it is not this branch. Not folded in here on purpose: the test and the README disagree about which of them is now right, the README edit looks deliberate, and guessing would undo someone's change. Left for whoever shortened it.

The rest of the red on this branch is shared with every other open PR, Core and Core zoo included, and reproduces the same way:

  • Core (HF=4.57.6 + TRL<1): test_import_fixes_drift.py, 'Gemma2Config' object has no attribute 'rope_parameters'. Version-gated, passes on 5.x.
  • Core zoo (x3): tests/test_per_layer_device.py, '_FakeLayer' object has no attribute '_per_layer_device'. That file is unsloth-zoo's, not this repo's.
  • GGUF inference smoke: the llama.cpp cache preflight, covered in the comment above.

@danielhanchen

Copy link
Copy Markdown
Member Author

Heads up: parts of this landed on main overnight via #11222, which is why the branch now shows conflicts.

Already on main:

  • install.ps1 / studio/setup.ps1 - the vendor name removed from Get-SecuritySoftwareNote, with the product-to-feature table moved into AV_SHAPES_RECORD where the guard's failure message asks for it
  • tests/studio/test_installer_av_shapes.py - the bitdefender entries
  • tests/test_apply_qkv_fallback.py, tests/test_lora_dropout_patch_summary.py - the skip guards moved off torch.cuda.is_available() onto tests/_shared/real_accelerator.py (has_real_cuda for the qkv one, since its body allocates on "cuda" by name)
  • tests/test_st_save_merged_signature.py - the harness now resolves the relative import Route save_method="lora" to the adapter save instead of the merge #11067 deferred, and test_the_forwarding_path_still_accepts_lora was rewritten to the post-Route save_method="lora" to the adapter save instead of the merge #11067 contract

Not on main, so still wanted from here: tests/python/test_windows_studio_update_launcher.py.

Apologies for the collision - I was triaging the same main-reds from the CI side and did not check the full open-PR list before opening #11222, only the batch I was driving. A rebase should drop most of the diff.

@danielhanchen

Copy link
Copy Markdown
Member Author

Closing this as superseded: every fix here is already on main, landed by #11222 while this sat open. Checked against ed91ec211 rather than assumed, item by item.

The two skip guards (tests/test_apply_qkv_fallback.py, tests/test_lora_dropout_patch_summary.py) now read the real probes on main, with the same distinction this PR drew:

test_apply_qkv_fallback.py:39        from real_accelerator import has_real_cuda
test_lora_dropout_patch_summary.py:27  from real_accelerator import has_real_accelerator

the narrow probe for the one that allocates on "cuda", the broad one for the other.

The shared runtime lock is redirected in the fixture on main:

tests/python/test_windows_studio_update_launcher.py:129
  monkeypatch.setattr(studio, "STUDIO_HOME", tmp_path / "studio_home")

The vendor name is gone from both shipped scripts (grep -i bitdefender install.ps1 studio/setup.ps1 finds nothing at ed91ec211), and the record this PR proposed adding to the test file is there, as AV_SHAPES_RECORD, carrying the same product table. The comment main now ships is better than the one here: it also says why the names are not repeated in a file that is scanned in full before it runs, and that nothing below hard-codes a product.

tests/test_st_save_merged_signature.py resolves its import on main and no longer raises KeyError: "'__name__' not in globals".

All four suites green on main:

tests/studio/test_installer_av_shapes.py
tests/test_st_save_merged_signature.py
tests/python/test_accelerator_skip_guards.py
tests/python/test_windows_studio_update_launcher.py
354 passed, 5 skipped

Nothing here is worth rebasing on top of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants