Skip to content

Refuse Hub network-share paths in parallel auto sizing and sentence-transformers routes - #19101

Merged
danielhanchen merged 4 commits into
mainfrom
s1123b/U2/unc-probes
Nov 23, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
s1123b/U2/unc-probes

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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=auto sizing (parallel_auto.py): a Hub adapter's base_model_name_or_path went to get_model_name and _checkpoint_tensors (os.path.isdir). It now runs the loader's existing _refuse_network_share_adapter_base right after reading the base.
  • sentence-transformers Router routes: modules.json folders were already refused when they leave the model, but Router route keys from router_config.json were 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T16:16:56.381861Z 7de2c7e 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread tests/test_parallel_auto.py Resolved
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 4289bc9d90

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

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 7de2c7eed5

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 23, 2026
@danielhanchen
danielhanchen merged commit 70375a1 into main Nov 23, 2026
@danielhanchen
danielhanchen deleted the s1123b/U2/unc-probes branch November 23, 2026 19:27
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).
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