Skip to content

Commit 7b07f98

Browse files
authored
Move controlnet load local tests to nightly (huggingface#4543)
move controlnet load local tests to nihghtly
1 parent 16ad13b commit 7b07f98

File tree

3 files changed

+66
-39
lines changed

3 files changed

+66
-39
lines changed

tests/pipelines/controlnet/test_controlnet.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
UNet2DConditionModel,
3232
)
3333
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
3535
from diffusers.utils.import_utils import is_xformers_available
3636
from diffusers.utils.testing_utils import (
3737
enable_full_determinism,
@@ -925,42 +925,6 @@ def test_v11_shuffle_global_pool_conditions(self):
925925
expected_slice = np.array([0.1338, 0.1597, 0.1202, 0.1687, 0.1377, 0.1017, 0.2070, 0.1574, 0.1348])
926926
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
927927

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-
964928

965929
@slow
966930
@require_torch_gpu
@@ -1000,3 +964,48 @@ def test_pose_and_canny(self):
1000964
)
1001965

1002966
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

tests/pipelines/controlnet/test_controlnet_img2img.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
UNet2DConditionModel,
3434
)
3535
from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_controlnet import MultiControlNetModel
36-
from diffusers.utils import floats_tensor, load_image, load_numpy, randn_tensor, slow, torch_device
36+
from diffusers.utils import floats_tensor, load_image, load_numpy, nightly, randn_tensor, slow, torch_device
3737
from diffusers.utils.import_utils import is_xformers_available
3838
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu
3939

@@ -402,6 +402,15 @@ def test_canny(self):
402402

403403
assert np.abs(expected_image - image).max() < 9e-2
404404

405+
406+
@nightly
407+
@require_torch_gpu
408+
class ControlNetImg2ImgPipelineNightlyTests(unittest.TestCase):
409+
def tearDown(self):
410+
super().tearDown()
411+
gc.collect()
412+
torch.cuda.empty_cache()
413+
405414
def test_load_local(self):
406415
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_canny")
407416
pipe_1 = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(

tests/pipelines/controlnet/test_controlnet_inpaint.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
UNet2DConditionModel,
3434
)
3535
from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_controlnet import MultiControlNetModel
36-
from diffusers.utils import floats_tensor, load_image, load_numpy, randn_tensor, slow, torch_device
36+
from diffusers.utils import floats_tensor, load_image, load_numpy, nightly, randn_tensor, slow, torch_device
3737
from diffusers.utils.import_utils import is_xformers_available
3838
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu
3939

@@ -544,6 +544,15 @@ def make_inpaint_condition(image, image_mask):
544544

545545
assert np.abs(expected_image - image).max() < 9e-2
546546

547+
548+
@nightly
549+
@require_torch_gpu
550+
class ControlNetInpaintPipelineNightlyTests(unittest.TestCase):
551+
def tearDown(self):
552+
super().tearDown()
553+
gc.collect()
554+
torch.cuda.empty_cache()
555+
547556
def test_load_local(self):
548557
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_canny")
549558
pipe_1 = StableDiffusionControlNetInpaintPipeline.from_pretrained(

0 commit comments

Comments
 (0)