From 8340e8746e7d27cce05253ec0f2845aeb0313884 Mon Sep 17 00:00:00 2001 From: Yuanyuan Chen Date: Tue, 10 Jun 2025 20:13:49 +0800 Subject: [PATCH] Use OSError (#38712) Signed-off-by: cyy --- .../generation/configuration_utils.py | 8 +++---- .../integrations/integration_utils.py | 2 +- .../integrations/tensor_parallel.py | 4 ++-- .../modeling_flax_pytorch_utils.py | 2 +- src/transformers/modeling_flax_utils.py | 18 +++++++-------- src/transformers/modeling_tf_utils.py | 14 ++++++------ src/transformers/modeling_utils.py | 22 +++++++++---------- src/transformers/models/auto/auto_factory.py | 2 +- .../models/auto/configuration_auto.py | 2 +- .../models/auto/feature_extraction_auto.py | 2 +- .../models/auto/image_processing_auto.py | 2 +- .../models/auto/processing_auto.py | 2 +- .../models/auto/tokenization_auto.py | 2 +- .../models/auto/video_processing_auto.py | 2 +- .../transfo_xl/tokenization_transfo_xl.py | 2 +- src/transformers/models/rag/retrieval_rag.py | 4 ++-- .../models/wav2vec2/modeling_wav2vec2.py | 8 +++---- src/transformers/onnx/features.py | 2 +- src/transformers/utils/hub.py | 2 +- src/transformers/video_processing_utils.py | 8 +++---- 20 files changed, 54 insertions(+), 56 deletions(-) diff --git a/src/transformers/generation/configuration_utils.py b/src/transformers/generation/configuration_utils.py index 99239b760d..c886b51cf5 100644 --- a/src/transformers/generation/configuration_utils.py +++ b/src/transformers/generation/configuration_utils.py @@ -1049,13 +1049,13 @@ class GenerationConfig(PushToHubMixin): _commit_hash=commit_hash, ) commit_hash = extract_commit_hash(resolved_config_file, commit_hash) - except EnvironmentError: + except OSError: # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to # the original exception. raise except Exception: # For any other exception, we throw a generic error. - raise EnvironmentError( + raise OSError( f"Can't load the configuration of '{pretrained_model_name}'. If you were trying to load it" " from 'https://huggingface.co/models', make sure you don't have a local directory with the same" f" name. Otherwise, make sure '{pretrained_model_name}' is the correct path to a directory" @@ -1067,9 +1067,7 @@ class GenerationConfig(PushToHubMixin): config_dict = cls._dict_from_json_file(resolved_config_file) config_dict["_commit_hash"] = commit_hash except (json.JSONDecodeError, UnicodeDecodeError): - raise EnvironmentError( - f"It looks like the config file at '{resolved_config_file}' is not a valid JSON file." - ) + raise OSError(f"It looks like the config file at '{resolved_config_file}' is not a valid JSON file.") if is_local: logger.info(f"loading configuration file {resolved_config_file}") diff --git a/src/transformers/integrations/integration_utils.py b/src/transformers/integrations/integration_utils.py index 3efefe712d..1c743dcf90 100755 --- a/src/transformers/integrations/integration_utils.py +++ b/src/transformers/integrations/integration_utils.py @@ -1623,7 +1623,7 @@ class NeptuneCallback(TrainerCallback): copy_path = os.path.join(consistent_checkpoint_path, cpkt_path) shutil.copytree(relative_path, copy_path) target_path = consistent_checkpoint_path - except IOError as e: + except OSError as e: logger.warning( "NeptuneCallback was unable to made a copy of checkpoint due to I/O exception: '{}'. " "Could fail trying to upload.".format(e) diff --git a/src/transformers/integrations/tensor_parallel.py b/src/transformers/integrations/tensor_parallel.py index 769845e7e8..b0946ee771 100644 --- a/src/transformers/integrations/tensor_parallel.py +++ b/src/transformers/integrations/tensor_parallel.py @@ -48,7 +48,7 @@ def initialize_tensor_parallelism(tp_plan, tp_size=None): return None, None, None if not is_torch_greater_or_equal("2.5"): - raise EnvironmentError("Tensor parallel is only supported for `torch>=2.5`.") + raise OSError("Tensor parallel is only supported for `torch>=2.5`.") # Detect the accelerator on the machine. If no accelerator is available, it returns CPU. device_type = torch._C._get_accelerator().type @@ -70,7 +70,7 @@ def initialize_tensor_parallelism(tp_plan, tp_size=None): current_device.set_device(local_rank) except Exception as e: - raise EnvironmentError( + raise OSError( "We tried to initialize torch.distributed for you, but it failed. Make " "sure you init torch distributed in your script to use `tp_plan='auto'`." ) from e diff --git a/src/transformers/modeling_flax_pytorch_utils.py b/src/transformers/modeling_flax_pytorch_utils.py index 6ebcad15f7..b35e492460 100644 --- a/src/transformers/modeling_flax_pytorch_utils.py +++ b/src/transformers/modeling_flax_pytorch_utils.py @@ -347,7 +347,7 @@ def load_flax_checkpoint_in_pytorch_model(model, flax_checkpoint_path): try: flax_state_dict = from_bytes(flax_cls, state_f.read()) except UnpicklingError: - raise EnvironmentError(f"Unable to convert {flax_checkpoint_path} to Flax deserializable object. ") + raise OSError(f"Unable to convert {flax_checkpoint_path} to Flax deserializable object. ") return load_flax_weights_in_pytorch_model(model, flax_state_dict) diff --git a/src/transformers/modeling_flax_utils.py b/src/transformers/modeling_flax_utils.py index 7a200bdda9..7697294d6a 100644 --- a/src/transformers/modeling_flax_utils.py +++ b/src/transformers/modeling_flax_utils.py @@ -435,7 +435,7 @@ class FlaxPreTrainedModel(PushToHubMixin, FlaxGenerationMixin): else: raise ValueError from e except (UnicodeDecodeError, ValueError): - raise EnvironmentError(f"Unable to convert {resolved_archive_file} to Flax deserializable object. ") + raise OSError(f"Unable to convert {resolved_archive_file} to Flax deserializable object. ") return state @@ -476,7 +476,7 @@ class FlaxPreTrainedModel(PushToHubMixin, FlaxGenerationMixin): else: raise ValueError from e except (UnicodeDecodeError, ValueError): - raise EnvironmentError(f"Unable to convert {shard_file} to Flax deserializable object. ") + raise OSError(f"Unable to convert {shard_file} to Flax deserializable object. ") state = flatten_dict(state, sep="/") state_sharded_dict.update(state) @@ -738,13 +738,13 @@ class FlaxPreTrainedModel(PushToHubMixin, FlaxGenerationMixin): is_sharded = True raise NotImplementedError("Support for sharded checkpoints using safetensors is coming soon!") elif os.path.isfile(os.path.join(pretrained_model_name_or_path, subfolder, WEIGHTS_NAME)): - raise EnvironmentError( + raise OSError( f"Error no file named {FLAX_WEIGHTS_NAME} found in directory {pretrained_model_name_or_path} " "but there is a file for PyTorch weights. Use `from_pt=True` to load this model from those " "weights." ) else: - raise EnvironmentError( + raise OSError( f"Error no file named {FLAX_WEIGHTS_NAME} or {WEIGHTS_NAME} found in directory " f"{pretrained_model_name_or_path}." ) @@ -820,29 +820,29 @@ class FlaxPreTrainedModel(PushToHubMixin, FlaxGenerationMixin): "Support for sharded checkpoints using safetensors is coming soon!" ) elif has_file(pretrained_model_name_or_path, WEIGHTS_NAME, **has_file_kwargs): - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named" f" {FLAX_WEIGHTS_NAME} but there is a file for PyTorch weights. Use `from_pt=True` to" " load this model from those weights." ) elif has_file(pretrained_model_name_or_path, WEIGHTS_INDEX_NAME, **has_file_kwargs): - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named" f" {FLAX_WEIGHTS_INDEX_NAME} but there is a sharded file for PyTorch weights. Use" " `from_pt=True` to load this model from those weights." ) else: - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named" f" {FLAX_WEIGHTS_NAME} or {WEIGHTS_NAME}." ) - except EnvironmentError: + except OSError: # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted # to the original exception. raise except Exception: # For any other exception, we throw a generic error. - raise EnvironmentError( + raise OSError( f"Can't load the model for '{pretrained_model_name_or_path}'. If you were trying to load it" " from 'https://huggingface.co/models', make sure you don't have a local directory with the" f" same name. Otherwise, make sure '{pretrained_model_name_or_path}' is the correct path to a" diff --git a/src/transformers/modeling_tf_utils.py b/src/transformers/modeling_tf_utils.py index ed7b018d89..af436be20f 100644 --- a/src/transformers/modeling_tf_utils.py +++ b/src/transformers/modeling_tf_utils.py @@ -2760,7 +2760,7 @@ class TFPreTrainedModel(keras.Model, TFModelUtilsMixin, TFGenerationMixin, PushT # At this stage we don't have a weight file so we will raise an error. elif use_safetensors: - raise EnvironmentError( + raise OSError( f"Error no file named {SAFE_WEIGHTS_NAME} or {SAFE_WEIGHTS_INDEX_NAME} found in directory {pretrained_model_name_or_path}. " f"Please make sure that the model has been saved with `safe_serialization=True` or do not " f"set `use_safetensors=True`." @@ -2768,13 +2768,13 @@ class TFPreTrainedModel(keras.Model, TFModelUtilsMixin, TFGenerationMixin, PushT elif os.path.isfile(os.path.join(pretrained_model_name_or_path, WEIGHTS_NAME)) or os.path.isfile( os.path.join(pretrained_model_name_or_path, WEIGHTS_INDEX_NAME) ): - raise EnvironmentError( + raise OSError( f"Error no file named {TF2_WEIGHTS_NAME} or {SAFE_WEIGHTS_NAME} found in directory {pretrained_model_name_or_path} " "but there is a file for PyTorch weights. Use `from_pt=True` to load this model from those " "weights." ) else: - raise EnvironmentError( + raise OSError( f"Error no file named {TF2_WEIGHTS_NAME}, {SAFE_WEIGHTS_NAME} or {WEIGHTS_NAME} found in directory " f"{pretrained_model_name_or_path}." ) @@ -2850,25 +2850,25 @@ class TFPreTrainedModel(keras.Model, TFModelUtilsMixin, TFGenerationMixin, PushT if has_file(pretrained_model_name_or_path, SAFE_WEIGHTS_INDEX_NAME, **has_file_kwargs): is_sharded = True elif has_file(pretrained_model_name_or_path, WEIGHTS_NAME, **has_file_kwargs): - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named" f" {TF2_WEIGHTS_NAME} but there is a file for PyTorch weights. Use `from_pt=True` to" " load this model from those weights." ) else: - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named {WEIGHTS_NAME}," f" {TF2_WEIGHTS_NAME} or {TF_WEIGHTS_NAME}" ) - except EnvironmentError: + except OSError: # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted # to the original exception. raise except Exception: # For any other exception, we throw a generic error. - raise EnvironmentError( + raise OSError( f"Can't load the model for '{pretrained_model_name_or_path}'. If you were trying to load it" " from 'https://huggingface.co/models', make sure you don't have a local directory with the" f" same name. Otherwise, make sure '{pretrained_model_name_or_path}' is the correct path to a" diff --git a/src/transformers/modeling_utils.py b/src/transformers/modeling_utils.py index 6e2d7a8102..64d5737545 100644 --- a/src/transformers/modeling_utils.py +++ b/src/transformers/modeling_utils.py @@ -1069,7 +1069,7 @@ def _get_resolved_checkpoint_files( os.path.isfile(os.path.join(pretrained_model_name_or_path, subfolder, TF_WEIGHTS_NAME + ".index")) or os.path.isfile(os.path.join(pretrained_model_name_or_path, subfolder, TF2_WEIGHTS_NAME)) ): - raise EnvironmentError( + raise OSError( f"Error no file named {_add_variant(WEIGHTS_NAME, variant)} found in directory" f" {pretrained_model_name_or_path} but there is a file for TensorFlow weights. Use" " `from_tf=True` to load this model from those weights." @@ -1077,18 +1077,18 @@ def _get_resolved_checkpoint_files( elif not use_safetensors and os.path.isfile( os.path.join(pretrained_model_name_or_path, subfolder, FLAX_WEIGHTS_NAME) ): - raise EnvironmentError( + raise OSError( f"Error no file named {_add_variant(WEIGHTS_NAME, variant)} found in directory" f" {pretrained_model_name_or_path} but there is a file for Flax weights. Use `from_flax=True`" " to load this model from those weights." ) elif use_safetensors: - raise EnvironmentError( + raise OSError( f"Error no file named {_add_variant(SAFE_WEIGHTS_NAME, variant)} found in directory" f" {pretrained_model_name_or_path}." ) else: - raise EnvironmentError( + raise OSError( f"Error no file named {_add_variant(WEIGHTS_NAME, variant)}, {_add_variant(SAFE_WEIGHTS_NAME, variant)}," f" {TF2_WEIGHTS_NAME}, {TF_WEIGHTS_NAME + '.index'} or {FLAX_WEIGHTS_NAME} found in directory" f" {pretrained_model_name_or_path}." @@ -1156,7 +1156,7 @@ def _get_resolved_checkpoint_files( ) cached_file_kwargs["revision"] = revision if resolved_archive_file is None: - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named" f" {_add_variant(SAFE_WEIGHTS_NAME, variant)} or {_add_variant(SAFE_WEIGHTS_INDEX_NAME, variant)} " "and thus cannot be loaded with `safetensors`. Please make sure that the model has " @@ -1222,13 +1222,13 @@ def _get_resolved_checkpoint_files( "local_files_only": local_files_only, } if has_file(pretrained_model_name_or_path, TF2_WEIGHTS_NAME, **has_file_kwargs): - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named" f" {_add_variant(WEIGHTS_NAME, variant)} but there is a file for TensorFlow weights." " Use `from_tf=True` to load this model from those weights." ) elif has_file(pretrained_model_name_or_path, FLAX_WEIGHTS_NAME, **has_file_kwargs): - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named" f" {_add_variant(WEIGHTS_NAME, variant)} but there is a file for Flax weights. Use" " `from_flax=True` to load this model from those weights." @@ -1236,25 +1236,25 @@ def _get_resolved_checkpoint_files( elif variant is not None and has_file( pretrained_model_name_or_path, WEIGHTS_NAME, **has_file_kwargs ): - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named" f" {_add_variant(WEIGHTS_NAME, variant)} but there is a file without the variant" f" {variant}. Use `variant=None` to load this model from those weights." ) else: - raise EnvironmentError( + raise OSError( f"{pretrained_model_name_or_path} does not appear to have a file named" f" {_add_variant(WEIGHTS_NAME, variant)}, {_add_variant(SAFE_WEIGHTS_NAME, variant)}," f" {TF2_WEIGHTS_NAME}, {TF_WEIGHTS_NAME} or {FLAX_WEIGHTS_NAME}." ) - except EnvironmentError: + except OSError: # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted # to the original exception. raise except Exception as e: # For any other exception, we throw a generic error. - raise EnvironmentError( + raise OSError( f"Can't load the model for '{pretrained_model_name_or_path}'. If you were trying to load it" " from 'https://huggingface.co/models', make sure you don't have a local directory with the" f" same name. Otherwise, make sure '{pretrained_model_name_or_path}' is the correct path to a" diff --git a/src/transformers/models/auto/auto_factory.py b/src/transformers/models/auto/auto_factory.py index 084f147283..00c2986096 100644 --- a/src/transformers/models/auto/auto_factory.py +++ b/src/transformers/models/auto/auto_factory.py @@ -415,7 +415,7 @@ class _BaseAutoModelClass: _model_mapping = None def __init__(self, *args, **kwargs) -> None: - raise EnvironmentError( + raise OSError( f"{self.__class__.__name__} is designed to be instantiated " f"using the `{self.__class__.__name__}.from_pretrained(pretrained_model_name_or_path)` or " f"`{self.__class__.__name__}.from_config(config)` methods." diff --git a/src/transformers/models/auto/configuration_auto.py b/src/transformers/models/auto/configuration_auto.py index b6ee509170..da55432dfd 100644 --- a/src/transformers/models/auto/configuration_auto.py +++ b/src/transformers/models/auto/configuration_auto.py @@ -1047,7 +1047,7 @@ class AutoConfig: """ def __init__(self) -> None: - raise EnvironmentError( + raise OSError( "AutoConfig is designed to be instantiated " "using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method." ) diff --git a/src/transformers/models/auto/feature_extraction_auto.py b/src/transformers/models/auto/feature_extraction_auto.py index a0f171af24..dc94a15c7e 100644 --- a/src/transformers/models/auto/feature_extraction_auto.py +++ b/src/transformers/models/auto/feature_extraction_auto.py @@ -255,7 +255,7 @@ class AutoFeatureExtractor: """ def __init__(self): - raise EnvironmentError( + raise OSError( "AutoFeatureExtractor is designed to be instantiated " "using the `AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)` method." ) diff --git a/src/transformers/models/auto/image_processing_auto.py b/src/transformers/models/auto/image_processing_auto.py index f992369f27..2faabea5fe 100644 --- a/src/transformers/models/auto/image_processing_auto.py +++ b/src/transformers/models/auto/image_processing_auto.py @@ -338,7 +338,7 @@ class AutoImageProcessor: """ def __init__(self): - raise EnvironmentError( + raise OSError( "AutoImageProcessor is designed to be instantiated " "using the `AutoImageProcessor.from_pretrained(pretrained_model_name_or_path)` method." ) diff --git a/src/transformers/models/auto/processing_auto.py b/src/transformers/models/auto/processing_auto.py index d67b2c3982..7eb850cfe4 100644 --- a/src/transformers/models/auto/processing_auto.py +++ b/src/transformers/models/auto/processing_auto.py @@ -176,7 +176,7 @@ class AutoProcessor: """ def __init__(self): - raise EnvironmentError( + raise OSError( "AutoProcessor is designed to be instantiated " "using the `AutoProcessor.from_pretrained(pretrained_model_name_or_path)` method." ) diff --git a/src/transformers/models/auto/tokenization_auto.py b/src/transformers/models/auto/tokenization_auto.py index cba0e2e1cd..315c2e5168 100644 --- a/src/transformers/models/auto/tokenization_auto.py +++ b/src/transformers/models/auto/tokenization_auto.py @@ -819,7 +819,7 @@ class AutoTokenizer: """ def __init__(self): - raise EnvironmentError( + raise OSError( "AutoTokenizer is designed to be instantiated " "using the `AutoTokenizer.from_pretrained(pretrained_model_name_or_path)` method." ) diff --git a/src/transformers/models/auto/video_processing_auto.py b/src/transformers/models/auto/video_processing_auto.py index 507930df72..1688b7fbeb 100644 --- a/src/transformers/models/auto/video_processing_auto.py +++ b/src/transformers/models/auto/video_processing_auto.py @@ -205,7 +205,7 @@ class AutoVideoProcessor: """ def __init__(self): - raise EnvironmentError( + raise OSError( "AutoVideoProcessor is designed to be instantiated " "using the `AutoVideoProcessor.from_pretrained(pretrained_model_name_or_path)` method." ) diff --git a/src/transformers/models/deprecated/transfo_xl/tokenization_transfo_xl.py b/src/transformers/models/deprecated/transfo_xl/tokenization_transfo_xl.py index d9a118f54d..44a3c85add 100644 --- a/src/transformers/models/deprecated/transfo_xl/tokenization_transfo_xl.py +++ b/src/transformers/models/deprecated/transfo_xl/tokenization_transfo_xl.py @@ -693,7 +693,7 @@ class TransfoXLCorpus: # redirect to the cache, if necessary try: resolved_corpus_file = cached_file(pretrained_model_name_or_path, CORPUS_NAME, cache_dir=cache_dir) - except EnvironmentError: + except OSError: logger.error( f"Corpus '{pretrained_model_name_or_path}' was not found in corpus list" f" ({', '.join(PRETRAINED_CORPUS_ARCHIVE_MAP.keys())}. We assumed '{pretrained_model_name_or_path}'" diff --git a/src/transformers/models/rag/retrieval_rag.py b/src/transformers/models/rag/retrieval_rag.py index d1fde00995..355b131be5 100644 --- a/src/transformers/models/rag/retrieval_rag.py +++ b/src/transformers/models/rag/retrieval_rag.py @@ -117,13 +117,13 @@ class LegacyIndex(Index): try: # Load from URL or cache if already cached resolved_archive_file = cached_file(index_path, filename) - except EnvironmentError: + except OSError: msg = ( f"Can't load '{filename}'. Make sure that:\n\n" f"- '{index_path}' is a correct remote path to a directory containing a file named {filename}\n\n" f"- or '{index_path}' is the correct path to a directory containing a file named {filename}.\n\n" ) - raise EnvironmentError(msg) + raise OSError(msg) if is_local: logger.info(f"loading file {resolved_archive_file}") else: diff --git a/src/transformers/models/wav2vec2/modeling_wav2vec2.py b/src/transformers/models/wav2vec2/modeling_wav2vec2.py index ae3510f175..6a66a21eec 100755 --- a/src/transformers/models/wav2vec2/modeling_wav2vec2.py +++ b/src/transformers/models/wav2vec2/modeling_wav2vec2.py @@ -1322,7 +1322,7 @@ class Wav2Vec2PreTrainedModel(PreTrainedModel): state_dict = safe_load_file(weight_path) - except EnvironmentError: + except OSError: if use_safetensors: # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted # to the original exception. @@ -1331,7 +1331,7 @@ class Wav2Vec2PreTrainedModel(PreTrainedModel): except Exception: # For any other exception, we throw a generic error. if use_safetensors: - raise EnvironmentError( + raise OSError( f"Can't load the model for '{model_path_or_id}'. If you were trying to load it" " from 'https://huggingface.co/models', make sure you don't have a local directory with the" f" same name. Otherwise, make sure '{model_path_or_id}' is the correct path to a" @@ -1362,7 +1362,7 @@ class Wav2Vec2PreTrainedModel(PreTrainedModel): weights_only=True, ) - except EnvironmentError: + except OSError: # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted # to the original exception. raise @@ -1372,7 +1372,7 @@ class Wav2Vec2PreTrainedModel(PreTrainedModel): except Exception: # For any other exception, we throw a generic error. - raise EnvironmentError( + raise OSError( f"Can't load the model for '{model_path_or_id}'. If you were trying to load it" " from 'https://huggingface.co/models', make sure you don't have a local directory with the" f" same name. Otherwise, make sure '{model_path_or_id}' is the correct path to a" diff --git a/src/transformers/onnx/features.py b/src/transformers/onnx/features.py index da9ca2355f..5bd61d3cb5 100644 --- a/src/transformers/onnx/features.py +++ b/src/transformers/onnx/features.py @@ -669,7 +669,7 @@ class FeaturesManager: elif is_tf_available(): framework = "tf" else: - raise EnvironmentError("Neither PyTorch nor TensorFlow found in environment. Cannot export to ONNX.") + raise OSError("Neither PyTorch nor TensorFlow found in environment. Cannot export to ONNX.") logger.info(f"Framework not requested. Using {exporter_map[framework]} to export to ONNX.") diff --git a/src/transformers/utils/hub.py b/src/transformers/utils/hub.py index f110459129..3a9852452b 100644 --- a/src/transformers/utils/hub.py +++ b/src/transformers/utils/hub.py @@ -570,7 +570,7 @@ def cached_files( msg = ( f"a file named {missing_entries[0]}" if len(missing_entries) == 1 else f"files named {(*missing_entries,)}" ) - raise EnvironmentError( + raise OSError( f"{path_or_repo_id} does not appear to have {msg}. Checkout 'https://huggingface.co/{path_or_repo_id}/tree/{revision_}'" " for available files." ) diff --git a/src/transformers/video_processing_utils.py b/src/transformers/video_processing_utils.py index 527760eb8d..8a599d4737 100644 --- a/src/transformers/video_processing_utils.py +++ b/src/transformers/video_processing_utils.py @@ -579,7 +579,7 @@ class BaseVideoProcessor(BaseImageProcessorFast): revision=revision, subfolder=subfolder, ) - except EnvironmentError: + except OSError: video_processor_file = "preprocessor_config.json" resolved_video_processor_file = cached_file( pretrained_model_name_or_path, @@ -600,13 +600,13 @@ class BaseVideoProcessor(BaseImageProcessorFast): "the file or load and save the processor back which renames it automatically. " "Loading from `preprocessor.json` will be removed in v5.0." ) - except EnvironmentError: + except OSError: # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to # the original exception. raise except Exception: # For any other exception, we throw a generic error. - raise EnvironmentError( + raise OSError( f"Can't load video processor for '{pretrained_model_name_or_path}'. If you were trying to load" " it from 'https://huggingface.co/models', make sure you don't have a local directory with the" f" same name. Otherwise, make sure '{pretrained_model_name_or_path}' is the correct path to a" @@ -620,7 +620,7 @@ class BaseVideoProcessor(BaseImageProcessorFast): video_processor_dict = json.loads(text) except json.JSONDecodeError: - raise EnvironmentError( + raise OSError( f"It looks like the config file at '{resolved_video_processor_file}' is not a valid JSON file." )