Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed config.json download to go to user-supplied cache directory #30189

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/transformers/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ def pipeline(
pretrained_model_name_or_path = model

if not isinstance(config, PretrainedConfig) and pretrained_model_name_or_path is not None:
# cached_file needs the cache directory, so that config.json is found in the right place.
if "cache_dir" in model_kwargs:
hub_kwargs["cache_dir"] = model_kwargs["cache_dir"]

# We make a call to the config file first (which may be absent) to get the commit hash as soon as possible
resolved_config_file = cached_file(
pretrained_model_name_or_path,
Expand All @@ -785,6 +789,10 @@ def pipeline(
**hub_kwargs,
)
hub_kwargs["_commit_hash"] = extract_commit_hash(resolved_config_file, commit_hash)

# Remove the cache directory from hub_kwargs, so it doesn't conflict with model_kwargs.
if "cache_dir" in model_kwargs:
del hub_kwargs["cache_dir"]
else:
hub_kwargs["_commit_hash"] = getattr(config, "_commit_hash", None)

Expand Down