Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/diffusers/loaders/single_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ def is_valid_url(url):


def _is_single_file_path_or_url(pretrained_model_name_or_path):
if not os.path.isfile(pretrained_model_name_or_path) or not is_valid_url(pretrained_model_name_or_path):
if os.path.isfile(pretrained_model_name_or_path):
return True

if not is_valid_url(pretrained_model_name_or_path):
return False

repo_id, weight_name = _extract_repo_id_and_weights_name(pretrained_model_name_or_path)
Expand Down
22 changes: 21 additions & 1 deletion tests/modular_pipelines/test_modular_pipelines_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from huggingface_hub import hf_hub_download

import diffusers
from diffusers import AutoModel, ComponentsManager, ModularPipeline, ModularPipelineBlocks
from diffusers import AutoModel, ComponentsManager, ControlNetModel, ModularPipeline, ModularPipelineBlocks
from diffusers.guiders import ClassifierFreeGuidance
from diffusers.modular_pipelines.modular_pipeline_utils import (
ComponentSpec,
Expand Down Expand Up @@ -727,6 +727,26 @@ def test_automodel_update_components(self):
assert spec.pretrained_model_name_or_path == "hf-internal-testing/tiny-stable-diffusion-xl-pipe"
assert spec.subfolder == "unet"

def test_load_components_loads_local_single_file_path(self, tmp_path):
pipe = ModularPipeline.from_pretrained("hf-internal-testing/tiny-stable-diffusion-xl-pipe")

model = ControlNetModel.from_pretrained("hf-internal-testing/tiny-controlnet")
model.save_pretrained(tmp_path)

local_ckpt_path = str(tmp_path / "diffusion_pytorch_model.safetensors")

pipe._component_specs["controlnet"] = ComponentSpec(
name="controlnet",
type_hint=ControlNetModel,
pretrained_model_name_or_path=local_ckpt_path,
)
pipe.load_components(names="controlnet", config=str(tmp_path))

assert pipe.controlnet is not None
assert isinstance(pipe.controlnet, ControlNetModel)
assert pipe._component_specs["controlnet"].pretrained_model_name_or_path == local_ckpt_path
assert getattr(pipe.controlnet, "_diffusers_load_id", None) not in (None, "null")

Comment thread
andrew-w-ross marked this conversation as resolved.

class TestLoadComponentsSkipBehavior:
def test_load_components_skips_already_loaded(self):
Expand Down
Loading