Repository navigation
Load path: read an adapter's base config through the probe memo, skip the remote mapper for unknown LoRA bases in Studio - #16793
Merged
Conversation
…the probe memo FastModel.from_pretrained probed the adapter base's config.json directly for the diffusion check, so every adapter load reaching FastModel repeated a probe the per-load memo already answers (or answers right after). Same arguments, same except-Exception fallback; the memo returns a deep copy and never stores trust_remote_code results or network errors.
_load_download_repos called get_model_name on the adapter base unguarded, so a base the installed mapper does not know fetched mapper.py from GitHub before the load, and from_pretrained fetched it again. For such names get_model_name only returns the base itself or raises, so the repo list is unchanged; reuse the guard core/inference/inference.py already applies.
danielhanchen
marked this pull request as ready for review
November 6, 2026 07:48
Member
Author
|
@codex review |
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. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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
added a commit
that referenced
this pull request
Nov 6, 2026
…e stubbable package (#16898) ## Summary Since #16793 (`90e1e733c4`), Backend CI `(Python 3.13, g-r)` fails on unrelated PRs. The last hour's staging runs for #16887, #16886 and #16882 all show the same two tests: ``` tests/test_load_download_repos_mapper.py:11: in test_unmapped_lora_base_skips_the_remote_mapper from unsloth.models import loader_utils E ModuleNotFoundError: No module named 'unsloth.models'; 'unsloth' is not a package ``` What #16793 tests (skipping the remote mapper for unknown LoRA bases) is fine. The two new tests guard with `pytest.importorskip("unsloth")` and then `from unsloth.models import ...`. In the backend job, several test files stub `unsloth` at import time as a plain module (`_stub_if_missing` in `test_audio_type_inconclusive.py` and others) when the real package cannot be loaded. If one of those runs earlier in the same xdist worker, `importorskip("unsloth")` returns the stub instead of skipping, and the submodule import fails. Run alone, or in a worker where nothing stubbed it, the tests pass. That is why it depends on how the shard is laid out. ## Change - `studio/backend/tests/test_load_download_repos_mapper.py`: `importorskip` the submodules the tests use (`unsloth.models.loader_utils`, `unsloth.models.loader`). With a stub in place they now skip, the same as with no unsloth at all. With the real package they run unchanged. - `studio/backend/tests/test_backend_tests_stub_heavy_imports.py`: `test_no_test_importorskips_bare_unsloth` fails if any backend test calls `pytest.importorskip("unsloth")` on the bare package, and pins its own detector both ways. No other backend test does this today. The rule is narrowed to `unsloth`, since the `trl` stubs carry the attributes their tests read. ## Testing On `studio/backend`, with a one-line test file that stubs `sys.modules["unsloth"]` as a plain module run first (what the shard does): | | main | this branch | |---|---|---| | stub first, then `test_load_download_repos_mapper.py` | 2 failed (the error above) | 2 skipped | | `test_load_download_repos_mapper.py` alone, real unsloth | 2 passed | 2 passed | | `test_backend_tests_stub_heavy_imports.py` | 6 passed | 7 passed | Putting back the original `importorskip("unsloth")` makes the new guard fail and name `test_load_download_repos_mapper.py`.
danielhanchen
added a commit
that referenced
this pull request
Nov 6, 2026
… memo tests (#16908) ## 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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two repeated lookups on the LoRA load path.
1.
FastModel.from_pretrained: adapter base config read through the probe memoWhen an adapter is loaded through
FastModel(Gemma 3 / 4, Qwen-VL, gpt-oss and otherFastModelfamilies, and Studio LoRA loads), the diffusion dispatch check read the base model's config with a directAutoConfig.from_pretrainedcall. The probes just before and after it in the same load already ask for the same config through_memo_config_probe, so this one repeated theconfig.jsonHEAD and the resolve-cache HEAD on every adapter load.It now goes through
_memo_config_probewith the same arguments and the sameexcept Exceptionfallback. The memo's existing rules apply unchanged: it returns a copy, and never storestrust_remote_coderesults or errors.Local LoRA on a tiny Gemma 3 Hub base:
AutoConfigcalls, with / without a tokenThe saved probe costs 85 ms median online here (53 to 143 ms, n = 10); on a home connection at 150 ms per request it is about 300 ms per adapter load. The final weight-load call and the order of the load events are identical in all 20 runs, and a missing base raises the same error with the same text.
2. Studio worker: skip the remote mapper for a LoRA base the installed mapper does not know
_load_download_repos(which lists the repos a load will download) calledget_model_name(base)for every LoRA base. For a base that is not in the installed mapper tables, that fetches and parsesmapper.pyfrom GitHub, and the answer is either the base itself (already in the list) or an exception (ignored), so the repo list never changes. The load then fetches the remote mapper again on its own. The worker now callsget_model_nameonly for names in the installed mapper tables orBAD_MAPPINGS(the check_loader_repoincore/inference/inference.pymakes, except thatBAD_MAPPINGSnames still go through the mapper here, as on main). Any other base resolves to itself, so the pre-quantized suffix strip applied whenALLOW_PREQUANTIZED_MODELSis off (AMD Instinct on bitsandbytes < 0.49.2) still lists the stripped repo the loader downloads.Saves one GitHub GET per Studio LoRA load with such a base: 58 ms median here (40 to 89 ms, n = 5), and seconds when GitHub is slow.
Tests
tests/python/test_load_probe_memo.py::test_fastmodel_adapter_load_probes_base_config_once(string token andFalse): fails on main, passes here, on transformers 4.57.6 and 5.22.1. A missing-base case passes on both and keeps the same error.studio/backend/tests/test_load_download_repos_mapper.py::test_unmapped_lora_base_skips_the_remote_mapper: fails on main (2 mapper fetches), passes here; the returned repo lists are identical on both.studio/backend/tests/test_load_download_repos_mapper.py::test_unmapped_prequantized_base_still_lists_the_stripped_repo: passes on main, pins that an unmapped-bnb-4bitbase with pre-quantized models disabled still lists the stripped repo.studio/backend/tests/test_load_downloads.py: its loader stub gained the mapper tables the guard reads; passes on both.Not covered