Repository navigation
Text diffusion loader: refuse a network-share base model named by a Hub adapter - #18961
Merged
danielhanchen merged 2 commits intoNov 23, 2026
Merged
Conversation
…ub adapter FastDiffusionModel.from_pretrained resolves an adapter's base itself, so the guard FastLanguageModel / FastModel run (unslothai#18923) never saw it. FastModel reaches this loader for any repo whose config is a text-diffusion type. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01Pa8JdyYMHkqNpdksTfdmRG
danielhanchen
added a commit
to Etherll/unsloth
that referenced
this pull request
Nov 23, 2026
…er (unslothai#18960) unslothai#18923 refuses a Hub adapter whose `base_model_name_or_path` is a Windows network share, and leaves local adapter folders alone. With `UNSLOTH_USE_MODELSCOPE=1` the adapter repo has already been swapped for its downloaded snapshot folder when the guard runs, so `os.path.isdir(model_name)` is true and a remote adapter naming `\\host\share\model` is followed to the base. Both loaders keep the original repo id in `modelscope_repo_id`, so the guard now gets `modelscope_repo_id or model_name`. Hub adapters and the user's own local adapter folders behave as before. Reproduced on main with a mocked `modelscope.snapshot_download` and Windows simulated the way `tests/test_adapter_unc_base_guard.py` does: `FastLanguageModel` and `FastModel` both reach `AutoConfig.from_pretrained` on the UNC base; with this change both raise the unslothai#18923 `ValueError`. Not run on a real Windows machine. Tests (both fail on main): - `tests/test_optimized_precision_conflicts.py::test_modelscope_adapter_with_network_share_base_is_refused` runs `FastLanguageModel.from_pretrained` through the existing extracted-loader harness with a ModelScope adapter snapshot. - `tests/test_adapter_unc_base_guard.py::test_both_loaders_check_before_the_base_is_used` now pins the repo-id argument at both call sites. The text-diffusion loader has the same gap by a different route; that is unslothai#18961. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Pa8JdyYMHkqNpdksTfdmRG --------- Co-authored-by: Claude Fable 5.2 <[email protected]> Co-authored-by: Daniel Han <[email protected]>
Member
|
@codex review |
1 similar comment
Member
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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. |
|
Codex Review: Didn't find any major issues. You're on a roll. 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
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Nov 24, 2026
…elf (unslothai#19170) Follow-up to unslothai#18923, unslothai#18960, unslothai#18961, unslothai#19101. ## Problem `AutoModel*.from_pretrained("org/repo")` looks for `adapter_config.json` itself, reads `base_model_name_or_path` from the raw JSON and loads that base (`auto_factory.py`, `integrations/peft.py`). The guard runs only where Unsloth parsed the adapter with PEFT, so two kinds of Hub repo still reach a base on a Windows network share: 1. **An `adapter_config.json` PEFT cannot parse.** With a valid `config.json` and e.g. `"peft_type": "NOT_A_PEFT_TYPE"`, `PeftConfig.from_pretrained` raises, the loader sets `is_peft = False`, skips the guard and loads the repo as a plain model. transformers then swaps in the named base. Applies to `FastLanguageModel` and `FastModel`. 2. **`FastSentenceTransformer`**, on the `for_inference = True` route and the fast encoder route. Both hand the repo id to `SentenceTransformer(...)`, whose Transformer module loads through transformers. A plain valid LoRA `adapter_config.json` is enough here. The default route through `FastModel` was already covered. ## Fix `_refuse_network_share_raw_adapter_base` in `loader.py` finds the file the way transformers does (`transformers.utils.find_adapter_config_file`), reads the base from the JSON and passes it to the existing guard. Called in both loaders when PEFT parsed nothing, and before both `SentenceTransformer(model_name, ...)` loads. Local folders are left alone, as before. ## Tests End to end, with real `transformers` / `peft` / `sentence-transformers` against an offline Hub cache, Windows simulated as in `tests/test_adapter_unc_base_guard.py`, spying on `os.path.isdir` / `isfile` / `exists` and `open`: | | main | this PR | | --- | --- | --- | | loader, unparseable `adapter_config.json` | UNC base reaches `exists`, `isdir`, `isfile` | `ValueError`, nothing probed | | ST `for_inference` | same three calls | `ValueError`, nothing probed | | ST fast encoder route | same three calls | `ValueError`, nothing probed | Same result on transformers 5.18.0 and 5.23.0 (sentence-transformers 6.3.0). These ran on macOS, so they show the path reaching the filesystem calls, not an SMB connection. The loader run uses the from-source harness of `tests/test_optimized_precision_conflicts.py` with a stand-in for `FastLlamaModel.from_pretrained` that calls `AutoModelForCausalLM.from_pretrained`; the sentence-transformers run executes the real `sentence_transformer.py` with its sibling imports stubbed. In the repo: `test_raw_adapter_config_with_unc_base_is_refused` (parseable and unparseable config, a Hub base, no adapter file, a local folder) and `test_routes_that_hand_a_hub_id_to_transformers_check_the_raw_config` (the four call sites sit before the load). Both fail on main. The `loader` fixture stubs the new helper so those tests do not ask the Hub. Follow-ups on this branch: the loader check reads the same pinned snapshot the config probe and weight load use (`_resolved_revision`), and both sentence-transformers checks fall back to `SENTENCE_TRANSFORMERS_HOME`, which `SentenceTransformer` honours and `hf_hub_download` does not. ## Not covered - A ModelScope snapshot with an unparseable `adapter_config.json`, the fp8 offline-quantize path and `FastDiffusionModel` after a failed PEFT parse: same shape by reading, not run, not changed here. - A Transformer module in a sentence-transformers subfolder with its own `adapter_config.json`: only the repo root is checked. - The check adds one metadata request for `adapter_config.json` on a plain Hub model load (measured 40-49 ms per load online, none offline).
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.
#18923 added
_refuse_network_share_adapter_basetoFastLanguageModelandFastModel.FastDiffusionModel.from_pretrainedreadsadapter_config.jsonitself and swapsmodel_nameforbase_model_name_or_pathwithout that check, so on Windows a text-diffusion adapter repo naming\\host\share\modelstill sends the load to that host.FastModelreaches this loader before its own guard:_dispatch_diffusion()returns as soon as the repo's config is a text-diffusion type, including the early return for an AutoConfig error that mentionsdiffusion_gemma. So the repo author picks the route with itsconfig.json.The diffusion loader now calls the same guard right after its adapter probe, outside the probe's
except Exception: pass. The import is local becauseloader.pyimports this module. Local adapter folders and Hub bases are unchanged.Reproduced on main with only the Hub fetches mocked and Windows simulated as in
tests/test_adapter_unc_base_guard.py:FastModel(repo config of an unregistereddiffusion_gemma*type) andFastDiffusionModeldirectly both open the UNC base; with this change both raise the #18923ValueError. Not run on a real Windows machine.Test (fails on main):
tests/test_adapter_unc_base_guard.py::test_text_diffusion_loader_refuses_a_hub_adapter_with_unc_base.The ModelScope route past the same guard is #18960.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Pa8JdyYMHkqNpdksTfdmRG