huggingface-hub 0.26.3__py3-none-any.whl → 0.26.5__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.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +1 -1
- huggingface_hub/serialization/_torch.py +35 -11
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.26.5.dist-info}/METADATA +1 -1
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.26.5.dist-info}/RECORD +8 -8
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.26.5.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.26.5.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.26.5.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.26.3.dist-info → huggingface_hub-0.26.5.dist-info}/top_level.txt +0 -0
huggingface_hub/__init__.py
CHANGED
|
@@ -41,6 +41,7 @@ def save_torch_model(
|
|
|
41
41
|
max_shard_size: Union[int, str] = MAX_SHARD_SIZE,
|
|
42
42
|
metadata: Optional[Dict[str, str]] = None,
|
|
43
43
|
safe_serialization: bool = True,
|
|
44
|
+
shared_tensors_to_discard: Optional[List[str]] = None,
|
|
44
45
|
):
|
|
45
46
|
"""
|
|
46
47
|
Saves a given torch model to disk, handling sharding and shared tensors issues.
|
|
@@ -64,6 +65,12 @@ def save_torch_model(
|
|
|
64
65
|
|
|
65
66
|
</Tip>
|
|
66
67
|
|
|
68
|
+
<Tip warning={true}>
|
|
69
|
+
|
|
70
|
+
If your model is a `transformers.PreTrainedModel`, you should pass `model._tied_weights_keys` as `shared_tensors_to_discard` to properly handle shared tensors saving. This ensures the correct duplicate tensors are discarded during saving.
|
|
71
|
+
|
|
72
|
+
</Tip>
|
|
73
|
+
|
|
67
74
|
Args:
|
|
68
75
|
model (`torch.nn.Module`):
|
|
69
76
|
The model to save on disk.
|
|
@@ -88,6 +95,9 @@ def save_torch_model(
|
|
|
88
95
|
Whether to save as safetensors, which is the default behavior. If `False`, the shards are saved as pickle.
|
|
89
96
|
Safe serialization is recommended for security reasons. Saving as pickle is deprecated and will be removed
|
|
90
97
|
in a future version.
|
|
98
|
+
shared_tensors_to_discard (`List[str]`, *optional*):
|
|
99
|
+
List of tensor names to drop when saving shared tensors. If not provided and shared tensors are
|
|
100
|
+
detected, it will drop the first name alphabetically.
|
|
91
101
|
|
|
92
102
|
Example:
|
|
93
103
|
|
|
@@ -112,6 +122,7 @@ def save_torch_model(
|
|
|
112
122
|
metadata=metadata,
|
|
113
123
|
safe_serialization=safe_serialization,
|
|
114
124
|
save_directory=save_directory,
|
|
125
|
+
shared_tensors_to_discard=shared_tensors_to_discard,
|
|
115
126
|
)
|
|
116
127
|
|
|
117
128
|
|
|
@@ -124,6 +135,7 @@ def save_torch_state_dict(
|
|
|
124
135
|
max_shard_size: Union[int, str] = MAX_SHARD_SIZE,
|
|
125
136
|
metadata: Optional[Dict[str, str]] = None,
|
|
126
137
|
safe_serialization: bool = True,
|
|
138
|
+
shared_tensors_to_discard: Optional[List[str]] = None,
|
|
127
139
|
) -> None:
|
|
128
140
|
"""
|
|
129
141
|
Save a model state dictionary to the disk, handling sharding and shared tensors issues.
|
|
@@ -147,6 +159,12 @@ def save_torch_state_dict(
|
|
|
147
159
|
|
|
148
160
|
</Tip>
|
|
149
161
|
|
|
162
|
+
<Tip warning={true}>
|
|
163
|
+
|
|
164
|
+
If your model is a `transformers.PreTrainedModel`, you should pass `model._tied_weights_keys` as `shared_tensors_to_discard` to properly handle shared tensors saving. This ensures the correct duplicate tensors are discarded during saving.
|
|
165
|
+
|
|
166
|
+
</Tip>
|
|
167
|
+
|
|
150
168
|
Args:
|
|
151
169
|
state_dict (`Dict[str, torch.Tensor]`):
|
|
152
170
|
The state dictionary to save.
|
|
@@ -171,6 +189,9 @@ def save_torch_state_dict(
|
|
|
171
189
|
Whether to save as safetensors, which is the default behavior. If `False`, the shards are saved as pickle.
|
|
172
190
|
Safe serialization is recommended for security reasons. Saving as pickle is deprecated and will be removed
|
|
173
191
|
in a future version.
|
|
192
|
+
shared_tensors_to_discard (`List[str]`, *optional*):
|
|
193
|
+
List of tensor names to drop when saving shared tensors. If not provided and shared tensors are
|
|
194
|
+
detected, it will drop the first name alphabetically.
|
|
174
195
|
|
|
175
196
|
Example:
|
|
176
197
|
|
|
@@ -192,7 +213,8 @@ def save_torch_state_dict(
|
|
|
192
213
|
else constants.PYTORCH_WEIGHTS_FILE_PATTERN
|
|
193
214
|
)
|
|
194
215
|
|
|
195
|
-
|
|
216
|
+
if metadata is None:
|
|
217
|
+
metadata = {}
|
|
196
218
|
if safe_serialization:
|
|
197
219
|
try:
|
|
198
220
|
from safetensors.torch import save_file as save_file_fn
|
|
@@ -201,7 +223,13 @@ def save_torch_state_dict(
|
|
|
201
223
|
"Please install `safetensors` to use safe serialization. "
|
|
202
224
|
"You can install it with `pip install safetensors`."
|
|
203
225
|
) from e
|
|
204
|
-
|
|
226
|
+
# Clean state dict for safetensors
|
|
227
|
+
state_dict = _clean_state_dict_for_safetensors(
|
|
228
|
+
state_dict,
|
|
229
|
+
metadata,
|
|
230
|
+
force_contiguous=force_contiguous,
|
|
231
|
+
shared_tensors_to_discard=shared_tensors_to_discard,
|
|
232
|
+
)
|
|
205
233
|
else:
|
|
206
234
|
from torch import save as save_file_fn # type: ignore[assignment]
|
|
207
235
|
|
|
@@ -210,13 +238,6 @@ def save_torch_state_dict(
|
|
|
210
238
|
"pickled models from untrusted sources. If you intend to share your model, we strongly recommend "
|
|
211
239
|
"using safe serialization by installing `safetensors` with `pip install safetensors`."
|
|
212
240
|
)
|
|
213
|
-
|
|
214
|
-
# Clean state dict for safetensors
|
|
215
|
-
if metadata is None:
|
|
216
|
-
metadata = {}
|
|
217
|
-
if safe_serialization:
|
|
218
|
-
state_dict = _clean_state_dict_for_safetensors(state_dict, metadata, force_contiguous=force_contiguous)
|
|
219
|
-
|
|
220
241
|
# Split dict
|
|
221
242
|
state_dict_split = split_torch_state_dict_into_shards(
|
|
222
243
|
state_dict, filename_pattern=filename_pattern, max_shard_size=max_shard_size
|
|
@@ -459,7 +480,10 @@ def storage_ptr(tensor: "torch.Tensor") -> Union[int, Tuple[Any, ...]]:
|
|
|
459
480
|
|
|
460
481
|
|
|
461
482
|
def _clean_state_dict_for_safetensors(
|
|
462
|
-
state_dict: Dict[str, "torch.Tensor"],
|
|
483
|
+
state_dict: Dict[str, "torch.Tensor"],
|
|
484
|
+
metadata: Dict[str, str],
|
|
485
|
+
force_contiguous: bool = True,
|
|
486
|
+
shared_tensors_to_discard: Optional[List[str]] = None,
|
|
463
487
|
):
|
|
464
488
|
"""Remove shared tensors from state_dict and update metadata accordingly (for reloading).
|
|
465
489
|
|
|
@@ -467,7 +491,7 @@ def _clean_state_dict_for_safetensors(
|
|
|
467
491
|
|
|
468
492
|
Taken from https://github.com/huggingface/safetensors/blob/079781fd0dc455ba0fe851e2b4507c33d0c0d407/bindings/python/py_src/safetensors/torch.py#L155.
|
|
469
493
|
"""
|
|
470
|
-
to_removes = _remove_duplicate_names(state_dict)
|
|
494
|
+
to_removes = _remove_duplicate_names(state_dict, discard_names=shared_tensors_to_discard)
|
|
471
495
|
for kept_name, to_remove_group in to_removes.items():
|
|
472
496
|
for to_remove in to_remove_group:
|
|
473
497
|
if metadata is None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: huggingface-hub
|
|
3
|
-
Version: 0.26.
|
|
3
|
+
Version: 0.26.5
|
|
4
4
|
Summary: Client library to download and publish models, datasets and other repos on the huggingface.co hub
|
|
5
5
|
Home-page: https://github.com/huggingface/huggingface_hub
|
|
6
6
|
Author: Hugging Face, Inc.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
huggingface_hub/__init__.py,sha256=
|
|
1
|
+
huggingface_hub/__init__.py,sha256=Wl-Elpop7G1PCVIw6NRG58RnKdQ11i6r-6-Xduk55EI,35993
|
|
2
2
|
huggingface_hub/_commit_api.py,sha256=Y9eTaW4bYzxtrZsSniVtfeAuFafqx8x1ofMI5es8hvM,31057
|
|
3
3
|
huggingface_hub/_commit_scheduler.py,sha256=nlJS_vnLb8i92NLrRwJX8Mg9QZ7f3kfLbLlQuEd5YjU,13647
|
|
4
4
|
huggingface_hub/_inference_endpoints.py,sha256=wzjD8P68VpUDHzIDbXzFXsM2Y-aNVSAap7BXsZFuthk,16750
|
|
@@ -79,7 +79,7 @@ huggingface_hub/inference/_generated/types/zero_shot_object_detection.py,sha256=
|
|
|
79
79
|
huggingface_hub/serialization/__init__.py,sha256=z5MLxMqz0Y2qST-3Lj0PZHUONL-SGRlc0g4Z6MdL6rw,988
|
|
80
80
|
huggingface_hub/serialization/_base.py,sha256=JZneES-HgcRH9C2SQehIGRDtT7nS7emu-RRV4ZjB6xo,8124
|
|
81
81
|
huggingface_hub/serialization/_tensorflow.py,sha256=zHOvEMg-JHC55Fm4roDT3LUCDO5zB9qtXZffG065RAM,3625
|
|
82
|
-
huggingface_hub/serialization/_torch.py,sha256=
|
|
82
|
+
huggingface_hub/serialization/_torch.py,sha256=HbbB_Mzi_gLVMF7kaOxEev1tNFCX79x6gt396RQbqqQ,27876
|
|
83
83
|
huggingface_hub/templates/datasetcard_template.md,sha256=W-EMqR6wndbrnZorkVv56URWPG49l7MATGeI015kTvs,5503
|
|
84
84
|
huggingface_hub/templates/modelcard_template.md,sha256=4AqArS3cqdtbit5Bo-DhjcnDFR-pza5hErLLTPM4Yuc,6870
|
|
85
85
|
huggingface_hub/utils/__init__.py,sha256=aMEsiXGi93z-dXz1W7FFma71tAMeKw0SoKVZSQUeE_4,3525
|
|
@@ -109,9 +109,9 @@ huggingface_hub/utils/insecure_hashlib.py,sha256=OjxlvtSQHpbLp9PWSrXBDJ0wHjxCBU-
|
|
|
109
109
|
huggingface_hub/utils/logging.py,sha256=Cp03s0uEl3kDM9XHQW9a8GAoExODQ-e7kEtgMt-_To8,4728
|
|
110
110
|
huggingface_hub/utils/sha.py,sha256=OFnNGCba0sNcT2gUwaVCJnldxlltrHHe0DS_PCpV3C4,2134
|
|
111
111
|
huggingface_hub/utils/tqdm.py,sha256=jQiVYwRG78HK4_54u0vTtz6Kt9IMGiHy3ixbIn3h2TU,9368
|
|
112
|
-
huggingface_hub-0.26.
|
|
113
|
-
huggingface_hub-0.26.
|
|
114
|
-
huggingface_hub-0.26.
|
|
115
|
-
huggingface_hub-0.26.
|
|
116
|
-
huggingface_hub-0.26.
|
|
117
|
-
huggingface_hub-0.26.
|
|
112
|
+
huggingface_hub-0.26.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
113
|
+
huggingface_hub-0.26.5.dist-info/METADATA,sha256=vwuzPrQU945uSrY4_Q29Jm3e2lvx_EpneRyj2OZELpk,13091
|
|
114
|
+
huggingface_hub-0.26.5.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
115
|
+
huggingface_hub-0.26.5.dist-info/entry_points.txt,sha256=Y3Z2L02rBG7va_iE6RPXolIgwOdwUFONyRN3kXMxZ0g,131
|
|
116
|
+
huggingface_hub-0.26.5.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
|
|
117
|
+
huggingface_hub-0.26.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|