Use OSError (#38712)

Signed-off-by: cyy <cyyever@outlook.com>
This commit is contained in:
Yuanyuan Chen
2025-06-10 20:13:49 +08:00
committed by GitHub
parent 8257734b5f
commit 8340e8746e
20 changed files with 54 additions and 56 deletions

View File

@@ -1049,13 +1049,13 @@ class GenerationConfig(PushToHubMixin):
_commit_hash=commit_hash, _commit_hash=commit_hash,
) )
commit_hash = extract_commit_hash(resolved_config_file, 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 # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to
# the original exception. # the original exception.
raise raise
except Exception: except Exception:
# For any other exception, we throw a generic error. # 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" 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" " 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" 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 = cls._dict_from_json_file(resolved_config_file)
config_dict["_commit_hash"] = commit_hash config_dict["_commit_hash"] = commit_hash
except (json.JSONDecodeError, UnicodeDecodeError): except (json.JSONDecodeError, UnicodeDecodeError):
raise EnvironmentError( raise OSError(f"It looks like the config file at '{resolved_config_file}' is not a valid JSON file.")
f"It looks like the config file at '{resolved_config_file}' is not a valid JSON file."
)
if is_local: if is_local:
logger.info(f"loading configuration file {resolved_config_file}") logger.info(f"loading configuration file {resolved_config_file}")

View File

@@ -1623,7 +1623,7 @@ class NeptuneCallback(TrainerCallback):
copy_path = os.path.join(consistent_checkpoint_path, cpkt_path) copy_path = os.path.join(consistent_checkpoint_path, cpkt_path)
shutil.copytree(relative_path, copy_path) shutil.copytree(relative_path, copy_path)
target_path = consistent_checkpoint_path target_path = consistent_checkpoint_path
except IOError as e: except OSError as e:
logger.warning( logger.warning(
"NeptuneCallback was unable to made a copy of checkpoint due to I/O exception: '{}'. " "NeptuneCallback was unable to made a copy of checkpoint due to I/O exception: '{}'. "
"Could fail trying to upload.".format(e) "Could fail trying to upload.".format(e)

View File

@@ -48,7 +48,7 @@ def initialize_tensor_parallelism(tp_plan, tp_size=None):
return None, None, None return None, None, None
if not is_torch_greater_or_equal("2.5"): 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. # Detect the accelerator on the machine. If no accelerator is available, it returns CPU.
device_type = torch._C._get_accelerator().type 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) current_device.set_device(local_rank)
except Exception as e: except Exception as e:
raise EnvironmentError( raise OSError(
"We tried to initialize torch.distributed for you, but it failed. Make " "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'`." "sure you init torch distributed in your script to use `tp_plan='auto'`."
) from e ) from e

View File

@@ -347,7 +347,7 @@ def load_flax_checkpoint_in_pytorch_model(model, flax_checkpoint_path):
try: try:
flax_state_dict = from_bytes(flax_cls, state_f.read()) flax_state_dict = from_bytes(flax_cls, state_f.read())
except UnpicklingError: 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) return load_flax_weights_in_pytorch_model(model, flax_state_dict)

View File

@@ -435,7 +435,7 @@ class FlaxPreTrainedModel(PushToHubMixin, FlaxGenerationMixin):
else: else:
raise ValueError from e raise ValueError from e
except (UnicodeDecodeError, ValueError): 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 return state
@@ -476,7 +476,7 @@ class FlaxPreTrainedModel(PushToHubMixin, FlaxGenerationMixin):
else: else:
raise ValueError from e raise ValueError from e
except (UnicodeDecodeError, ValueError): 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 = flatten_dict(state, sep="/")
state_sharded_dict.update(state) state_sharded_dict.update(state)
@@ -738,13 +738,13 @@ class FlaxPreTrainedModel(PushToHubMixin, FlaxGenerationMixin):
is_sharded = True is_sharded = True
raise NotImplementedError("Support for sharded checkpoints using safetensors is coming soon!") 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)): 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} " 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 " "but there is a file for PyTorch weights. Use `from_pt=True` to load this model from those "
"weights." "weights."
) )
else: else:
raise EnvironmentError( raise OSError(
f"Error no file named {FLAX_WEIGHTS_NAME} or {WEIGHTS_NAME} found in directory " f"Error no file named {FLAX_WEIGHTS_NAME} or {WEIGHTS_NAME} found in directory "
f"{pretrained_model_name_or_path}." f"{pretrained_model_name_or_path}."
) )
@@ -820,29 +820,29 @@ class FlaxPreTrainedModel(PushToHubMixin, FlaxGenerationMixin):
"Support for sharded checkpoints using safetensors is coming soon!" "Support for sharded checkpoints using safetensors is coming soon!"
) )
elif has_file(pretrained_model_name_or_path, WEIGHTS_NAME, **has_file_kwargs): 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"{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" f" {FLAX_WEIGHTS_NAME} but there is a file for PyTorch weights. Use `from_pt=True` to"
" load this model from those weights." " load this model from those weights."
) )
elif has_file(pretrained_model_name_or_path, WEIGHTS_INDEX_NAME, **has_file_kwargs): 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"{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" 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." " `from_pt=True` to load this model from those weights."
) )
else: else:
raise EnvironmentError( raise OSError(
f"{pretrained_model_name_or_path} does not appear to have a file named" f"{pretrained_model_name_or_path} does not appear to have a file named"
f" {FLAX_WEIGHTS_NAME} or {WEIGHTS_NAME}." 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 # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted
# to the original exception. # to the original exception.
raise raise
except Exception: except Exception:
# For any other exception, we throw a generic error. # 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" 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" " 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" f" same name. Otherwise, make sure '{pretrained_model_name_or_path}' is the correct path to a"

View File

@@ -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. # At this stage we don't have a weight file so we will raise an error.
elif use_safetensors: 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"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"Please make sure that the model has been saved with `safe_serialization=True` or do not "
f"set `use_safetensors=True`." 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( 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) 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} " 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 " "but there is a file for PyTorch weights. Use `from_pt=True` to load this model from those "
"weights." "weights."
) )
else: else:
raise EnvironmentError( raise OSError(
f"Error no file named {TF2_WEIGHTS_NAME}, {SAFE_WEIGHTS_NAME} or {WEIGHTS_NAME} found in directory " f"Error no file named {TF2_WEIGHTS_NAME}, {SAFE_WEIGHTS_NAME} or {WEIGHTS_NAME} found in directory "
f"{pretrained_model_name_or_path}." 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): if has_file(pretrained_model_name_or_path, SAFE_WEIGHTS_INDEX_NAME, **has_file_kwargs):
is_sharded = True is_sharded = True
elif has_file(pretrained_model_name_or_path, WEIGHTS_NAME, **has_file_kwargs): 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"{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" f" {TF2_WEIGHTS_NAME} but there is a file for PyTorch weights. Use `from_pt=True` to"
" load this model from those weights." " load this model from those weights."
) )
else: else:
raise EnvironmentError( raise OSError(
f"{pretrained_model_name_or_path} does not appear to have a file named {WEIGHTS_NAME}," f"{pretrained_model_name_or_path} does not appear to have a file named {WEIGHTS_NAME},"
f" {TF2_WEIGHTS_NAME} or {TF_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 # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted
# to the original exception. # to the original exception.
raise raise
except Exception: except Exception:
# For any other exception, we throw a generic error. # 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" 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" " 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" f" same name. Otherwise, make sure '{pretrained_model_name_or_path}' is the correct path to a"

View File

@@ -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")) 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)) 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"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" 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." " `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( elif not use_safetensors and os.path.isfile(
os.path.join(pretrained_model_name_or_path, subfolder, FLAX_WEIGHTS_NAME) 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"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`" 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." " to load this model from those weights."
) )
elif use_safetensors: elif use_safetensors:
raise EnvironmentError( raise OSError(
f"Error no file named {_add_variant(SAFE_WEIGHTS_NAME, variant)} found in directory" f"Error no file named {_add_variant(SAFE_WEIGHTS_NAME, variant)} found in directory"
f" {pretrained_model_name_or_path}." f" {pretrained_model_name_or_path}."
) )
else: else:
raise EnvironmentError( raise OSError(
f"Error no file named {_add_variant(WEIGHTS_NAME, variant)}, {_add_variant(SAFE_WEIGHTS_NAME, variant)}," 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" {TF2_WEIGHTS_NAME}, {TF_WEIGHTS_NAME + '.index'} or {FLAX_WEIGHTS_NAME} found in directory"
f" {pretrained_model_name_or_path}." f" {pretrained_model_name_or_path}."
@@ -1156,7 +1156,7 @@ def _get_resolved_checkpoint_files(
) )
cached_file_kwargs["revision"] = revision cached_file_kwargs["revision"] = revision
if resolved_archive_file is None: 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"{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)} " 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 " "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, "local_files_only": local_files_only,
} }
if has_file(pretrained_model_name_or_path, TF2_WEIGHTS_NAME, **has_file_kwargs): 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"{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." 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." " 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): 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"{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" 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." " `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( elif variant is not None and has_file(
pretrained_model_name_or_path, WEIGHTS_NAME, **has_file_kwargs 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"{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" {_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." f" {variant}. Use `variant=None` to load this model from those weights."
) )
else: else:
raise EnvironmentError( raise OSError(
f"{pretrained_model_name_or_path} does not appear to have a file named" 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" {_add_variant(WEIGHTS_NAME, variant)}, {_add_variant(SAFE_WEIGHTS_NAME, variant)},"
f" {TF2_WEIGHTS_NAME}, {TF_WEIGHTS_NAME} or {FLAX_WEIGHTS_NAME}." 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 # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted
# to the original exception. # to the original exception.
raise raise
except Exception as e: except Exception as e:
# For any other exception, we throw a generic error. # 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" 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" " 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" f" same name. Otherwise, make sure '{pretrained_model_name_or_path}' is the correct path to a"

View File

@@ -415,7 +415,7 @@ class _BaseAutoModelClass:
_model_mapping = None _model_mapping = None
def __init__(self, *args, **kwargs) -> None: def __init__(self, *args, **kwargs) -> None:
raise EnvironmentError( raise OSError(
f"{self.__class__.__name__} is designed to be instantiated " f"{self.__class__.__name__} is designed to be instantiated "
f"using the `{self.__class__.__name__}.from_pretrained(pretrained_model_name_or_path)` or " f"using the `{self.__class__.__name__}.from_pretrained(pretrained_model_name_or_path)` or "
f"`{self.__class__.__name__}.from_config(config)` methods." f"`{self.__class__.__name__}.from_config(config)` methods."

View File

@@ -1047,7 +1047,7 @@ class AutoConfig:
""" """
def __init__(self) -> None: def __init__(self) -> None:
raise EnvironmentError( raise OSError(
"AutoConfig is designed to be instantiated " "AutoConfig is designed to be instantiated "
"using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method." "using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method."
) )

View File

@@ -255,7 +255,7 @@ class AutoFeatureExtractor:
""" """
def __init__(self): def __init__(self):
raise EnvironmentError( raise OSError(
"AutoFeatureExtractor is designed to be instantiated " "AutoFeatureExtractor is designed to be instantiated "
"using the `AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)` method." "using the `AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)` method."
) )

View File

@@ -338,7 +338,7 @@ class AutoImageProcessor:
""" """
def __init__(self): def __init__(self):
raise EnvironmentError( raise OSError(
"AutoImageProcessor is designed to be instantiated " "AutoImageProcessor is designed to be instantiated "
"using the `AutoImageProcessor.from_pretrained(pretrained_model_name_or_path)` method." "using the `AutoImageProcessor.from_pretrained(pretrained_model_name_or_path)` method."
) )

View File

@@ -176,7 +176,7 @@ class AutoProcessor:
""" """
def __init__(self): def __init__(self):
raise EnvironmentError( raise OSError(
"AutoProcessor is designed to be instantiated " "AutoProcessor is designed to be instantiated "
"using the `AutoProcessor.from_pretrained(pretrained_model_name_or_path)` method." "using the `AutoProcessor.from_pretrained(pretrained_model_name_or_path)` method."
) )

View File

@@ -819,7 +819,7 @@ class AutoTokenizer:
""" """
def __init__(self): def __init__(self):
raise EnvironmentError( raise OSError(
"AutoTokenizer is designed to be instantiated " "AutoTokenizer is designed to be instantiated "
"using the `AutoTokenizer.from_pretrained(pretrained_model_name_or_path)` method." "using the `AutoTokenizer.from_pretrained(pretrained_model_name_or_path)` method."
) )

View File

@@ -205,7 +205,7 @@ class AutoVideoProcessor:
""" """
def __init__(self): def __init__(self):
raise EnvironmentError( raise OSError(
"AutoVideoProcessor is designed to be instantiated " "AutoVideoProcessor is designed to be instantiated "
"using the `AutoVideoProcessor.from_pretrained(pretrained_model_name_or_path)` method." "using the `AutoVideoProcessor.from_pretrained(pretrained_model_name_or_path)` method."
) )

View File

@@ -693,7 +693,7 @@ class TransfoXLCorpus:
# redirect to the cache, if necessary # redirect to the cache, if necessary
try: try:
resolved_corpus_file = cached_file(pretrained_model_name_or_path, CORPUS_NAME, cache_dir=cache_dir) resolved_corpus_file = cached_file(pretrained_model_name_or_path, CORPUS_NAME, cache_dir=cache_dir)
except EnvironmentError: except OSError:
logger.error( logger.error(
f"Corpus '{pretrained_model_name_or_path}' was not found in corpus list" 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}'" f" ({', '.join(PRETRAINED_CORPUS_ARCHIVE_MAP.keys())}. We assumed '{pretrained_model_name_or_path}'"

View File

@@ -117,13 +117,13 @@ class LegacyIndex(Index):
try: try:
# Load from URL or cache if already cached # Load from URL or cache if already cached
resolved_archive_file = cached_file(index_path, filename) resolved_archive_file = cached_file(index_path, filename)
except EnvironmentError: except OSError:
msg = ( msg = (
f"Can't load '{filename}'. Make sure that:\n\n" 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"- '{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" 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: if is_local:
logger.info(f"loading file {resolved_archive_file}") logger.info(f"loading file {resolved_archive_file}")
else: else:

View File

@@ -1322,7 +1322,7 @@ class Wav2Vec2PreTrainedModel(PreTrainedModel):
state_dict = safe_load_file(weight_path) state_dict = safe_load_file(weight_path)
except EnvironmentError: except OSError:
if use_safetensors: if use_safetensors:
# Raise any environment error raise by `cached_file`. It will have a helpful error message adapted # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted
# to the original exception. # to the original exception.
@@ -1331,7 +1331,7 @@ class Wav2Vec2PreTrainedModel(PreTrainedModel):
except Exception: except Exception:
# For any other exception, we throw a generic error. # For any other exception, we throw a generic error.
if use_safetensors: 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" 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" " 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" 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, weights_only=True,
) )
except EnvironmentError: except OSError:
# Raise any environment error raise by `cached_file`. It will have a helpful error message adapted # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted
# to the original exception. # to the original exception.
raise raise
@@ -1372,7 +1372,7 @@ class Wav2Vec2PreTrainedModel(PreTrainedModel):
except Exception: except Exception:
# For any other exception, we throw a generic error. # 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" 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" " 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" f" same name. Otherwise, make sure '{model_path_or_id}' is the correct path to a"

View File

@@ -669,7 +669,7 @@ class FeaturesManager:
elif is_tf_available(): elif is_tf_available():
framework = "tf" framework = "tf"
else: 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.") logger.info(f"Framework not requested. Using {exporter_map[framework]} to export to ONNX.")

View File

@@ -570,7 +570,7 @@ def cached_files(
msg = ( msg = (
f"a file named {missing_entries[0]}" if len(missing_entries) == 1 else f"files named {(*missing_entries,)}" 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_}'" f"{path_or_repo_id} does not appear to have {msg}. Checkout 'https://huggingface.co/{path_or_repo_id}/tree/{revision_}'"
" for available files." " for available files."
) )

View File

@@ -579,7 +579,7 @@ class BaseVideoProcessor(BaseImageProcessorFast):
revision=revision, revision=revision,
subfolder=subfolder, subfolder=subfolder,
) )
except EnvironmentError: except OSError:
video_processor_file = "preprocessor_config.json" video_processor_file = "preprocessor_config.json"
resolved_video_processor_file = cached_file( resolved_video_processor_file = cached_file(
pretrained_model_name_or_path, 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. " "the file or load and save the processor back which renames it automatically. "
"Loading from `preprocessor.json` will be removed in v5.0." "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 # Raise any environment error raise by `cached_file`. It will have a helpful error message adapted to
# the original exception. # the original exception.
raise raise
except Exception: except Exception:
# For any other exception, we throw a generic error. # 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" 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" " 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" 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) video_processor_dict = json.loads(text)
except json.JSONDecodeError: 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." f"It looks like the config file at '{resolved_video_processor_file}' is not a valid JSON file."
) )