Skip to content

Commit 69920ef

Browse files
committed
feat: model_info but local.
1 parent 8d431dc commit 69920ef

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/diffusers/utils/hub_utils.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,21 @@ def _get_checkpoint_shard_files(
404404

405405
ignore_patterns = ["*.json", "*.md"]
406406
# `model_info` call must guarded with the above condition.
407-
model_files_info = model_info(pretrained_model_name_or_path, revision=revision, token=token)
407+
local = False
408+
try:
409+
model_files_info = model_info(pretrained_model_name_or_path, revision=revision, token=token)
410+
except HTTPError:
411+
if local_files_only:
412+
temp_dir = snapshot_download(
413+
repo_id=pretrained_model_name_or_path, cache_dir=cache_dir, local_files_only=local_files_only
414+
)
415+
model_files_info = _get_filepaths_for_folder(temp_dir)
416+
local = True
408417
for shard_file in original_shard_filenames:
409-
shard_file_present = any(shard_file in k.rfilename for k in model_files_info.siblings)
418+
if local:
419+
shard_file_present = any(shard_file in k for k in model_files_info)
420+
else:
421+
shard_file_present = any(shard_file in k.rfilename for k in model_files_info.siblings)
410422
if not shard_file_present:
411423
raise EnvironmentError(
412424
f"{shards_path} does not appear to have a file named {shard_file} which is "
@@ -442,6 +454,16 @@ def _get_checkpoint_shard_files(
442454
return cached_filenames, sharded_metadata
443455

444456

457+
def _get_filepaths_for_folder(folder):
458+
relative_paths = []
459+
for root, dirs, files in os.walk(folder):
460+
for fname in files:
461+
abs_path = os.path.join(root, fname)
462+
rel_path = os.path.relpath(abs_path, start=folder)
463+
relative_paths.append(rel_path)
464+
return relative_paths
465+
466+
445467
def _check_legacy_sharding_variant_format(folder: str = None, filenames: List[str] = None, variant: str = None):
446468
if filenames and folder:
447469
raise ValueError("Both `filenames` and `folder` cannot be provided.")

0 commit comments

Comments
 (0)