Skip to content

Tests: undo the Unsloth load's PEFT LoRA forward swap after the probe memo tests - #16908

Merged
danielhanchen merged 1 commit into
mainfrom
ci-load-probe-memo-restore-lora
Nov 6, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci-load-probe-memo-restore-lora

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Repo tests (CPU, studio) has been failing on unrelated PRs since #16793 landed, always in the same test with a different parameter each time:

tests/python/test_preference_chunked_logprobs.py:278: in test_matches_trl
    torch.testing.assert_close(g, w, rtol = 1e-4, atol = 1e-6)
E   AssertionError: Tensor-likes are not close!
E   Mismatched elements: 1 / 32 (3.1%)
E   Greatest absolute difference: 3.814697265625e-06 at index (0, 6) (up to 1e-06 allowed)

Seen on the staging runs for #16109, #16886, #16882 and #16877 today (cpo-kwargs1, kwargs2, kwargs3, kwargs5, kwargs6, always qwen3_lora).

The cause is test pollution. #16793 added test_load_probe_memo.py::test_fastmodel_adapter_load_probes_base_config_once, which runs FastModel.from_pretrained up to the weights. That load does what it does in real use: it swaps PEFT's LoRA forwards (peft.tuners.lora.layer.Linear and 8 other LoRA layer classes) for Unsloth's, process-wide, and sets UNSLOTH_FORCE_FLOAT32, UNSLOTH_FULLGRAPH, UNSLOTH_RETURN_LOGITS and UNSLOTH_MODEL_NAME. The test never puts them back, so when xdist schedules the CPO parity test on the same worker later, it compares the chunked path against TRL on Unsloth's LoRA forward instead of stock PEFT, and its tight gradient tolerance trips. The swapped forward is the part that matters: restoring only the environment variables still fails with the same numbers, restoring only the forwards passes.

Neither side's product code is wrong. #16793's loader change and its probe-count assertions are correct; only the test leaks process state.

Change

Tests only.

  • tests/python/test_load_probe_memo.py: an autouse fixture records every PEFT LoRA layer class's own forward and the UNSLOTH_* variables before each test and puts them back after. A PEFT module first imported during the load falls back to the _unsloth_original_forward the wrapper carries.
  • tests/python/test_preference_chunked_logprobs.py: test_matches_trl[...-qwen3_lora] pins stock PEFT forwards for its duration (through monkeypatch), since its reference is TRL on stock PEFT. This keeps it deterministic whatever else ran earlier in the worker.

Testing

The failing worker's exact history from a local rerun of the CI shard (-n 4 --dist loadgroup) replayed serially reproduces the CI failure with the same numbers, and bisects to the #16793 test. With that test followed by test_matches_trl[cpo-kwargs1-qwen3_lora]:

result
main 1 failed (3.814697265625e-06 at index (0, 6), as in CI)
this branch 2 passed
this branch, parity test pin removed 2 passed
this branch, probe memo fixture disabled 2 passed
this branch, both removed 1 failed (same numbers)

The same failing worker's history replayed serially (1595 tests) on this branch: test_matches_trl[cpo-kwargs1-qwen3_lora] passes. On main the same replay fails it. One other failure in both arms, test_cached_paths_hold_no_credentials.py::test_model_cache_variables_are_not_treated_as_credential_homes, comes from this machine's environment; it passes in CI and is unchanged here.

Both touched files pass in full: tests/python/test_load_probe_memo.py plus tests/python/test_preference_chunked_logprobs.py, 33 passed (torch 2.10.0+cpu, transformers 5.17.0, TRL 1.15.0, PEFT 0.21.2, the CI shard's versions).

… memo tests

test_fastmodel_adapter_load_probes_base_config_once (#16793) runs
FastModel.from_pretrained up to the weights, which swaps PEFT's LoRA
forwards and sets UNSLOTH_* variables for the whole process. A later
test in the same xdist worker then ran on Unsloth's LoRA forward:
test_preference_chunked_logprobs::test_matches_trl[cpo-*-qwen3_lora]
drifted past its gradient tolerance in Repo tests (CPU, studio).

Put both back after every test in test_load_probe_memo.py, and pin
stock PEFT in the parity test, whose reference is TRL on stock PEFT.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 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-11-06T12:52:31.157430Z 61876c8 Manual request
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 61876c8b47

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 7a13256 into main Nov 6, 2026
@danielhanchen
danielhanchen deleted the ci-load-probe-memo-restore-lora branch November 6, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant