Repository navigation
Refuse Hub network-share paths in parallel auto sizing and sentence-transformers routes - #19101
Conversation
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9093cf0e73
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
[skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
…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).
Two more places where a Hub repo's metadata reached a Windows filesystem probe as a UNC path before any check (same class as #18923, #19014, #19060):
UNSLOTH_PARALLEL=autosizing (parallel_auto.py): a Hub adapter'sbase_model_name_or_pathwent toget_model_nameand_checkpoint_tensors(os.path.isdir). It now runs the loader's existing_refuse_network_share_adapter_baseright after reading the base.modules.jsonfolders were already refused when they leave the model, but Router route keys fromrouter_config.jsonwere joined onto the folder and probed. That rule is now a shared helper (_folder_escapes_model), applied to Hub routes too: UNC, absolute, drive and..-escaping routes are refused. Local folders and normal routes are unchanged.Tests:
tests/test_parallel_auto.py,tests/test_sentence_transformer_route_unc.py.