Skip to content

Commit 39cc5c5

Browse files
ADD Option: OFFLINE fetch modelscope model (#172)
* ADD option: fetch modelscope model OFFLINE * format * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent ccf97d8 commit 39cc5c5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

diffsynth_engine/utils/download.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from modelscope.hub.api import HubApi
1313
from diffsynth_engine.utils import logging
1414
from diffsynth_engine.utils.lock import HeartbeatFileLock
15-
from diffsynth_engine.utils.env import DIFFSYNTH_FILELOCK_DIR, DIFFSYNTH_CACHE
15+
from diffsynth_engine.utils.env import DIFFSYNTH_FILELOCK_DIR, DIFFSYNTH_CACHE, MS_HUB_OFFLINE
1616
from diffsynth_engine.utils.constants import MB
1717

1818
logger = logging.get_logger(__name__)
@@ -81,7 +81,13 @@ def fetch_modelscope_model(
8181
api.login(access_token)
8282
with HeartbeatFileLock(lock_file_path):
8383
directory = os.path.join(DIFFSYNTH_CACHE, "modelscope", model_id, revision if revision else "__version")
84-
dirpath = snapshot_download(model_id, revision=revision, local_dir=directory, allow_patterns=path)
84+
dirpath = snapshot_download(
85+
model_id,
86+
revision=revision,
87+
local_dir=directory,
88+
allow_patterns=path,
89+
local_files_only=MS_HUB_OFFLINE
90+
)
8591

8692
if isinstance(path, str):
8793
path = glob.glob(os.path.join(dirpath, path))

diffsynth_engine/utils/env.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
DIFFSYNTH_FILELOCK_DIR = os.environ.get(
99
"DIFFSYNTH_FILELOCK_DIR", os.path.join(HOME, ".cache", "diffsynth", "filelocks")
1010
)
11+
12+
MS_HUB_OFFLINE = os.getenv("MS_HUB_OFFLINE", "0").lower() in ("1", "true", "yes")

0 commit comments

Comments
 (0)