|
31 | 31 | UNet2DConditionModel, |
32 | 32 | ) |
33 | 33 | from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_controlnet import MultiControlNetModel |
34 | | -from diffusers.utils import load_image, load_numpy, randn_tensor, slow, torch_device |
| 34 | +from diffusers.utils import load_image, load_numpy, nightly, randn_tensor, slow, torch_device |
35 | 35 | from diffusers.utils.import_utils import is_xformers_available |
36 | 36 | from diffusers.utils.testing_utils import ( |
37 | 37 | enable_full_determinism, |
@@ -925,42 +925,6 @@ def test_v11_shuffle_global_pool_conditions(self): |
925 | 925 | expected_slice = np.array([0.1338, 0.1597, 0.1202, 0.1687, 0.1377, 0.1017, 0.2070, 0.1574, 0.1348]) |
926 | 926 | assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 |
927 | 927 |
|
928 | | - def test_load_local(self): |
929 | | - controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_canny") |
930 | | - pipe_1 = StableDiffusionControlNetPipeline.from_pretrained( |
931 | | - "runwayml/stable-diffusion-v1-5", safety_checker=None, controlnet=controlnet |
932 | | - ) |
933 | | - |
934 | | - controlnet = ControlNetModel.from_single_file( |
935 | | - "https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15_canny.pth" |
936 | | - ) |
937 | | - pipe_2 = StableDiffusionControlNetPipeline.from_single_file( |
938 | | - "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors", |
939 | | - safety_checker=None, |
940 | | - controlnet=controlnet, |
941 | | - ) |
942 | | - pipes = [pipe_1, pipe_2] |
943 | | - images = [] |
944 | | - |
945 | | - for pipe in pipes: |
946 | | - pipe.enable_model_cpu_offload() |
947 | | - pipe.set_progress_bar_config(disable=None) |
948 | | - |
949 | | - generator = torch.Generator(device="cpu").manual_seed(0) |
950 | | - prompt = "bird" |
951 | | - image = load_image( |
952 | | - "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/bird_canny.png" |
953 | | - ) |
954 | | - |
955 | | - output = pipe(prompt, image, generator=generator, output_type="np", num_inference_steps=3) |
956 | | - images.append(output.images[0]) |
957 | | - |
958 | | - del pipe |
959 | | - gc.collect() |
960 | | - torch.cuda.empty_cache() |
961 | | - |
962 | | - assert np.abs(images[0] - images[1]).sum() < 1e-3 |
963 | | - |
964 | 928 |
|
965 | 929 | @slow |
966 | 930 | @require_torch_gpu |
@@ -1000,3 +964,48 @@ def test_pose_and_canny(self): |
1000 | 964 | ) |
1001 | 965 |
|
1002 | 966 | assert np.abs(expected_image - image).max() < 5e-2 |
| 967 | + |
| 968 | + |
| 969 | +@nightly |
| 970 | +@require_torch_gpu |
| 971 | +class StableDiffusionMultiControlNetPipelineNightlyTests(unittest.TestCase): |
| 972 | + def tearDown(self): |
| 973 | + super().tearDown() |
| 974 | + gc.collect() |
| 975 | + torch.cuda.empty_cache() |
| 976 | + |
| 977 | + def test_load_local(self): |
| 978 | + controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_canny") |
| 979 | + pipe_1 = StableDiffusionControlNetPipeline.from_pretrained( |
| 980 | + "runwayml/stable-diffusion-v1-5", safety_checker=None, controlnet=controlnet |
| 981 | + ) |
| 982 | + |
| 983 | + controlnet = ControlNetModel.from_single_file( |
| 984 | + "https://huggingface.co/lllyasviel/ControlNet-v1-1/blob/main/control_v11p_sd15_canny.pth" |
| 985 | + ) |
| 986 | + pipe_2 = StableDiffusionControlNetPipeline.from_single_file( |
| 987 | + "https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.safetensors", |
| 988 | + safety_checker=None, |
| 989 | + controlnet=controlnet, |
| 990 | + ) |
| 991 | + pipes = [pipe_1, pipe_2] |
| 992 | + images = [] |
| 993 | + |
| 994 | + for pipe in pipes: |
| 995 | + pipe.enable_model_cpu_offload() |
| 996 | + pipe.set_progress_bar_config(disable=None) |
| 997 | + |
| 998 | + generator = torch.Generator(device="cpu").manual_seed(0) |
| 999 | + prompt = "bird" |
| 1000 | + image = load_image( |
| 1001 | + "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/bird_canny.png" |
| 1002 | + ) |
| 1003 | + |
| 1004 | + output = pipe(prompt, image, generator=generator, output_type="np", num_inference_steps=3) |
| 1005 | + images.append(output.images[0]) |
| 1006 | + |
| 1007 | + del pipe |
| 1008 | + gc.collect() |
| 1009 | + torch.cuda.empty_cache() |
| 1010 | + |
| 1011 | + assert np.abs(images[0] - images[1]).sum() < 1e-3 |
0 commit comments