Skip to content

Commit a647682

Browse files
authored
Remove cache migration script (#10619)
1 parent a1f9a71 commit a647682

File tree

1 file changed

+1
-74
lines changed

1 file changed

+1
-74
lines changed

src/diffusers/utils/hub_utils.py

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import re
2020
import sys
2121
import tempfile
22-
import traceback
2322
import warnings
2423
from pathlib import Path
2524
from typing import Dict, List, Optional, Union
@@ -35,7 +34,7 @@
3534
snapshot_download,
3635
upload_folder,
3736
)
38-
from huggingface_hub.constants import HF_HUB_CACHE, HF_HUB_DISABLE_TELEMETRY, HF_HUB_OFFLINE
37+
from huggingface_hub.constants import HF_HUB_DISABLE_TELEMETRY, HF_HUB_OFFLINE
3938
from huggingface_hub.file_download import REGEX_COMMIT_HASH
4039
from huggingface_hub.utils import (
4140
EntryNotFoundError,
@@ -197,78 +196,6 @@ def extract_commit_hash(resolved_file: Optional[str], commit_hash: Optional[str]
197196
return commit_hash if REGEX_COMMIT_HASH.match(commit_hash) else None
198197

199198

200-
# Old default cache path, potentially to be migrated.
201-
# This logic was more or less taken from `transformers`, with the following differences:
202-
# - Diffusers doesn't use custom environment variables to specify the cache path.
203-
# - There is no need to migrate the cache format, just move the files to the new location.
204-
hf_cache_home = os.path.expanduser(
205-
os.getenv("HF_HOME", os.path.join(os.getenv("XDG_CACHE_HOME", "~/.cache"), "huggingface"))
206-
)
207-
old_diffusers_cache = os.path.join(hf_cache_home, "diffusers")
208-
209-
210-
def move_cache(old_cache_dir: Optional[str] = None, new_cache_dir: Optional[str] = None) -> None:
211-
if new_cache_dir is None:
212-
new_cache_dir = HF_HUB_CACHE
213-
if old_cache_dir is None:
214-
old_cache_dir = old_diffusers_cache
215-
216-
old_cache_dir = Path(old_cache_dir).expanduser()
217-
new_cache_dir = Path(new_cache_dir).expanduser()
218-
for old_blob_path in old_cache_dir.glob("**/blobs/*"):
219-
if old_blob_path.is_file() and not old_blob_path.is_symlink():
220-
new_blob_path = new_cache_dir / old_blob_path.relative_to(old_cache_dir)
221-
new_blob_path.parent.mkdir(parents=True, exist_ok=True)
222-
os.replace(old_blob_path, new_blob_path)
223-
try:
224-
os.symlink(new_blob_path, old_blob_path)
225-
except OSError:
226-
logger.warning(
227-
"Could not create symlink between old cache and new cache. If you use an older version of diffusers again, files will be re-downloaded."
228-
)
229-
# At this point, old_cache_dir contains symlinks to the new cache (it can still be used).
230-
231-
232-
cache_version_file = os.path.join(HF_HUB_CACHE, "version_diffusers_cache.txt")
233-
if not os.path.isfile(cache_version_file):
234-
cache_version = 0
235-
else:
236-
with open(cache_version_file) as f:
237-
try:
238-
cache_version = int(f.read())
239-
except ValueError:
240-
cache_version = 0
241-
242-
if cache_version < 1:
243-
old_cache_is_not_empty = os.path.isdir(old_diffusers_cache) and len(os.listdir(old_diffusers_cache)) > 0
244-
if old_cache_is_not_empty:
245-
logger.warning(
246-
"The cache for model files in Diffusers v0.14.0 has moved to a new location. Moving your "
247-
"existing cached models. This is a one-time operation, you can interrupt it or run it "
248-
"later by calling `diffusers.utils.hub_utils.move_cache()`."
249-
)
250-
try:
251-
move_cache()
252-
except Exception as e:
253-
trace = "\n".join(traceback.format_tb(e.__traceback__))
254-
logger.error(
255-
f"There was a problem when trying to move your cache:\n\n{trace}\n{e.__class__.__name__}: {e}\n\nPlease "
256-
"file an issue at https://github.com/huggingface/diffusers/issues/new/choose, copy paste this whole "
257-
"message and we will do our best to help."
258-
)
259-
260-
if cache_version < 1:
261-
try:
262-
os.makedirs(HF_HUB_CACHE, exist_ok=True)
263-
with open(cache_version_file, "w") as f:
264-
f.write("1")
265-
except Exception:
266-
logger.warning(
267-
f"There was a problem when trying to write in your cache folder ({HF_HUB_CACHE}). Please, ensure "
268-
"the directory exists and can be written to."
269-
)
270-
271-
272199
def _add_variant(weights_name: str, variant: Optional[str] = None) -> str:
273200
if variant is not None:
274201
splits = weights_name.split(".")

0 commit comments

Comments
 (0)