|
8 | 8 | from huggingface_hub import hf_hub_download |
9 | 9 |
|
10 | 10 | import diffusers |
11 | | -from diffusers import AutoModel, ComponentsManager, ModularPipeline, ModularPipelineBlocks |
| 11 | +from diffusers import AutoModel, ComponentsManager, ControlNetModel, ModularPipeline, ModularPipelineBlocks |
12 | 12 | from diffusers.guiders import ClassifierFreeGuidance |
13 | 13 | from diffusers.modular_pipelines.modular_pipeline_utils import ( |
14 | 14 | ComponentSpec, |
@@ -727,6 +727,28 @@ def test_automodel_update_components(self): |
727 | 727 | assert spec.pretrained_model_name_or_path == "hf-internal-testing/tiny-stable-diffusion-xl-pipe" |
728 | 728 | assert spec.subfolder == "unet" |
729 | 729 |
|
| 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 | + |
730 | 752 |
|
731 | 753 | class TestLoadComponentsSkipBehavior: |
732 | 754 | def test_load_components_skips_already_loaded(self): |
|
0 commit comments