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
47e16762
Unverified
Commit
47e16762
authored
Aug 08, 2022
by
Sylvain Gugger
Committed by
GitHub
Aug 08, 2022
Browse files
New cache fixes: add safeguard before looking in folders (#18522)
parent
74959240
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
0 deletions
+7
-0
src/transformers/utils/hub.py
src/transformers/utils/hub.py
+7
-0
No files found.
src/transformers/utils/hub.py
View file @
47e16762
...
...
@@ -133,6 +133,8 @@ def get_cached_models(cache_dir: Union[str, Path] = None) -> List[Tuple]:
cache_dir
=
TRANSFORMERS_CACHE
elif
isinstance
(
cache_dir
,
Path
):
cache_dir
=
str
(
cache_dir
)
if
not
os
.
path
.
isdir
(
cache_dir
):
return
[]
cached_models
=
[]
for
file
in
os
.
listdir
(
cache_dir
):
...
...
@@ -210,6 +212,9 @@ def try_to_load_from_cache(cache_dir, repo_id, filename, revision=None):
if
not
os
.
path
.
isdir
(
model_cache
):
# No cache for this model
return
None
for
subfolder
in
[
"refs"
,
"snapshots"
]:
if
not
os
.
path
.
isdir
(
os
.
path
.
join
(
model_cache
,
subfolder
)):
return
None
# Resolve refs (for instance to convert main to the associated commit sha)
cached_refs
=
os
.
listdir
(
os
.
path
.
join
(
model_cache
,
"refs"
))
...
...
@@ -873,6 +878,8 @@ def get_all_cached_files(cache_dir=None):
cache_dir
=
TRANSFORMERS_CACHE
else
:
cache_dir
=
str
(
cache_dir
)
if
not
os
.
path
.
isdir
(
cache_dir
):
return
[]
cached_files
=
[]
for
file
in
os
.
listdir
(
cache_dir
):
...
...
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