huggingface-hub 0.13.1__py3-none-any.whl → 0.13.3__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/file_download.py +55 -34
- huggingface_hub/repocard.py +8 -6
- {huggingface_hub-0.13.1.dist-info → huggingface_hub-0.13.3.dist-info}/METADATA +1 -1
- {huggingface_hub-0.13.1.dist-info → huggingface_hub-0.13.3.dist-info}/RECORD +9 -9
- {huggingface_hub-0.13.1.dist-info → huggingface_hub-0.13.3.dist-info}/WHEEL +1 -1
- {huggingface_hub-0.13.1.dist-info → huggingface_hub-0.13.3.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.13.1.dist-info → huggingface_hub-0.13.3.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.13.1.dist-info → huggingface_hub-0.13.3.dist-info}/top_level.txt +0 -0
huggingface_hub/__init__.py
CHANGED
huggingface_hub/file_download.py
CHANGED
|
@@ -103,7 +103,7 @@ def are_symlinks_supported(cache_dir: Union[str, Path, None] = None) -> bool:
|
|
|
103
103
|
src_path.touch()
|
|
104
104
|
dst_path = Path(tmpdir) / "dummy_file_dst"
|
|
105
105
|
|
|
106
|
-
# Relative source path as in `
|
|
106
|
+
# Relative source path as in `_create_symlink``
|
|
107
107
|
relative_src = os.path.relpath(src_path, start=os.path.dirname(dst_path))
|
|
108
108
|
try:
|
|
109
109
|
os.symlink(relative_src, dst_path)
|
|
@@ -558,7 +558,7 @@ def cached_download(
|
|
|
558
558
|
token: Union[bool, str, None] = None,
|
|
559
559
|
local_files_only: bool = False,
|
|
560
560
|
legacy_cache_layout: bool = False,
|
|
561
|
-
) ->
|
|
561
|
+
) -> str:
|
|
562
562
|
"""
|
|
563
563
|
Download from a given URL and cache it if it's not already present in the
|
|
564
564
|
local cache.
|
|
@@ -820,60 +820,81 @@ def _normalize_etag(etag: Optional[str]) -> Optional[str]:
|
|
|
820
820
|
|
|
821
821
|
|
|
822
822
|
def _create_relative_symlink(src: str, dst: str, new_blob: bool = False) -> None:
|
|
823
|
-
"""
|
|
823
|
+
"""Alias method used in `transformers` conversion script."""
|
|
824
|
+
return _create_symlink(src=src, dst=dst, new_blob=new_blob)
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
def _create_symlink(src: str, dst: str, new_blob: bool = False) -> None:
|
|
828
|
+
"""Create a symbolic link named dst pointing to src.
|
|
829
|
+
|
|
830
|
+
By default, it will try to create a symlink using a relative path. Relative paths have 2 advantages:
|
|
831
|
+
- If the cache_folder is moved (example: back-up on a shared drive), relative paths within the cache folder will
|
|
832
|
+
not brake.
|
|
833
|
+
- Relative paths seems to be better handled on Windows. Issue was reported 3 times in less than a week when
|
|
834
|
+
changing from relative to absolute paths. See https://github.com/huggingface/huggingface_hub/issues/1398,
|
|
835
|
+
https://github.com/huggingface/diffusers/issues/2729 and https://github.com/huggingface/transformers/pull/22228.
|
|
836
|
+
NOTE: The issue with absolute paths doesn't happen on admin mode.
|
|
837
|
+
When creating a symlink from the cache to a local folder, it is possible that a relative path cannot be created.
|
|
838
|
+
This happens when paths are not on the same volume. In that case, we use absolute paths.
|
|
824
839
|
|
|
825
|
-
The relative part is mostly because it seems more elegant to the author.
|
|
826
840
|
|
|
827
841
|
The result layout looks something like
|
|
828
842
|
└── [ 128] snapshots
|
|
829
843
|
├── [ 128] 2439f60ef33a0d46d85da5001d52aeda5b00ce9f
|
|
830
|
-
│ ├── [ 52] README.md ->
|
|
831
|
-
│ └── [ 76] pytorch_model.bin ->
|
|
844
|
+
│ ├── [ 52] README.md -> ../../../blobs/d7edf6bd2a681fb0175f7735299831ee1b22b812
|
|
845
|
+
│ └── [ 76] pytorch_model.bin -> ../../../blobs/403450e234d65943a7dcf7e05a771ce3c92faa84dd07db4ac20f592037a1e4bd
|
|
832
846
|
|
|
833
|
-
If symlinks cannot be created on this platform (most likely to be Windows), the
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
To avoid breaking existing cache, the file is duplicated on the disk.
|
|
847
|
+
If symlinks cannot be created on this platform (most likely to be Windows), the workaround is to avoid symlinks by
|
|
848
|
+
having the actual file in `dst`. If it is a new file (`new_blob=True`), we move it to `dst`. If it is not a new file
|
|
849
|
+
(`new_blob=False`), we don't know if the blob file is already referenced elsewhere. To avoid breaking existing
|
|
850
|
+
cache, the file is duplicated on the disk.
|
|
838
851
|
|
|
839
|
-
In case symlinks are not supported, a warning message is displayed to the user once
|
|
840
|
-
|
|
841
|
-
`DISABLE_SYMLINKS_WARNING` environment variable.
|
|
852
|
+
In case symlinks are not supported, a warning message is displayed to the user once when loading `huggingface_hub`.
|
|
853
|
+
The warning message can be disable with the `DISABLE_SYMLINKS_WARNING` environment variable.
|
|
842
854
|
"""
|
|
843
855
|
try:
|
|
844
856
|
os.remove(dst)
|
|
845
857
|
except OSError:
|
|
846
858
|
pass
|
|
847
859
|
|
|
860
|
+
abs_src = os.path.abspath(os.path.expanduser(src))
|
|
861
|
+
abs_dst = os.path.abspath(os.path.expanduser(dst))
|
|
862
|
+
|
|
863
|
+
# Use relative_dst in priority
|
|
848
864
|
try:
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
865
|
+
relative_src = os.path.relpath(abs_src, os.path.dirname(abs_dst))
|
|
866
|
+
except ValueError:
|
|
867
|
+
# Raised on Windows if src and dst are not on the same volume. This is the case when creating a symlink to a
|
|
868
|
+
# local_dir instead of within the cache directory.
|
|
869
|
+
# See https://docs.python.org/3/library/os.path.html#os.path.relpath
|
|
870
|
+
relative_src = None
|
|
871
|
+
|
|
872
|
+
try:
|
|
873
|
+
_support_symlinks = are_symlinks_supported(os.path.dirname(os.path.commonpath([abs_src, abs_dst])))
|
|
852
874
|
except PermissionError:
|
|
853
875
|
# Permission error means src and dst are not in the same volume (e.g. destination path has been provided
|
|
854
876
|
# by the user via `local_dir`. Let's test symlink support there)
|
|
855
|
-
_support_symlinks = are_symlinks_supported(os.path.dirname(
|
|
877
|
+
_support_symlinks = are_symlinks_supported(os.path.dirname(abs_dst))
|
|
856
878
|
|
|
857
879
|
if _support_symlinks:
|
|
858
|
-
|
|
880
|
+
src_rel_or_abs = relative_src or abs_src
|
|
881
|
+
logger.info(f"Creating pointer from {src_rel_or_abs} to {abs_dst}")
|
|
859
882
|
try:
|
|
860
|
-
os.symlink(
|
|
883
|
+
os.symlink(src_rel_or_abs, abs_dst)
|
|
861
884
|
except FileExistsError:
|
|
862
|
-
if os.path.islink(
|
|
863
|
-
# `
|
|
864
|
-
#
|
|
865
|
-
# between `os.remove` and `os.symlink`). Do nothing.
|
|
885
|
+
if os.path.islink(abs_dst) and os.path.realpath(abs_dst) == os.path.realpath(abs_src):
|
|
886
|
+
# `abs_dst` already exists and is a symlink to the `abs_src` blob. It is most likely that the file has
|
|
887
|
+
# been cached twice concurrently (exactly between `os.remove` and `os.symlink`). Do nothing.
|
|
866
888
|
pass
|
|
867
889
|
else:
|
|
868
|
-
# Very unlikely to happen. Means a file `dst` has been created exactly
|
|
869
|
-
#
|
|
870
|
-
# blob file. Raise exception.
|
|
890
|
+
# Very unlikely to happen. Means a file `dst` has been created exactly between `os.remove` and
|
|
891
|
+
# `os.symlink` and is not a symlink to the `abs_src` blob file. Raise exception.
|
|
871
892
|
raise
|
|
872
893
|
elif new_blob:
|
|
873
|
-
logger.info(f"Symlink not supported. Moving file from {
|
|
894
|
+
logger.info(f"Symlink not supported. Moving file from {abs_src} to {abs_dst}")
|
|
874
895
|
os.replace(src, dst)
|
|
875
896
|
else:
|
|
876
|
-
logger.info(f"Symlink not supported. Copying file from {
|
|
897
|
+
logger.info(f"Symlink not supported. Copying file from {abs_src} to {abs_dst}")
|
|
877
898
|
shutil.copyfile(src, dst)
|
|
878
899
|
|
|
879
900
|
|
|
@@ -926,7 +947,7 @@ def hf_hub_download(
|
|
|
926
947
|
token: Union[bool, str, None] = None,
|
|
927
948
|
local_files_only: bool = False,
|
|
928
949
|
legacy_cache_layout: bool = False,
|
|
929
|
-
):
|
|
950
|
+
) -> str:
|
|
930
951
|
"""Download a given file if it's not already present in the local cache.
|
|
931
952
|
|
|
932
953
|
The new cache file layout looks like this:
|
|
@@ -1258,7 +1279,7 @@ def hf_hub_download(
|
|
|
1258
1279
|
if local_dir is not None: # to local dir
|
|
1259
1280
|
return _to_local_dir(blob_path, local_dir, relative_filename, use_symlinks=local_dir_use_symlinks)
|
|
1260
1281
|
else: # or in snapshot cache
|
|
1261
|
-
|
|
1282
|
+
_create_symlink(blob_path, pointer_path, new_blob=False)
|
|
1262
1283
|
return pointer_path
|
|
1263
1284
|
|
|
1264
1285
|
# Prevent parallel downloads of the same file with a lock.
|
|
@@ -1313,7 +1334,7 @@ def hf_hub_download(
|
|
|
1313
1334
|
if local_dir is None:
|
|
1314
1335
|
logger.info(f"Storing {url} in cache at {blob_path}")
|
|
1315
1336
|
_chmod_and_replace(temp_file.name, blob_path)
|
|
1316
|
-
|
|
1337
|
+
_create_symlink(blob_path, pointer_path, new_blob=True)
|
|
1317
1338
|
else:
|
|
1318
1339
|
local_dir_filepath = os.path.join(local_dir, relative_filename)
|
|
1319
1340
|
os.makedirs(os.path.dirname(local_dir_filepath), exist_ok=True)
|
|
@@ -1325,7 +1346,7 @@ def hf_hub_download(
|
|
|
1325
1346
|
logger.info(f"Storing {url} in cache at {blob_path}")
|
|
1326
1347
|
_chmod_and_replace(temp_file.name, blob_path)
|
|
1327
1348
|
logger.info("Create symlink to local dir")
|
|
1328
|
-
|
|
1349
|
+
_create_symlink(blob_path, local_dir_filepath, new_blob=False)
|
|
1329
1350
|
elif local_dir_use_symlinks == "auto" and not is_big_file:
|
|
1330
1351
|
logger.info(f"Storing {url} in cache at {blob_path}")
|
|
1331
1352
|
_chmod_and_replace(temp_file.name, blob_path)
|
|
@@ -1544,7 +1565,7 @@ def _to_local_dir(
|
|
|
1544
1565
|
use_symlinks = os.stat(real_blob_path).st_size > constants.HF_HUB_LOCAL_DIR_AUTO_SYMLINK_THRESHOLD
|
|
1545
1566
|
|
|
1546
1567
|
if use_symlinks:
|
|
1547
|
-
|
|
1568
|
+
_create_symlink(real_blob_path, local_dir_filepath, new_blob=False)
|
|
1548
1569
|
else:
|
|
1549
1570
|
shutil.copyfile(real_blob_path, local_dir_filepath)
|
|
1550
1571
|
return local_dir_filepath
|
huggingface_hub/repocard.py
CHANGED
|
@@ -170,17 +170,19 @@ class RepoCard:
|
|
|
170
170
|
if Path(repo_id_or_path).exists():
|
|
171
171
|
card_path = Path(repo_id_or_path)
|
|
172
172
|
elif isinstance(repo_id_or_path, str):
|
|
173
|
-
card_path =
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
173
|
+
card_path = Path(
|
|
174
|
+
hf_hub_download(
|
|
175
|
+
repo_id_or_path,
|
|
176
|
+
REPOCARD_NAME,
|
|
177
|
+
repo_type=repo_type or cls.repo_type,
|
|
178
|
+
token=token,
|
|
179
|
+
)
|
|
178
180
|
)
|
|
179
181
|
else:
|
|
180
182
|
raise ValueError(f"Cannot load RepoCard: path not found on disk ({repo_id_or_path}).")
|
|
181
183
|
|
|
182
184
|
# Preserve newlines in the existing file.
|
|
183
|
-
with
|
|
185
|
+
with card_path.open(mode="r", newline="", encoding="utf-8") as f:
|
|
184
186
|
return cls(f.read(), ignore_metadata_errors=ignore_metadata_errors)
|
|
185
187
|
|
|
186
188
|
def validate(self, repo_type: Optional[str] = None):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: huggingface-hub
|
|
3
|
-
Version: 0.13.
|
|
3
|
+
Version: 0.13.3
|
|
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=8PDH0M8_c2CwqboAvkN8wrnOiMWUNZxfEqclxK4aLfQ,14645
|
|
2
2
|
huggingface_hub/_commit_api.py,sha256=QP3YtZdMOFKW0EchiS9JGPo5EVlkUz6cGktCagvoOx0,22558
|
|
3
3
|
huggingface_hub/_login.py,sha256=iKK6-4tDBcdCoJar_TXILUdJ76G00QYbgFVM5Dtput8,11531
|
|
4
4
|
huggingface_hub/_snapshot_download.py,sha256=eY0OWOpunWJY32d1d30ggV3rr3ND_LpEnYmu87nzZcY,11339
|
|
@@ -6,13 +6,13 @@ huggingface_hub/_space_api.py,sha256=URSt8IDDnzZ4wiGiuoZgwNP3ZMgNmXZQGFcOQhfkQEU
|
|
|
6
6
|
huggingface_hub/community.py,sha256=WwVSOtephAX0OqALlOW_1EPu09r-Y5WpIF7jPkn0ze8,11062
|
|
7
7
|
huggingface_hub/constants.py,sha256=EIhFt9LSDZKnstgJ3Zwqu2coHBHg8ms7dXNPE6QkFU8,4714
|
|
8
8
|
huggingface_hub/fastai_utils.py,sha256=5I7zAfgHJU_mZnxnf9wgWTHrCRu_EAV8VTangDVfE_o,16676
|
|
9
|
-
huggingface_hub/file_download.py,sha256=
|
|
9
|
+
huggingface_hub/file_download.py,sha256=2KBueqiPJ2MGuuvCIkH2yOEhfAwODnpWERrKpRhIgic,65133
|
|
10
10
|
huggingface_hub/hf_api.py,sha256=Zh_iIV_Qhk79nbKaXigtcanCeGVfIpqdkqU9yYhaH3M,173043
|
|
11
11
|
huggingface_hub/hub_mixin.py,sha256=94BN_vzHDBX2tDgVV8la4CfkUzN2OgLsV9p9sz4OP7c,16783
|
|
12
12
|
huggingface_hub/inference_api.py,sha256=3NkHAAGS9wK8PbXxly8YI-0V6gfZgZvV3N5bTdRfvDM,7882
|
|
13
13
|
huggingface_hub/keras_mixin.py,sha256=cvLoaf2GNpeYOyDEQrZnSkYxeYPoDjgrxCr8BRWHPcA,18797
|
|
14
14
|
huggingface_hub/lfs.py,sha256=Ij-QF8sWjVtL2XwWw4SaLIlsEP8sL2hdr7efFoonrEU,16007
|
|
15
|
-
huggingface_hub/repocard.py,sha256=
|
|
15
|
+
huggingface_hub/repocard.py,sha256=TV0V6UxCCRlJ0Yvr9p2KA8dGUFlTgzSObczNqkNIItw,34219
|
|
16
16
|
huggingface_hub/repocard_data.py,sha256=xpLC_PNIEIArNu4EVMBOXtC8VPnpXRQLHyXAlvUMVss,29768
|
|
17
17
|
huggingface_hub/repository.py,sha256=arXVSuom8jTJxbia_fm2HAvWeEVnowK5cHajcO6n_vQ,53727
|
|
18
18
|
huggingface_hub/commands/__init__.py,sha256=AkbM2a-iGh0Vq_xAWhK3mu3uZ44km8-X5uWjKcvcrUQ,928
|
|
@@ -48,9 +48,9 @@ huggingface_hub/utils/endpoint_helpers.py,sha256=wXE3U1resSFvfdZbNevzrFyf39o9LfE
|
|
|
48
48
|
huggingface_hub/utils/logging.py,sha256=-Uov2WGLv16hS-V4Trvs_XO-TvSeZ1xIWZ-cfvDl7ac,4778
|
|
49
49
|
huggingface_hub/utils/sha.py,sha256=Wmeh2lwS2H0_CNLqDk_mNyb4jAjfTdlG6FZsuh6LqVg,890
|
|
50
50
|
huggingface_hub/utils/tqdm.py,sha256=iTe9IhbPWIezSn6GBAuPlZe_q-5T47ARwUJAQZ6xepc,5741
|
|
51
|
-
huggingface_hub-0.13.
|
|
52
|
-
huggingface_hub-0.13.
|
|
53
|
-
huggingface_hub-0.13.
|
|
54
|
-
huggingface_hub-0.13.
|
|
55
|
-
huggingface_hub-0.13.
|
|
56
|
-
huggingface_hub-0.13.
|
|
51
|
+
huggingface_hub-0.13.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
52
|
+
huggingface_hub-0.13.3.dist-info/METADATA,sha256=nt-YabDZxogsoN7HxTX4nyVt0TXB6cPAYTVZb7eZJKI,7476
|
|
53
|
+
huggingface_hub-0.13.3.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
|
54
|
+
huggingface_hub-0.13.3.dist-info/entry_points.txt,sha256=7-_O79Kk26OM9R3QgywVzfyrNjZ3F8tCUhDtozJ7yIc,83
|
|
55
|
+
huggingface_hub-0.13.3.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
|
|
56
|
+
huggingface_hub-0.13.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|