Skip to content

Commit

Permalink
Don't fail when LocalEntryNotFoundError during `processor_config.js…
Browse files Browse the repository at this point in the history
…on` loading (#28709)

* fix

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
  • Loading branch information
2 people authored and amyeroberts committed Jan 26, 2024
1 parent e393419 commit 8d8fdb5
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/transformers/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def get_processor_dict(
user_agent=user_agent,
revision=revision,
subfolder=subfolder,
_raise_exceptions_for_missing_entries=False,
)
except EnvironmentError:
# Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to
Expand All @@ -331,6 +332,13 @@ def get_processor_dict(
f" directory containing a {PROCESSOR_NAME} file"
)

# Existing processors on the Hub created before #27761 being merged don't have `processor_config.json` (if not
# updated afterward), and we need to keep `from_pretrained` work. So here it fallbacks to the empty dict.
# (`cached_file` called using `_raise_exceptions_for_missing_entries=False` to avoid exception)
# However, for models added in the future, we won't get the expected error if this file is missing.
if resolved_processor_file is None:
return {}, kwargs

try:
# Load processor dict
with open(resolved_processor_file, "r", encoding="utf-8") as reader:
Expand Down Expand Up @@ -456,17 +464,7 @@ def from_pretrained(
kwargs["token"] = token

args = cls._get_arguments_from_pretrained(pretrained_model_name_or_path, **kwargs)

# Existing processors on the Hub created before #27761 being merged don't have `processor_config.json` (if not
# updated afterward), and we need to keep `from_pretrained` work. So here it fallbacks to the empty dict.
# However, for models added in the future, we won't get the expected error if this file is missing.
try:
processor_dict, kwargs = cls.get_processor_dict(pretrained_model_name_or_path, **kwargs)
except EnvironmentError as e:
if "does not appear to have a file named processor_config.json." in str(e):
processor_dict, kwargs = {}, kwargs
else:
raise
processor_dict, kwargs = cls.get_processor_dict(pretrained_model_name_or_path, **kwargs)

return cls.from_args_and_dict(args, processor_dict, **kwargs)

Expand Down

0 comments on commit 8d8fdb5

Please sign in to comment.