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
renzhc
diffusers_dcu
Commits
a6476822
Unverified
Commit
a6476822
authored
Jan 21, 2025
by
Lucain
Committed by
GitHub
Jan 21, 2025
Browse files
Remove cache migration script (#10619)
parent
a1f9a712
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
74 deletions
+1
-74
src/diffusers/utils/hub_utils.py
src/diffusers/utils/hub_utils.py
+1
-74
No files found.
src/diffusers/utils/hub_utils.py
View file @
a6476822
...
...
@@ -19,7 +19,6 @@ import os
import
re
import
sys
import
tempfile
import
traceback
import
warnings
from
pathlib
import
Path
from
typing
import
Dict
,
List
,
Optional
,
Union
...
...
@@ -35,7 +34,7 @@ from huggingface_hub import (
snapshot_download
,
upload_folder
,
)
from
huggingface_hub.constants
import
HF_HUB_CACHE
,
HF_HUB_DISABLE_TELEMETRY
,
HF_HUB_OFFLINE
from
huggingface_hub.constants
import
HF_HUB_DISABLE_TELEMETRY
,
HF_HUB_OFFLINE
from
huggingface_hub.file_download
import
REGEX_COMMIT_HASH
from
huggingface_hub.utils
import
(
EntryNotFoundError
,
...
...
@@ -197,78 +196,6 @@ def extract_commit_hash(resolved_file: Optional[str], commit_hash: Optional[str]
return
commit_hash
if
REGEX_COMMIT_HASH
.
match
(
commit_hash
)
else
None
# Old default cache path, potentially to be migrated.
# This logic was more or less taken from `transformers`, with the following differences:
# - Diffusers doesn't use custom environment variables to specify the cache path.
# - There is no need to migrate the cache format, just move the files to the new location.
hf_cache_home
=
os
.
path
.
expanduser
(
os
.
getenv
(
"HF_HOME"
,
os
.
path
.
join
(
os
.
getenv
(
"XDG_CACHE_HOME"
,
"~/.cache"
),
"huggingface"
))
)
old_diffusers_cache
=
os
.
path
.
join
(
hf_cache_home
,
"diffusers"
)
def
move_cache
(
old_cache_dir
:
Optional
[
str
]
=
None
,
new_cache_dir
:
Optional
[
str
]
=
None
)
->
None
:
if
new_cache_dir
is
None
:
new_cache_dir
=
HF_HUB_CACHE
if
old_cache_dir
is
None
:
old_cache_dir
=
old_diffusers_cache
old_cache_dir
=
Path
(
old_cache_dir
).
expanduser
()
new_cache_dir
=
Path
(
new_cache_dir
).
expanduser
()
for
old_blob_path
in
old_cache_dir
.
glob
(
"**/blobs/*"
):
if
old_blob_path
.
is_file
()
and
not
old_blob_path
.
is_symlink
():
new_blob_path
=
new_cache_dir
/
old_blob_path
.
relative_to
(
old_cache_dir
)
new_blob_path
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
os
.
replace
(
old_blob_path
,
new_blob_path
)
try
:
os
.
symlink
(
new_blob_path
,
old_blob_path
)
except
OSError
:
logger
.
warning
(
"Could not create symlink between old cache and new cache. If you use an older version of diffusers again, files will be re-downloaded."
)
# At this point, old_cache_dir contains symlinks to the new cache (it can still be used).
cache_version_file
=
os
.
path
.
join
(
HF_HUB_CACHE
,
"version_diffusers_cache.txt"
)
if
not
os
.
path
.
isfile
(
cache_version_file
):
cache_version
=
0
else
:
with
open
(
cache_version_file
)
as
f
:
try
:
cache_version
=
int
(
f
.
read
())
except
ValueError
:
cache_version
=
0
if
cache_version
<
1
:
old_cache_is_not_empty
=
os
.
path
.
isdir
(
old_diffusers_cache
)
and
len
(
os
.
listdir
(
old_diffusers_cache
))
>
0
if
old_cache_is_not_empty
:
logger
.
warning
(
"The cache for model files in Diffusers v0.14.0 has moved to a new location. Moving your "
"existing cached models. This is a one-time operation, you can interrupt it or run it "
"later by calling `diffusers.utils.hub_utils.move_cache()`."
)
try
:
move_cache
()
except
Exception
as
e
:
trace
=
"
\n
"
.
join
(
traceback
.
format_tb
(
e
.
__traceback__
))
logger
.
error
(
f
"There was a problem when trying to move your cache:
\n\n
{
trace
}
\n
{
e
.
__class__
.
__name__
}
:
{
e
}
\n\n
Please "
"file an issue at https://github.com/huggingface/diffusers/issues/new/choose, copy paste this whole "
"message and we will do our best to help."
)
if
cache_version
<
1
:
try
:
os
.
makedirs
(
HF_HUB_CACHE
,
exist_ok
=
True
)
with
open
(
cache_version_file
,
"w"
)
as
f
:
f
.
write
(
"1"
)
except
Exception
:
logger
.
warning
(
f
"There was a problem when trying to write in your cache folder (
{
HF_HUB_CACHE
}
). Please, ensure "
"the directory exists and can be written to."
)
def
_add_variant
(
weights_name
:
str
,
variant
:
Optional
[
str
]
=
None
)
->
str
:
if
variant
is
not
None
:
splits
=
weights_name
.
split
(
"."
)
...
...
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