Repository navigation
Refuse a network-share adapter base that transformers resolves by itself - #19170
Merged
danielhanchen merged 5 commits intoNov 24, 2026
Merged
danielhanchen merged 5 commits into
danielhanchen merged 5 commits into
Conversation
transformers reads a Hub repo's adapter_config.json as raw JSON and loads the base it names. The guard only ran when PEFT parsed the file in the two main loaders, so a file PEFT rejects, and both FastSentenceTransformer routes that hand the repo id to sentence-transformers, still reached the named base. Check the raw file on those routes. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01Pa8JdyYMHkqNpdksTfdmRG
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. |
…ceTransformer cache [skip ci]
|
Codex Review: Didn't find any major issues. Keep them coming! 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 24, 2026
…9310) ## Problem `tests/test_prefetch_snapshot_scope.py::test_st_cache_resolutions_honor_explicit_hf_cache_dir` fails on main since #19170, and with it the Core legs of every PR based on main (seen first on the staging run for #19181): ``` AssertionError: an ST cache_dir resolution must read an explicit kwargs.get('cache_dir') first ``` ## Cause #19170 added `_refuse_network_share_raw_adapter_base(...)` before both `SentenceTransformer(...)` loads. On the `for_inference = True` route it passes ```python cache_dir = st_kwargs.get("cache_folder") or os.environ.get("SENTENCE_TRANSFORMERS_HOME"), ``` The code is right. A few lines earlier the same function maps an explicit HF `cache_dir` onto `st_kwargs["cache_folder"]`: ```python _st_cache = kwargs.get("cache_dir") or kwargs.get("cache_folder") if _st_cache is not None: st_kwargs["cache_folder"] = _st_cache ``` so `st_kwargs.get("cache_folder")` already reads `cache_dir` first, and it is the same value the neighbouring `_check_modules_json_types(..., cache_dir = st_kwargs.get("cache_folder"))` call and the `SentenceTransformer(**st_kwargs)` load use. The guard only looked for the literal `'cache_dir'` inside the expression, so it could not see the mapping. #19170's own CI ran on an older base and the failure showed up only after it merged. ## Fix Test only, no product code changes. The guard now accepts a resolution that either: - reads `kwargs.get("cache_dir")` as its first operand, or - reads `<dict>.get("cache_folder")` first, where the same function, earlier, assigns `<dict>["cache_folder"]` only from expressions whose first operand reads `cache_dir` (directly or through one local name). This is stricter than before in one way: `cache_dir` has to come first, not just appear somewhere in the expression. ## Verification - `tests/test_prefetch_snapshot_scope.py`: 43 passed (1 failed on main). - Sabotage, one at a time on `sentence_transformer.py`, each makes the guard fail: - swapping the mapping to `kwargs.get("cache_folder") or kwargs.get("cache_dir")`; - dropping `st_kwargs["cache_folder"] = _st_cache`; - changing the delegated route's resolution to `kwargs.get("cache_folder") or os.environ.get("SENTENCE_TRANSFORMERS_HOME")`. - With `tests/test_adapter_unc_base_guard.py` (the tests #19170 added): all pass.
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.
Follow-up to #18923, #18960, #18961, #19101.
Problem
AutoModel*.from_pretrained("org/repo")looks foradapter_config.jsonitself, readsbase_model_name_or_pathfrom 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:adapter_config.jsonPEFT cannot parse. With a validconfig.jsonand e.g."peft_type": "NOT_A_PEFT_TYPE",PeftConfig.from_pretrainedraises, the loader setsis_peft = False, skips the guard and loads the repo as a plain model. transformers then swaps in the named base. Applies toFastLanguageModelandFastModel.FastSentenceTransformer, on thefor_inference = Trueroute and the fast encoder route. Both hand the repo id toSentenceTransformer(...), whose Transformer module loads through transformers. A plain valid LoRAadapter_config.jsonis enough here. The default route throughFastModelwas already covered.Fix
_refuse_network_share_raw_adapter_baseinloader.pyfinds 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 bothSentenceTransformer(model_name, ...)loads. Local folders are left alone, as before.Tests
End to end, with real
transformers/peft/sentence-transformersagainst an offline Hub cache, Windows simulated as intests/test_adapter_unc_base_guard.py, spying onos.path.isdir/isfile/existsandopen:adapter_config.jsonexists,isdir,isfileValueError, nothing probedfor_inferenceValueError, nothing probedValueError, nothing probedSame 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.pywith a stand-in forFastLlamaModel.from_pretrainedthat callsAutoModelForCausalLM.from_pretrained; the sentence-transformers run executes the realsentence_transformer.pywith 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) andtest_routes_that_hand_a_hub_id_to_transformers_check_the_raw_config(the four call sites sit before the load). Both fail on main. Theloaderfixture stubs the new helper so those tests do not ask the Hub.Not covered
adapter_config.json, the fp8 offline-quantize path andFastDiffusionModelafter a failed PEFT parse: same shape by reading, not run, not changed here.adapter_config.json: only the repo root is checked.adapter_config.jsonon a plain Hub model load; not measured.🤖 Generated with Claude Code
https://claude.ai/code/session_01Pa8JdyYMHkqNpdksTfdmRG