diff --git a/src/transformers/utils/hub.py b/src/transformers/utils/hub.py index 0d58211da83..f6cf0a852ed 100644 --- a/src/transformers/utils/hub.py +++ b/src/transformers/utils/hub.py @@ -43,6 +43,7 @@ from huggingface_hub.file_download import REGEX_COMMIT_HASH, http_get from huggingface_hub.utils import ( EntryNotFoundError, GatedRepoError, + HFValidationError, LocalEntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError, @@ -491,7 +492,10 @@ def cached_file( return None raise EnvironmentError(f"There was a specific connection error when trying to load {path_or_repo_id}:\n{err}") - + except HFValidationError as e: + raise EnvironmentError( + f"Incorrect path_or_model_id: '{path_or_repo_id}'. Please provide either the path to a local folder or the repo_id of a model on the Hub." + ) from e return resolved_file diff --git a/tests/test_configuration_common.py b/tests/test_configuration_common.py index 5fb93f71eb0..57521a3e7c5 100644 --- a/tests/test_configuration_common.py +++ b/tests/test_configuration_common.py @@ -96,6 +96,9 @@ class ConfigTester(object): self.parent.assertEqual(config_second.to_dict(), config_first.to_dict()) + with self.parent.assertRaises(OSError): + self.config_class.from_pretrained(f".{tmpdirname}") + def create_and_test_config_from_and_save_pretrained_subfolder(self): config_first = self.config_class(**self.inputs_dict)