@@ -317,6 +317,7 @@ def get_processor_dict(
317
317
user_agent = user_agent ,
318
318
revision = revision ,
319
319
subfolder = subfolder ,
320
+ _raise_exceptions_for_missing_entries = False ,
320
321
)
321
322
except EnvironmentError :
322
323
# 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(
331
332
f" directory containing a { PROCESSOR_NAME } file"
332
333
)
333
334
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
+
334
342
try :
335
343
# Load processor dict
336
344
with open (resolved_processor_file , "r" , encoding = "utf-8" ) as reader :
@@ -456,17 +464,7 @@ def from_pretrained(
456
464
kwargs ["token" ] = token
457
465
458
466
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 )
470
468
471
469
return cls .from_args_and_dict (args , processor_dict , ** kwargs )
472
470
0 commit comments