Skip to content

Commit afd101f

Browse files
authored
Merge pull request #1058 from modelscope/download
support downloading resource
2 parents 8332ece + 1313f4d commit afd101f

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

diffsynth/utils/__init__.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from einops import repeat, reduce
55
from typing import Optional, Union
66
from dataclasses import dataclass
7+
from huggingface_hub import snapshot_download as hf_snapshot_download
78
from modelscope import snapshot_download
89
import numpy as np
910
from PIL import Image
@@ -196,13 +197,24 @@ def download_if_necessary(self, use_usp=False):
196197
self.local_model_path = "./models"
197198
if not skip_download:
198199
downloaded_files = glob.glob(self.origin_file_pattern, root_dir=os.path.join(self.local_model_path, self.model_id))
199-
snapshot_download(
200-
self.model_id,
201-
local_dir=os.path.join(self.local_model_path, self.model_id),
202-
allow_file_pattern=allow_file_pattern,
203-
ignore_file_pattern=downloaded_files,
204-
local_files_only=False
205-
)
200+
if self.download_resource.lower() == "modelscope":
201+
snapshot_download(
202+
self.model_id,
203+
local_dir=os.path.join(self.local_model_path, self.model_id),
204+
allow_file_pattern=allow_file_pattern,
205+
ignore_file_pattern=downloaded_files,
206+
local_files_only=False
207+
)
208+
elif self.download_resource.lower() == "huggingface":
209+
hf_snapshot_download(
210+
self.model_id,
211+
local_dir=os.path.join(self.local_model_path, self.model_id),
212+
allow_patterns=allow_file_pattern,
213+
ignore_patterns=downloaded_files,
214+
local_files_only=False
215+
)
216+
else:
217+
raise ValueError("`download_resource` should be `modelscope` or `huggingface`.")
206218

207219
# Let rank 1, 2, ... wait for rank 0
208220
if use_usp:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
setup(
1616
name="diffsynth",
17-
version="1.1.8",
17+
version="1.1.9",
1818
description="Enjoy the magic of Diffusion models!",
1919
author="Artiprocher",
2020
packages=find_packages(),

0 commit comments

Comments
 (0)