Skip to content

Commit 8d7566b

Browse files
committed
corrects single file path validation logic
1 parent f2be8bd commit 8d7566b

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/diffusers/loaders/single_file_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,10 @@ def is_valid_url(url):
409409

410410

411411
def _is_single_file_path_or_url(pretrained_model_name_or_path):
412-
if not os.path.isfile(pretrained_model_name_or_path) or not is_valid_url(pretrained_model_name_or_path):
412+
if os.path.isfile(pretrained_model_name_or_path):
413+
return True
414+
415+
if not is_valid_url(pretrained_model_name_or_path):
413416
return False
414417

415418
repo_id, weight_name = _extract_repo_id_and_weights_name(pretrained_model_name_or_path)

tests/modular_pipelines/test_modular_pipelines_common.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from huggingface_hub import hf_hub_download
99

1010
import diffusers
11-
from diffusers import AutoModel, ComponentsManager, ModularPipeline, ModularPipelineBlocks
11+
from diffusers import AutoModel, ComponentsManager, ControlNetModel, ModularPipeline, ModularPipelineBlocks
1212
from diffusers.guiders import ClassifierFreeGuidance
1313
from diffusers.modular_pipelines.modular_pipeline_utils import (
1414
ComponentSpec,
@@ -727,6 +727,28 @@ def test_automodel_update_components(self):
727727
assert spec.pretrained_model_name_or_path == "hf-internal-testing/tiny-stable-diffusion-xl-pipe"
728728
assert spec.subfolder == "unet"
729729

730+
def test_load_components_loads_local_single_file_path(self, tmp_path):
731+
pipe = ModularPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-xl-pipe")
732+
733+
local_ckpt_path = hf_hub_download(
734+
repo_id="lllyasviel/ControlNet-v1-1",
735+
filename="control_v11p_sd15_canny.pth",
736+
local_dir=str(tmp_path),
737+
)
738+
739+
pipe._component_specs["controlnet"] = ComponentSpec(
740+
name="controlnet",
741+
type_hint=ControlNetModel,
742+
pretrained_model_name_or_path=local_ckpt_path,
743+
)
744+
745+
pipe.load_components(names="controlnet")
746+
747+
assert pipe.controlnet is not None
748+
assert isinstance(pipe.controlnet, ControlNetModel)
749+
assert pipe._component_specs["controlnet"].pretrained_model_name_or_path == local_ckpt_path
750+
assert getattr(pipe.controlnet, "_diffusers_load_id", None) not in (None, "null")
751+
730752

731753
class TestLoadComponentsSkipBehavior:
732754
def test_load_components_skips_already_loaded(self):

0 commit comments

Comments
 (0)