huggingface-hub 0.12.0rc0__py3-none-any.whl → 0.13.0rc0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- huggingface_hub/__init__.py +166 -126
- huggingface_hub/_commit_api.py +25 -51
- huggingface_hub/_login.py +4 -13
- huggingface_hub/_snapshot_download.py +45 -23
- huggingface_hub/_space_api.py +7 -0
- huggingface_hub/commands/delete_cache.py +13 -39
- huggingface_hub/commands/env.py +1 -3
- huggingface_hub/commands/huggingface_cli.py +1 -3
- huggingface_hub/commands/lfs.py +4 -8
- huggingface_hub/commands/scan_cache.py +5 -16
- huggingface_hub/commands/user.py +27 -45
- huggingface_hub/community.py +4 -4
- huggingface_hub/constants.py +22 -19
- huggingface_hub/fastai_utils.py +14 -23
- huggingface_hub/file_download.py +210 -121
- huggingface_hub/hf_api.py +500 -255
- huggingface_hub/hub_mixin.py +181 -176
- huggingface_hub/inference_api.py +4 -10
- huggingface_hub/keras_mixin.py +39 -71
- huggingface_hub/lfs.py +8 -24
- huggingface_hub/repocard.py +33 -48
- huggingface_hub/repocard_data.py +141 -30
- huggingface_hub/repository.py +41 -112
- huggingface_hub/templates/modelcard_template.md +39 -34
- huggingface_hub/utils/__init__.py +1 -0
- huggingface_hub/utils/_cache_assets.py +1 -4
- huggingface_hub/utils/_cache_manager.py +17 -39
- huggingface_hub/utils/_deprecation.py +8 -12
- huggingface_hub/utils/_errors.py +10 -57
- huggingface_hub/utils/_fixes.py +2 -6
- huggingface_hub/utils/_git_credential.py +5 -16
- huggingface_hub/utils/_headers.py +22 -11
- huggingface_hub/utils/_http.py +1 -4
- huggingface_hub/utils/_paths.py +5 -12
- huggingface_hub/utils/_runtime.py +2 -1
- huggingface_hub/utils/_telemetry.py +120 -0
- huggingface_hub/utils/_validators.py +5 -13
- huggingface_hub/utils/endpoint_helpers.py +1 -3
- huggingface_hub/utils/logging.py +10 -8
- {huggingface_hub-0.12.0rc0.dist-info → huggingface_hub-0.13.0rc0.dist-info}/METADATA +7 -14
- huggingface_hub-0.13.0rc0.dist-info/RECORD +56 -0
- huggingface_hub/py.typed +0 -0
- huggingface_hub-0.12.0rc0.dist-info/RECORD +0 -56
- {huggingface_hub-0.12.0rc0.dist-info → huggingface_hub-0.13.0rc0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.12.0rc0.dist-info → huggingface_hub-0.13.0rc0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.12.0rc0.dist-info → huggingface_hub-0.13.0rc0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.12.0rc0.dist-info → huggingface_hub-0.13.0rc0.dist-info}/top_level.txt +0 -0
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
{{ model_summary | default("", true) }}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Model Details
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
### Model Description
|
|
16
16
|
|
|
17
17
|
<!-- Provide a longer summary of what this model is. -->
|
|
18
18
|
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
- **License:** {{ license | default("[More Information Needed]", true)}}
|
|
26
26
|
- **Finetuned from model [optional]:** {{ finetuned_from | default("[More Information Needed]", true)}}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
### Model Sources [optional]
|
|
29
29
|
|
|
30
30
|
<!-- Provide the basic links for the model. -->
|
|
31
31
|
|
|
@@ -33,107 +33,112 @@
|
|
|
33
33
|
- **Paper [optional]:** {{ paper | default("[More Information Needed]", true)}}
|
|
34
34
|
- **Demo [optional]:** {{ demo | default("[More Information Needed]", true)}}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
## Uses
|
|
37
37
|
|
|
38
38
|
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
### Direct Use
|
|
41
41
|
|
|
42
42
|
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
|
43
43
|
|
|
44
44
|
{{ direct_use | default("[More Information Needed]", true)}}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
### Downstream Use [optional]
|
|
47
47
|
|
|
48
48
|
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
|
49
49
|
|
|
50
50
|
{{ downstream_use | default("[More Information Needed]", true)}}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
### Out-of-Scope Use
|
|
53
53
|
|
|
54
54
|
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
|
55
55
|
|
|
56
56
|
{{ out_of_scope_use | default("[More Information Needed]", true)}}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
## Bias, Risks, and Limitations
|
|
59
59
|
|
|
60
60
|
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
|
61
61
|
|
|
62
62
|
{{ bias_risks_limitations | default("[More Information Needed]", true)}}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
### Recommendations
|
|
65
65
|
|
|
66
66
|
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
|
67
67
|
|
|
68
68
|
{{ bias_recommendations | default("Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.", true)}}
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
### How to Get Started with the Model
|
|
71
71
|
|
|
72
72
|
Use the code below to get started with the model.
|
|
73
73
|
|
|
74
74
|
{{ get_started_code | default("[More Information Needed]", true)}}
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
## Training Details
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
### Training Data
|
|
79
79
|
|
|
80
80
|
<!-- This should link to a Data Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
|
81
81
|
|
|
82
82
|
{{ training_data | default("[More Information Needed]", true)}}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
### Training Procedure
|
|
85
85
|
|
|
86
86
|
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
#### Preprocessing [optional]
|
|
89
89
|
|
|
90
90
|
{{ preprocessing | default("[More Information Needed]", true)}}
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
|
|
93
|
+
#### Training Hyperparameters
|
|
94
|
+
|
|
95
|
+
- **Training regime:** {{ training_regime | default("[More Information Needed]", true)}} <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
|
96
|
+
|
|
97
|
+
#### Speeds, Sizes, Times [optional]
|
|
93
98
|
|
|
94
99
|
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
|
95
100
|
|
|
96
101
|
{{ speeds_sizes_times | default("[More Information Needed]", true)}}
|
|
97
102
|
|
|
98
|
-
|
|
103
|
+
## Evaluation
|
|
99
104
|
|
|
100
105
|
<!-- This section describes the evaluation protocols and provides the results. -->
|
|
101
106
|
|
|
102
|
-
|
|
107
|
+
### Testing Data, Factors & Metrics
|
|
103
108
|
|
|
104
|
-
|
|
109
|
+
#### Testing Data
|
|
105
110
|
|
|
106
111
|
<!-- This should link to a Data Card if possible. -->
|
|
107
112
|
|
|
108
113
|
{{ testing_data | default("[More Information Needed]", true)}}
|
|
109
114
|
|
|
110
|
-
|
|
115
|
+
#### Factors
|
|
111
116
|
|
|
112
117
|
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
|
113
118
|
|
|
114
119
|
{{ testing_factors | default("[More Information Needed]", true)}}
|
|
115
120
|
|
|
116
|
-
|
|
121
|
+
#### Metrics
|
|
117
122
|
|
|
118
123
|
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
|
119
124
|
|
|
120
125
|
{{ testing_metrics | default("[More Information Needed]", true)}}
|
|
121
126
|
|
|
122
|
-
|
|
127
|
+
### Results
|
|
123
128
|
|
|
124
129
|
{{ results | default("[More Information Needed]", true)}}
|
|
125
130
|
|
|
126
|
-
|
|
131
|
+
#### Summary
|
|
127
132
|
|
|
128
133
|
{{ results_summary | default("", true) }}
|
|
129
134
|
|
|
130
|
-
|
|
135
|
+
## Model Examination [optional]
|
|
131
136
|
|
|
132
137
|
<!-- Relevant interpretability work for the model goes here -->
|
|
133
138
|
|
|
134
139
|
{{ model_examination | default("[More Information Needed]", true)}}
|
|
135
140
|
|
|
136
|
-
|
|
141
|
+
## Environmental Impact
|
|
137
142
|
|
|
138
143
|
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
|
139
144
|
|
|
@@ -145,25 +150,25 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
|
|
|
145
150
|
- **Compute Region:** {{ cloud_region | default("[More Information Needed]", true)}}
|
|
146
151
|
- **Carbon Emitted:** {{ co2_emitted | default("[More Information Needed]", true)}}
|
|
147
152
|
|
|
148
|
-
|
|
153
|
+
## Technical Specifications [optional]
|
|
149
154
|
|
|
150
|
-
|
|
155
|
+
### Model Architecture and Objective
|
|
151
156
|
|
|
152
157
|
{{ model_specs | default("[More Information Needed]", true)}}
|
|
153
158
|
|
|
154
|
-
|
|
159
|
+
### Compute Infrastructure
|
|
155
160
|
|
|
156
161
|
{{ compute_infrastructure | default("[More Information Needed]", true)}}
|
|
157
162
|
|
|
158
|
-
|
|
163
|
+
#### Hardware
|
|
159
164
|
|
|
160
165
|
{{ hardware | default("[More Information Needed]", true)}}
|
|
161
166
|
|
|
162
|
-
|
|
167
|
+
#### Software
|
|
163
168
|
|
|
164
169
|
{{ software | default("[More Information Needed]", true)}}
|
|
165
170
|
|
|
166
|
-
|
|
171
|
+
## Citation [optional]
|
|
167
172
|
|
|
168
173
|
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
|
169
174
|
|
|
@@ -175,21 +180,21 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
|
|
|
175
180
|
|
|
176
181
|
{{ citation_apa | default("[More Information Needed]", true)}}
|
|
177
182
|
|
|
178
|
-
|
|
183
|
+
## Glossary [optional]
|
|
179
184
|
|
|
180
185
|
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
|
181
186
|
|
|
182
187
|
{{ glossary | default("[More Information Needed]", true)}}
|
|
183
188
|
|
|
184
|
-
|
|
189
|
+
## More Information [optional]
|
|
185
190
|
|
|
186
191
|
{{ more_information | default("[More Information Needed]", true)}}
|
|
187
192
|
|
|
188
|
-
|
|
193
|
+
## Model Card Authors [optional]
|
|
189
194
|
|
|
190
195
|
{{ model_card_authors | default("[More Information Needed]", true)}}
|
|
191
196
|
|
|
192
|
-
|
|
197
|
+
## Model Card Contact
|
|
193
198
|
|
|
194
199
|
{{ model_card_contact | default("[More Information Needed]", true)}}
|
|
195
200
|
|
|
@@ -129,10 +129,7 @@ def cached_assets_path(
|
|
|
129
129
|
try:
|
|
130
130
|
path.mkdir(exist_ok=True, parents=True)
|
|
131
131
|
except (FileExistsError, NotADirectoryError):
|
|
132
|
-
raise ValueError(
|
|
133
|
-
"Corrupted assets folder: cannot create directory because of an existing"
|
|
134
|
-
f" file ({path})."
|
|
135
|
-
)
|
|
132
|
+
raise ValueError(f"Corrupted assets folder: cannot create directory because of an existing file ({path}).")
|
|
136
133
|
|
|
137
134
|
# Return
|
|
138
135
|
return path
|
|
@@ -430,9 +430,7 @@ class HFCacheInfo:
|
|
|
430
430
|
"""
|
|
431
431
|
hashes_to_delete: Set[str] = set(revisions)
|
|
432
432
|
|
|
433
|
-
repos_with_revisions: Dict[
|
|
434
|
-
CachedRepoInfo, Set[CachedRevisionInfo]
|
|
435
|
-
] = defaultdict(set)
|
|
433
|
+
repos_with_revisions: Dict[CachedRepoInfo, Set[CachedRevisionInfo]] = defaultdict(set)
|
|
436
434
|
|
|
437
435
|
for repo in self.repos:
|
|
438
436
|
for revision in repo.revisions:
|
|
@@ -441,10 +439,7 @@ class HFCacheInfo:
|
|
|
441
439
|
hashes_to_delete.remove(revision.commit_hash)
|
|
442
440
|
|
|
443
441
|
if len(hashes_to_delete) > 0:
|
|
444
|
-
logger.warning(
|
|
445
|
-
"Revision(s) not found - cannot delete them:"
|
|
446
|
-
f" {', '.join(hashes_to_delete)}"
|
|
447
|
-
)
|
|
442
|
+
logger.warning(f"Revision(s) not found - cannot delete them: {', '.join(hashes_to_delete)}")
|
|
448
443
|
|
|
449
444
|
delete_strategy_blobs: Set[Path] = set()
|
|
450
445
|
delete_strategy_refs: Set[Path] = set()
|
|
@@ -591,8 +586,10 @@ def scan_cache_dir(cache_dir: Optional[Union[str, Path]] = None) -> HFCacheInfo:
|
|
|
591
586
|
cache_dir = Path(cache_dir).expanduser().resolve()
|
|
592
587
|
if not cache_dir.exists():
|
|
593
588
|
raise CacheNotFound(
|
|
594
|
-
|
|
595
|
-
|
|
589
|
+
(
|
|
590
|
+
f"Cache directory not found: {cache_dir}. Please use `cache_dir`"
|
|
591
|
+
" argument or set `HUGGINGFACE_HUB_CACHE` environment variable."
|
|
592
|
+
),
|
|
596
593
|
cache_dir=cache_dir,
|
|
597
594
|
)
|
|
598
595
|
|
|
@@ -627,9 +624,7 @@ def _scan_cached_repo(repo_path: Path) -> CachedRepoInfo:
|
|
|
627
624
|
raise CorruptedCacheException(f"Repo path is not a directory: {repo_path}")
|
|
628
625
|
|
|
629
626
|
if "--" not in repo_path.name:
|
|
630
|
-
raise CorruptedCacheException(
|
|
631
|
-
f"Repo path is not a valid HuggingFace cache directory: {repo_path}"
|
|
632
|
-
)
|
|
627
|
+
raise CorruptedCacheException(f"Repo path is not a valid HuggingFace cache directory: {repo_path}")
|
|
633
628
|
|
|
634
629
|
repo_type, repo_id = repo_path.name.split("--", maxsplit=1)
|
|
635
630
|
repo_type = repo_type[:-1] # "models" -> "model"
|
|
@@ -637,8 +632,7 @@ def _scan_cached_repo(repo_path: Path) -> CachedRepoInfo:
|
|
|
637
632
|
|
|
638
633
|
if repo_type not in {"dataset", "model", "space"}:
|
|
639
634
|
raise CorruptedCacheException(
|
|
640
|
-
f"Repo type must be `dataset`, `model` or `space`, found `{repo_type}`"
|
|
641
|
-
f" ({repo_path})."
|
|
635
|
+
f"Repo type must be `dataset`, `model` or `space`, found `{repo_type}` ({repo_path})."
|
|
642
636
|
)
|
|
643
637
|
|
|
644
638
|
blob_stats: Dict[Path, os.stat_result] = {} # Key is blob_path, value is blob stats
|
|
@@ -647,9 +641,7 @@ def _scan_cached_repo(repo_path: Path) -> CachedRepoInfo:
|
|
|
647
641
|
refs_path = repo_path / "refs"
|
|
648
642
|
|
|
649
643
|
if not snapshots_path.exists() or not snapshots_path.is_dir():
|
|
650
|
-
raise CorruptedCacheException(
|
|
651
|
-
f"Snapshots dir doesn't exist in cached repo: {snapshots_path}"
|
|
652
|
-
)
|
|
644
|
+
raise CorruptedCacheException(f"Snapshots dir doesn't exist in cached repo: {snapshots_path}")
|
|
653
645
|
|
|
654
646
|
# Scan over `refs` directory
|
|
655
647
|
|
|
@@ -663,9 +655,7 @@ def _scan_cached_repo(repo_path: Path) -> CachedRepoInfo:
|
|
|
663
655
|
# └── pr
|
|
664
656
|
# └── 1
|
|
665
657
|
if refs_path.is_file():
|
|
666
|
-
raise CorruptedCacheException(
|
|
667
|
-
f"Refs directory cannot be a file: {refs_path}"
|
|
668
|
-
)
|
|
658
|
+
raise CorruptedCacheException(f"Refs directory cannot be a file: {refs_path}")
|
|
669
659
|
|
|
670
660
|
for ref_path in refs_path.glob("**/*"):
|
|
671
661
|
# glob("**/*") iterates over all files and directories -> skip directories
|
|
@@ -682,9 +672,7 @@ def _scan_cached_repo(repo_path: Path) -> CachedRepoInfo:
|
|
|
682
672
|
cached_revisions: Set[CachedRevisionInfo] = set()
|
|
683
673
|
for revision_path in snapshots_path.iterdir():
|
|
684
674
|
if revision_path.is_file():
|
|
685
|
-
raise CorruptedCacheException(
|
|
686
|
-
f"Snapshots folder corrupted. Found a file: {revision_path}"
|
|
687
|
-
)
|
|
675
|
+
raise CorruptedCacheException(f"Snapshots folder corrupted. Found a file: {revision_path}")
|
|
688
676
|
|
|
689
677
|
cached_files = set()
|
|
690
678
|
for file_path in revision_path.glob("**/*"):
|
|
@@ -694,9 +682,7 @@ def _scan_cached_repo(repo_path: Path) -> CachedRepoInfo:
|
|
|
694
682
|
|
|
695
683
|
blob_path = Path(file_path).resolve()
|
|
696
684
|
if not blob_path.exists():
|
|
697
|
-
raise CorruptedCacheException(
|
|
698
|
-
f"Blob missing (broken symlink): {blob_path}"
|
|
699
|
-
)
|
|
685
|
+
raise CorruptedCacheException(f"Blob missing (broken symlink): {blob_path}")
|
|
700
686
|
|
|
701
687
|
if blob_path not in blob_stats:
|
|
702
688
|
blob_stats[blob_path] = blob_path.stat()
|
|
@@ -715,9 +701,7 @@ def _scan_cached_repo(repo_path: Path) -> CachedRepoInfo:
|
|
|
715
701
|
# Last modified is either the last modified blob file or the revision folder
|
|
716
702
|
# itself if it is empty
|
|
717
703
|
if len(cached_files) > 0:
|
|
718
|
-
revision_last_modified = max(
|
|
719
|
-
blob_stats[file.blob_path].st_mtime for file in cached_files
|
|
720
|
-
)
|
|
704
|
+
revision_last_modified = max(blob_stats[file.blob_path].st_mtime for file in cached_files)
|
|
721
705
|
else:
|
|
722
706
|
revision_last_modified = revision_path.stat().st_mtime
|
|
723
707
|
|
|
@@ -727,8 +711,7 @@ def _scan_cached_repo(repo_path: Path) -> CachedRepoInfo:
|
|
|
727
711
|
files=frozenset(cached_files),
|
|
728
712
|
refs=frozenset(refs_by_hash.pop(revision_path.name, set())),
|
|
729
713
|
size_on_disk=sum(
|
|
730
|
-
blob_stats[blob_path].st_size
|
|
731
|
-
for blob_path in set(file.blob_path for file in cached_files)
|
|
714
|
+
blob_stats[blob_path].st_size for blob_path in set(file.blob_path for file in cached_files)
|
|
732
715
|
),
|
|
733
716
|
snapshot_path=revision_path,
|
|
734
717
|
last_modified=revision_last_modified,
|
|
@@ -738,8 +721,7 @@ def _scan_cached_repo(repo_path: Path) -> CachedRepoInfo:
|
|
|
738
721
|
# Check that all refs referred to an existing revision
|
|
739
722
|
if len(refs_by_hash) > 0:
|
|
740
723
|
raise CorruptedCacheException(
|
|
741
|
-
"Reference(s) refer to missing commit hashes:"
|
|
742
|
-
f" {dict(refs_by_hash)} ({repo_path})."
|
|
724
|
+
f"Reference(s) refer to missing commit hashes: {dict(refs_by_hash)} ({repo_path})."
|
|
743
725
|
)
|
|
744
726
|
|
|
745
727
|
# Last modified is either the last modified blob file or the repo folder itself if
|
|
@@ -823,10 +805,6 @@ def _try_delete_path(path: Path, path_type: str) -> None:
|
|
|
823
805
|
else:
|
|
824
806
|
shutil.rmtree(path)
|
|
825
807
|
except FileNotFoundError:
|
|
826
|
-
logger.warning(
|
|
827
|
-
f"Couldn't delete {path_type}: file not found ({path})", exc_info=True
|
|
828
|
-
)
|
|
808
|
+
logger.warning(f"Couldn't delete {path_type}: file not found ({path})", exc_info=True)
|
|
829
809
|
except PermissionError:
|
|
830
|
-
logger.warning(
|
|
831
|
-
f"Couldn't delete {path_type}: permission denied ({path})", exc_info=True
|
|
832
|
-
)
|
|
810
|
+
logger.warning(f"Couldn't delete {path_type}: permission denied ({path})", exc_info=True)
|
|
@@ -36,9 +36,11 @@ def _deprecate_positional_args(*, version: str):
|
|
|
36
36
|
]
|
|
37
37
|
args_msg = ", ".join(args_msg)
|
|
38
38
|
warnings.warn(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
(
|
|
40
|
+
f"Deprecated positional argument(s) used in '{f.__name__}': pass"
|
|
41
|
+
f" {args_msg} as keyword args. From version {version} passing these"
|
|
42
|
+
" as positional arguments will result in an error,"
|
|
43
|
+
),
|
|
42
44
|
FutureWarning,
|
|
43
45
|
)
|
|
44
46
|
kwargs.update(zip(sig.parameters, args))
|
|
@@ -120,8 +122,7 @@ def _deprecate_method(*, version: str, message: Optional[str] = None):
|
|
|
120
122
|
@wraps(f)
|
|
121
123
|
def inner_f(*args, **kwargs):
|
|
122
124
|
warning_message = (
|
|
123
|
-
f"'{f.__name__}' (from '{f.__module__}') is deprecated and will be"
|
|
124
|
-
f" removed from version '{version}'."
|
|
125
|
+
f"'{f.__name__}' (from '{f.__module__}') is deprecated and will be removed from version '{version}'."
|
|
125
126
|
)
|
|
126
127
|
if message is not None:
|
|
127
128
|
warning_message += " " + message
|
|
@@ -189,14 +190,9 @@ class DeprecateListMetaclass(type):
|
|
|
189
190
|
def __new__(cls, clsname, bases, attrs):
|
|
190
191
|
# Check consistency
|
|
191
192
|
if "_deprecate" not in attrs:
|
|
192
|
-
raise TypeError(
|
|
193
|
-
"A `_deprecate` method must be implemented to use"
|
|
194
|
-
" `DeprecateListMetaclass`."
|
|
195
|
-
)
|
|
193
|
+
raise TypeError("A `_deprecate` method must be implemented to use `DeprecateListMetaclass`.")
|
|
196
194
|
if list not in bases:
|
|
197
|
-
raise TypeError(
|
|
198
|
-
"Class must inherit from `list` to use `DeprecateListMetaclass`."
|
|
199
|
-
)
|
|
195
|
+
raise TypeError("Class must inherit from `list` to use `DeprecateListMetaclass`.")
|
|
200
196
|
|
|
201
197
|
# Create decorator to deprecate list-only methods, including magic ones
|
|
202
198
|
def _with_deprecation(f, name):
|
huggingface_hub/utils/_errors.py
CHANGED
|
@@ -2,7 +2,6 @@ from typing import Optional
|
|
|
2
2
|
|
|
3
3
|
from requests import HTTPError, Response
|
|
4
4
|
|
|
5
|
-
from ._deprecation import _deprecate_method
|
|
6
5
|
from ._fixes import JSONDecodeError
|
|
7
6
|
|
|
8
7
|
|
|
@@ -39,7 +38,7 @@ class HfHubHTTPError(HTTPError):
|
|
|
39
38
|
request_id: Optional[str] = None
|
|
40
39
|
server_message: Optional[str] = None
|
|
41
40
|
|
|
42
|
-
def __init__(self, message: str, response: Optional[Response]):
|
|
41
|
+
def __init__(self, message: str, response: Optional[Response] = None):
|
|
43
42
|
# Parse server information if any.
|
|
44
43
|
if response is not None:
|
|
45
44
|
self.request_id = response.headers.get("X-Request-Id")
|
|
@@ -52,9 +51,7 @@ class HfHubHTTPError(HTTPError):
|
|
|
52
51
|
server_message_from_headers = response.headers.get("X-Error-Message")
|
|
53
52
|
server_message_from_body = server_data.get("error")
|
|
54
53
|
server_multiple_messages_from_body = "\n".join(
|
|
55
|
-
error["message"]
|
|
56
|
-
for error in server_data.get("errors", [])
|
|
57
|
-
if "message" in error
|
|
54
|
+
error["message"] for error in server_data.get("errors", []) if "message" in error
|
|
58
55
|
)
|
|
59
56
|
|
|
60
57
|
# Concatenate error messages
|
|
@@ -203,9 +200,7 @@ class BadRequestError(HfHubHTTPError, ValueError):
|
|
|
203
200
|
"""
|
|
204
201
|
|
|
205
202
|
|
|
206
|
-
def hf_raise_for_status(
|
|
207
|
-
response: Response, endpoint_name: Optional[str] = None
|
|
208
|
-
) -> None:
|
|
203
|
+
def hf_raise_for_status(response: Response, endpoint_name: Optional[str] = None) -> None:
|
|
209
204
|
"""
|
|
210
205
|
Internal version of `response.raise_for_status()` that will refine a
|
|
211
206
|
potential HTTPError. Raised exception will be an instance of `HfHubHTTPError`.
|
|
@@ -266,26 +261,16 @@ def hf_raise_for_status(
|
|
|
266
261
|
error_code = response.headers.get("X-Error-Code")
|
|
267
262
|
|
|
268
263
|
if error_code == "RevisionNotFound":
|
|
269
|
-
message =
|
|
270
|
-
f"{response.status_code} Client Error."
|
|
271
|
-
+ "\n\n"
|
|
272
|
-
+ f"Revision Not Found for url: {response.url}."
|
|
273
|
-
)
|
|
264
|
+
message = f"{response.status_code} Client Error." + "\n\n" + f"Revision Not Found for url: {response.url}."
|
|
274
265
|
raise RevisionNotFoundError(message, response) from e
|
|
275
266
|
|
|
276
267
|
elif error_code == "EntryNotFound":
|
|
277
|
-
message =
|
|
278
|
-
f"{response.status_code} Client Error."
|
|
279
|
-
+ "\n\n"
|
|
280
|
-
+ f"Entry Not Found for url: {response.url}."
|
|
281
|
-
)
|
|
268
|
+
message = f"{response.status_code} Client Error." + "\n\n" + f"Entry Not Found for url: {response.url}."
|
|
282
269
|
raise EntryNotFoundError(message, response) from e
|
|
283
270
|
|
|
284
271
|
elif error_code == "GatedRepo":
|
|
285
272
|
message = (
|
|
286
|
-
f"{response.status_code} Client Error."
|
|
287
|
-
+ "\n\n"
|
|
288
|
-
+ f"Cannot access gated repo for url {response.url}."
|
|
273
|
+
f"{response.status_code} Client Error." + "\n\n" + f"Cannot access gated repo for url {response.url}."
|
|
289
274
|
)
|
|
290
275
|
raise GatedRepoError(message, response) from e
|
|
291
276
|
|
|
@@ -307,9 +292,7 @@ def hf_raise_for_status(
|
|
|
307
292
|
|
|
308
293
|
elif response.status_code == 400:
|
|
309
294
|
message = (
|
|
310
|
-
f"\n\nBad request for {endpoint_name} endpoint:"
|
|
311
|
-
if endpoint_name is not None
|
|
312
|
-
else "\n\nBad request:"
|
|
295
|
+
f"\n\nBad request for {endpoint_name} endpoint:" if endpoint_name is not None else "\n\nBad request:"
|
|
313
296
|
)
|
|
314
297
|
raise BadRequestError(message, response=response) from e
|
|
315
298
|
|
|
@@ -318,31 +301,7 @@ def hf_raise_for_status(
|
|
|
318
301
|
raise HfHubHTTPError(str(e), response=response) from e
|
|
319
302
|
|
|
320
303
|
|
|
321
|
-
|
|
322
|
-
def _raise_for_status(response):
|
|
323
|
-
"""Keep alias for now."""
|
|
324
|
-
hf_raise_for_status(response)
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
@_deprecate_method(version="0.13", message="Use `hf_raise_for_status` instead.")
|
|
328
|
-
def _raise_with_request_id(response):
|
|
329
|
-
"""Keep alias for now."""
|
|
330
|
-
hf_raise_for_status(response)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
@_deprecate_method(version="0.13", message="Use `hf_raise_for_status` instead.")
|
|
334
|
-
def _raise_convert_bad_request(response: Response, endpoint_name: str):
|
|
335
|
-
"""
|
|
336
|
-
Calls hf_raise_for_status on resp and converts HTTP 400 errors into ValueError.
|
|
337
|
-
|
|
338
|
-
Keep alias for now.
|
|
339
|
-
"""
|
|
340
|
-
hf_raise_for_status(response, endpoint_name=endpoint_name)
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
def _format_error_message(
|
|
344
|
-
message: str, request_id: Optional[str], server_message: Optional[str]
|
|
345
|
-
) -> str:
|
|
304
|
+
def _format_error_message(message: str, request_id: Optional[str], server_message: Optional[str]) -> str:
|
|
346
305
|
"""
|
|
347
306
|
Format the `HfHubHTTPError` error message based on initial message and information
|
|
348
307
|
returned by the server.
|
|
@@ -350,11 +309,7 @@ def _format_error_message(
|
|
|
350
309
|
Used when initializing `HfHubHTTPError`.
|
|
351
310
|
"""
|
|
352
311
|
# Add message from response body
|
|
353
|
-
if (
|
|
354
|
-
server_message is not None
|
|
355
|
-
and len(server_message) > 0
|
|
356
|
-
and server_message.lower() not in message.lower()
|
|
357
|
-
):
|
|
312
|
+
if server_message is not None and len(server_message) > 0 and server_message.lower() not in message.lower():
|
|
358
313
|
if "\n\n" in message:
|
|
359
314
|
message += "\n" + server_message
|
|
360
315
|
else:
|
|
@@ -365,9 +320,7 @@ def _format_error_message(
|
|
|
365
320
|
request_id_message = f" (Request ID: {request_id})"
|
|
366
321
|
if "\n" in message:
|
|
367
322
|
newline_index = message.index("\n")
|
|
368
|
-
message =
|
|
369
|
-
message[:newline_index] + request_id_message + message[newline_index:]
|
|
370
|
-
)
|
|
323
|
+
message = message[:newline_index] + request_id_message + message[newline_index:]
|
|
371
324
|
else:
|
|
372
325
|
message += request_id_message
|
|
373
326
|
|
huggingface_hub/utils/_fixes.py
CHANGED
|
@@ -31,9 +31,7 @@ import yaml
|
|
|
31
31
|
# >>> yaml_dump({"emoji": "👀", "some unicode": "日本か"})
|
|
32
32
|
# 'emoji: "👀"\nsome unicode: "日本か"\n'
|
|
33
33
|
# ```
|
|
34
|
-
yaml_dump: Callable[..., str] = partial( # type: ignore
|
|
35
|
-
yaml.dump, stream=None, allow_unicode=True
|
|
36
|
-
)
|
|
34
|
+
yaml_dump: Callable[..., str] = partial(yaml.dump, stream=None, allow_unicode=True) # type: ignore
|
|
37
35
|
|
|
38
36
|
|
|
39
37
|
@contextlib.contextmanager
|
|
@@ -53,9 +51,7 @@ def SoftTemporaryDirectory(
|
|
|
53
51
|
|
|
54
52
|
See https://www.scivision.dev/python-tempfile-permission-error-windows/.
|
|
55
53
|
"""
|
|
56
|
-
tmpdir = tempfile.TemporaryDirectory(
|
|
57
|
-
prefix=prefix, suffix=suffix, dir=dir, **kwargs
|
|
58
|
-
)
|
|
54
|
+
tmpdir = tempfile.TemporaryDirectory(prefix=prefix, suffix=suffix, dir=dir, **kwargs)
|
|
59
55
|
yield tmpdir.name
|
|
60
56
|
|
|
61
57
|
try:
|
|
@@ -40,18 +40,14 @@ def list_credential_helpers(folder: Optional[str] = None) -> List[str]:
|
|
|
40
40
|
# See: https://github.com/huggingface/huggingface_hub/pull/1138#discussion_r1013324508
|
|
41
41
|
return sorted( # Sort for nice printing
|
|
42
42
|
{ # Might have some duplicates
|
|
43
|
-
line.split("=")[-1].split()[0]
|
|
44
|
-
for line in output.split("\n")
|
|
45
|
-
if "credential.helper" in line
|
|
43
|
+
line.split("=")[-1].split()[0] for line in output.split("\n") if "credential.helper" in line
|
|
46
44
|
}
|
|
47
45
|
)
|
|
48
46
|
except subprocess.CalledProcessError as exc:
|
|
49
47
|
raise EnvironmentError(exc.stderr)
|
|
50
48
|
|
|
51
49
|
|
|
52
|
-
def set_git_credential(
|
|
53
|
-
token: str, username: str = "hf_user", folder: Optional[str] = None
|
|
54
|
-
) -> None:
|
|
50
|
+
def set_git_credential(token: str, username: str = "hf_user", folder: Optional[str] = None) -> None:
|
|
55
51
|
"""Save a username/token pair in git credential for HF Hub registry.
|
|
56
52
|
|
|
57
53
|
Credentials are saved in all configured helpers (store, cache, macOS keychain,...).
|
|
@@ -70,15 +66,11 @@ def set_git_credential(
|
|
|
70
66
|
stdin,
|
|
71
67
|
_,
|
|
72
68
|
):
|
|
73
|
-
stdin.write(
|
|
74
|
-
f"url={ENDPOINT}\nusername={username.lower()}\npassword={token}\n\n"
|
|
75
|
-
)
|
|
69
|
+
stdin.write(f"url={ENDPOINT}\nusername={username.lower()}\npassword={token}\n\n")
|
|
76
70
|
stdin.flush()
|
|
77
71
|
|
|
78
72
|
|
|
79
|
-
def unset_git_credential(
|
|
80
|
-
username: str = "hf_user", folder: Optional[str] = None
|
|
81
|
-
) -> None:
|
|
73
|
+
def unset_git_credential(username: str = "hf_user", folder: Optional[str] = None) -> None:
|
|
82
74
|
"""Erase credentials from git credential for HF Hub registry.
|
|
83
75
|
|
|
84
76
|
Credentials are erased from the configured helpers (store, cache, macOS
|
|
@@ -122,10 +114,7 @@ def write_to_credential_store(username: str, password: str) -> None:
|
|
|
122
114
|
|
|
123
115
|
@_deprecate_method(
|
|
124
116
|
version="0.14",
|
|
125
|
-
message=
|
|
126
|
-
"Please open an issue on https://github.com/huggingface/huggingface_hub if this"
|
|
127
|
-
" a useful feature for you."
|
|
128
|
-
),
|
|
117
|
+
message="Please open an issue on https://github.com/huggingface/huggingface_hub if this a useful feature for you.",
|
|
129
118
|
)
|
|
130
119
|
def read_from_credential_store(
|
|
131
120
|
username: Optional[str] = None,
|