Skip to content

Fix: Pass local_files_only from pipeline() to model loading#42318

Merged
Rocketknight1 merged 12 commits intohuggingface:mainfrom
nandan2003:fix-pipeline-local-files
Dec 17, 2025
Merged

Fix: Pass local_files_only from pipeline() to model loading#42318
Rocketknight1 merged 12 commits intohuggingface:mainfrom
nandan2003:fix-pipeline-local-files

Conversation

@nandan2003
Copy link
Copy Markdown
Contributor

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

Who can review?

@Rocketknight1 (Pipelines)

@nandan2003
Copy link
Copy Markdown
Contributor Author

Branch updated to sync with main.

I verified this locally by clearing the Hugging Face cache and running a test script:

  1. Before: pipeline(..., local_files_only=True) triggered a download.
  2. After: It correctly raises OSError (indicating offline mode is respected).

The CI failure in tests_processors appears unrelated to these changes in pipelines/__init__.py.

Copy link
Copy Markdown
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for fixing this!

(might be good to add a test in ./tests/test_pipeline_mixin.py? -let's wait for a review from a transformers's maintainer :) -)

@Rocketknight1
Copy link
Copy Markdown
Member

This PR makes sense to me! One question - can you check in the PEFT path, to see if we need to pass this there too? I'm not sure if the adapter-loading path will respect local_files_only either.

@nandan2003 nandan2003 force-pushed the fix-pipeline-local-files branch from e833ed5 to 385c690 Compare November 24, 2025 17:44
@nandan2003
Copy link
Copy Markdown
Contributor Author

This PR makes sense to me! One question - can you check in the PEFT path, to see if we need to pass this there too? I'm not sure if the adapter-loading path will respect local_files_only either.

You're actually right. made some changes and PTAL.

@Rocketknight1
Copy link
Copy Markdown
Member

There's a lot of unrelated style changes here! Can you pip install -e .[quality] to make sure you're using the right versions of the style tools, then make style or make fixup? That should reduce the size of the diff a lot.

@nandan2003 nandan2003 force-pushed the fix-pipeline-local-files branch from 4ee4804 to 7630509 Compare November 25, 2025 18:20
Comment thread src/transformers/integrations/peft.py Outdated
Comment on lines +357 to +360
from peft.utils.hotswap import (
check_hotswap_configs_compatible,
hotswap_adapter_from_state_dict,
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still a lot of unrelated style changes, sorry! Can you check against main and revert the unrelated changes that are just style like this? Most good IDEs have git compare/diff functions that should make it easy enough to do, but doing it manually shouldn't take too long either.

@nandan2003 nandan2003 force-pushed the fix-pipeline-local-files branch from 706a52f to ec259f7 Compare November 27, 2025 18:01
Comment on lines +717 to +724
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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey, I see the review ping but there's still lots of style issues! If you look at the diff, everything in __init__.py except this section is just style changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Every other styling change was done by ruff.

@Rocketknight1
Copy link
Copy Markdown
Member

@bot /style

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 1, 2025

Style bot fixed some files and pushed the changes.

@Rocketknight1
Copy link
Copy Markdown
Member

There are some CI issues, not the fault of this PR! Hold on for a day or two and we'll resolve them, then ping me to rerun tests

@nandan2003
Copy link
Copy Markdown
Contributor Author

There are some CI issues, not the fault of this PR! Hold on for a day or two and we'll resolve them, then ping me to rerun tests

Hey! Is the CI issues sorted?

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Copy Markdown
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Yep, and sorry about that! I'm happy with the changes at this point. Thank you for the PR!

@Rocketknight1 Rocketknight1 merged commit 0218f1a into huggingface:main Dec 17, 2025
25 checks passed
SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Jan 23, 2026
…ace#42318)

* Fix: Propagate local_files_only to hub_kwargs and PEFT adapter loading

* Fix conflicts and code style

* Apply formatting fixes

* Apply style fixes

* Fix style: Apply minimal changes for local_files_only

* Style: Revert formatting and finalize local_files_only fix in __init__.py

* Apply style fixes

* Trigger tests

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
Co-authored-by: Matt <rocketknight1@gmail.com>
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.

local_files_only=True in pipeline() does not prevent model downloads in transformers==4.57.1

4 participants