Skip to content

Commit 8d8fdb5

Browse files
ydshiehamyeroberts
authored andcommitted
Don't fail when LocalEntryNotFoundError during processor_config.json loading (#28709)
* fix --------- Co-authored-by: ydshieh <[email protected]>
1 parent e393419 commit 8d8fdb5

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/transformers/processing_utils.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def get_processor_dict(
317317
user_agent=user_agent,
318318
revision=revision,
319319
subfolder=subfolder,
320+
_raise_exceptions_for_missing_entries=False,
320321
)
321322
except EnvironmentError:
322323
# Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to
@@ -331,6 +332,13 @@ def get_processor_dict(
331332
f" directory containing a {PROCESSOR_NAME} file"
332333
)
333334

335+
# Existing processors on the Hub created before #27761 being merged don't have `processor_config.json` (if not
336+
# updated afterward), and we need to keep `from_pretrained` work. So here it fallbacks to the empty dict.
337+
# (`cached_file` called using `_raise_exceptions_for_missing_entries=False` to avoid exception)
338+
# However, for models added in the future, we won't get the expected error if this file is missing.
339+
if resolved_processor_file is None:
340+
return {}, kwargs
341+
334342
try:
335343
# Load processor dict
336344
with open(resolved_processor_file, "r", encoding="utf-8") as reader:
@@ -456,17 +464,7 @@ def from_pretrained(
456464
kwargs["token"] = token
457465

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

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

0 commit comments

Comments
 (0)