Skip to content

Conversation

@nandan2003
Copy link

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
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
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
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
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
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 on lines +357 to +360
from peft.utils.hotswap import (
check_hotswap_configs_compatible,
hotswap_adapter_from_state_dict,
)
Copy link
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.

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

3 participants