Skip to content

Commit b935381

Browse files
andrew-w-rossDN6
andauthored
corrects single file path validation logic (#13363)
* corrects single file path validation logic * Update tests/modular_pipelines/test_modular_pipelines_common.py Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com> --------- Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
1 parent 514bba0 commit b935381

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-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: 21 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,26 @@ 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+
model = ControlNetModel.from_pretrained("hf-internal-testing/tiny-controlnet")
734+
model.save_pretrained(tmp_path)
735+
736+
local_ckpt_path = str(tmp_path / "diffusion_pytorch_model.safetensors")
737+
738+
pipe._component_specs["controlnet"] = ComponentSpec(
739+
name="controlnet",
740+
type_hint=ControlNetModel,
741+
pretrained_model_name_or_path=local_ckpt_path,
742+
)
743+
pipe.load_components(names="controlnet", config=str(tmp_path))
744+
745+
assert pipe.controlnet is not None
746+
assert isinstance(pipe.controlnet, ControlNetModel)
747+
assert pipe._component_specs["controlnet"].pretrained_model_name_or_path == local_ckpt_path
748+
assert getattr(pipe.controlnet, "_diffusers_load_id", None) not in (None, "null")
749+
730750

731751
class TestLoadComponentsSkipBehavior:
732752
def test_load_components_skips_already_loaded(self):

0 commit comments

Comments
 (0)