Repository: huggingface/transformers
Pull request: Fix: Pass local_files_only from pipeline() to model loading

Fixes #42269

Fixes a bug where passing `local_files_only=True` to `pipeline()` was ignored, causing models to download from the Hub even when offline mode was explicitly requested.

**The Fix:**
The `local_files_only` argument was being extracted from `kwargs` but was missing from the `hub_kwargs` dictionary that `pipeline()` uses to configure downloads. This PR adds the flag to `hub_kwargs`, ensuring it is correctly propagated to `AutoConfig.from_pretrained` and `load_model`.

## Reproduction & Verification
I verified this locally by clearing the cache for a specific model (`hf-internal-testing/tiny-random-bert`) and attempting to load it via `pipeline()` with `local_files_only=True`.

* **Before Fix:** The model would download despite the flag.
* **After Fix:** The call correctly raises an `OSError` (because the model is not locally available), confirming that no connection to the Hub was attempted.

## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request), Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Yes, issue #42269.
- [ ] Did you make sure to update the documentation with your changes? (Bug fix, no docs needed).
- [x] Did you write any new necessary tests? (Verified manually via reproduction script).

## Who can review?

@Rocketknight1 (Pipelines)

Changed files:
filename: src/transformers/integrations/peft.py
patch: @@ -84,6 +84,7 @@ def load_adapter(
         low_cpu_mem_usage: bool = False,
         is_trainable: bool = False,
         hotswap: bool | Literal["auto"] = "auto",
+        local_files_only: bool = False,
         adapter_kwargs: dict[str, Any] | None = None,
     ) -> None:
         """
@@ -243,6 +244,7 @@ def load_adapter(
             adapter_config_file = find_adapter_config_file(
                 peft_model_id,
                 token=token,
+                local_files_only=local_files_only,
                 **adapter_kwargs,
             )
 
@@ -255,6 +257,7 @@ def load_adapter(
             peft_config = PeftConfig.from_pretrained(
                 peft_model_id,
                 token=token,
+                local_files_only=local_files_only,
                 **adapter_kwargs,
             )
             peft_config.inference_mode = not is_trainable
@@ -268,6 +271,8 @@ def load_adapter(
             self._hf_peft_config_loaded = True
 
         if peft_model_id is not None:
+            if "local_files_only" not in adapter_kwargs:
+                adapter_kwargs["local_files_only"] = local_files_only
             adapter_state_dict = load_peft_weights(peft_model_id, token=token, device=device, **adapter_kwargs)
 
         # We need to pre-process the state dict to remove unneeded prefixes - for backward compatibility

filename: src/transformers/pipelines/__init__.py
patch: @@ -700,12 +700,14 @@ def pipeline(
 
     code_revision = kwargs.pop("code_revision", None)
     commit_hash = kwargs.pop("_commit_hash", None)
+    local_files_only = kwargs.get("local_files_only", False)
 
     hub_kwargs = {
         "revision": revision,
         "token": token,
         "trust_remote_code": trust_remote_code,
         "_commit_hash": commit_hash,
+        "local_files_only": local_files_only,
     }
 
     if task is None and model is None: