Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
298f6a98
Unverified
Commit
298f6a98
authored
Oct 10, 2022
by
Lysandre Debut
Committed by
GitHub
Oct 10, 2022
Browse files
Stop relying on huggingface_hub's private methods (#19392)
* Leverage hfh for move cache * Style
parent
7d5ce680
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
23 deletions
+3
-23
src/transformers/utils/hub.py
src/transformers/utils/hub.py
+3
-23
No files found.
src/transformers/utils/hub.py
View file @
298f6a98
...
...
@@ -34,11 +34,11 @@ from huggingface_hub import (
HfFolder
,
create_commit
,
create_repo
,
get_hf_file_metadata
,
hf_hub_download
,
hf_hub_url
,
whoami
,
)
from
huggingface_hub.constants
import
HUGGINGFACE_HEADER_X_LINKED_ETAG
,
HUGGINGFACE_HEADER_X_REPO_COMMIT
from
huggingface_hub.file_download
import
REGEX_COMMIT_HASH
,
http_get
from
huggingface_hub.utils
import
(
EntryNotFoundError
,
...
...
@@ -982,26 +982,6 @@ def get_all_cached_files(cache_dir=None):
return
cached_files
def
get_hub_metadata
(
url
,
token
=
None
):
"""
Returns the commit hash and associated etag for a given url.
"""
if
token
is
None
:
token
=
HfFolder
.
get_token
()
headers
=
{
"user-agent"
:
http_user_agent
()}
headers
[
"authorization"
]
=
f
"Bearer
{
token
}
"
r
=
huggingface_hub
.
file_download
.
_request_with_retry
(
method
=
"HEAD"
,
url
=
url
,
headers
=
headers
,
allow_redirects
=
False
)
hf_raise_for_status
(
r
)
commit_hash
=
r
.
headers
.
get
(
HUGGINGFACE_HEADER_X_REPO_COMMIT
)
etag
=
r
.
headers
.
get
(
HUGGINGFACE_HEADER_X_LINKED_ETAG
)
or
r
.
headers
.
get
(
"ETag"
)
if
etag
is
not
None
:
etag
=
huggingface_hub
.
file_download
.
_normalize_etag
(
etag
)
return
etag
,
commit_hash
def
extract_info_from_url
(
url
):
"""
Extract repo_name, revision and filename from an url.
...
...
@@ -1069,11 +1049,11 @@ def move_cache(cache_dir=None, new_cache_dir=None, token=None):
url
=
file_info
.
pop
(
"url"
)
if
url
not
in
hub_metadata
:
try
:
hub_metadata
[
url
]
=
get_h
ub
_metadata
(
url
,
token
=
token
)
hub_metadata
[
url
]
=
get_h
f_file
_metadata
(
url
,
use_auth_
token
=
token
)
except
requests
.
HTTPError
:
continue
etag
,
commit_hash
=
hub_metadata
[
url
]
etag
,
commit_hash
=
hub_metadata
[
url
]
.
etag
,
hub_metadata
[
url
].
commit_hash
if
etag
is
None
or
commit_hash
is
None
:
continue
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment