Unverified Commit 142ce683 authored by Yih-Dar's avatar Yih-Dar Committed by GitHub
Browse files

Don't fail when `LocalEntryNotFoundError` during `processor_config.json` loading (#28709)



* fix

---------
Co-authored-by: default avatarydshieh <ydshieh@users.noreply.github.com>
parent 28751958
...@@ -317,6 +317,7 @@ class ProcessorMixin(PushToHubMixin): ...@@ -317,6 +317,7 @@ class ProcessorMixin(PushToHubMixin):
user_agent=user_agent, user_agent=user_agent,
revision=revision, revision=revision,
subfolder=subfolder, subfolder=subfolder,
_raise_exceptions_for_missing_entries=False,
) )
except EnvironmentError: except EnvironmentError:
# Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to
...@@ -331,6 +332,13 @@ class ProcessorMixin(PushToHubMixin): ...@@ -331,6 +332,13 @@ class ProcessorMixin(PushToHubMixin):
f" directory containing a {PROCESSOR_NAME} file" 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: try:
# Load processor dict # Load processor dict
with open(resolved_processor_file, "r", encoding="utf-8") as reader: with open(resolved_processor_file, "r", encoding="utf-8") as reader:
...@@ -456,17 +464,7 @@ class ProcessorMixin(PushToHubMixin): ...@@ -456,17 +464,7 @@ class ProcessorMixin(PushToHubMixin):
kwargs["token"] = token kwargs["token"] = token
args = cls._get_arguments_from_pretrained(pretrained_model_name_or_path, **kwargs) args = cls._get_arguments_from_pretrained(pretrained_model_name_or_path, **kwargs)
processor_dict, kwargs = cls.get_processor_dict(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
return cls.from_args_and_dict(args, processor_dict, **kwargs) return cls.from_args_and_dict(args, processor_dict, **kwargs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment