Skip to content

Commit 8d6487f

Browse files
Fix some failing tests (#1041)
* up * up * up * Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py * Apply suggestions from code review
1 parent d2d9764 commit 8d6487f

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ def custom_forward(*inputs):
662662

663663

664664
class LDMBertModel(LDMBertPreTrainedModel):
665+
_no_split_modules = []
666+
665667
def __init__(self, config: LDMBertConfig):
666668
super().__init__(config)
667669
self.model = LDMBertEncoder(config)

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ def __call__(
208208
list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work"
209209
(nsfw) content, according to the `safety_checker`.
210210
"""
211-
212211
if isinstance(prompt, str):
213212
batch_size = 1
214213
elif isinstance(prompt, list):

tests/pipelines/stable_diffusion/test_stable_diffusion.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def test_stable_diffusion_accelerate_auto_device(self):
740740

741741
start_time = time.time()
742742
pipeline_normal_load = StableDiffusionPipeline.from_pretrained(
743-
pipeline_id, revision="fp16", torch_dtype=torch.float16, device_map="auto"
743+
pipeline_id, revision="fp16", torch_dtype=torch.float16
744744
)
745745
pipeline_normal_load.to(torch_device)
746746
normal_load_time = time.time() - start_time
@@ -761,9 +761,7 @@ def test_stable_diffusion_pipeline_with_unet_on_gpu_only(self):
761761
pipeline_id = "CompVis/stable-diffusion-v1-4"
762762
prompt = "Andromeda galaxy in a bottle"
763763

764-
pipeline = StableDiffusionPipeline.from_pretrained(
765-
pipeline_id, revision="fp16", torch_dtype=torch.float16, device_map="auto"
766-
)
764+
pipeline = StableDiffusionPipeline.from_pretrained(pipeline_id, revision="fp16", torch_dtype=torch.float16)
767765
pipeline.enable_attention_slicing(1)
768766
pipeline.enable_sequential_cpu_offload()
769767

tests/test_pipelines.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def test_load_custom_pipeline(self):
7777
pipeline = DiffusionPipeline.from_pretrained(
7878
"google/ddpm-cifar10-32", custom_pipeline="hf-internal-testing/diffusers-dummy-pipeline"
7979
)
80+
pipeline = pipeline.to(torch_device)
8081
# NOTE that `"CustomPipeline"` is not a class that is defined in this library, but solely on the Hub
8182
# under https://huggingface.co/hf-internal-testing/diffusers-dummy-pipeline/blob/main/pipeline.py#L24
8283
assert pipeline.__class__.__name__ == "CustomPipeline"
@@ -85,6 +86,7 @@ def test_run_custom_pipeline(self):
8586
pipeline = DiffusionPipeline.from_pretrained(
8687
"google/ddpm-cifar10-32", custom_pipeline="hf-internal-testing/diffusers-dummy-pipeline"
8788
)
89+
pipeline = pipeline.to(torch_device)
8890
images, output_str = pipeline(num_inference_steps=2, output_type="np")
8991

9092
assert images[0].shape == (1, 32, 32, 3)
@@ -96,6 +98,7 @@ def test_local_custom_pipeline(self):
9698
pipeline = DiffusionPipeline.from_pretrained(
9799
"google/ddpm-cifar10-32", custom_pipeline=local_custom_pipeline_path
98100
)
101+
pipeline = pipeline.to(torch_device)
99102
images, output_str = pipeline(num_inference_steps=2, output_type="np")
100103

101104
assert pipeline.__class__.__name__ == "CustomLocalPipeline"
@@ -109,7 +112,7 @@ def test_load_pipeline_from_git(self):
109112
clip_model_id = "laion/CLIP-ViT-B-32-laion2B-s34B-b79K"
110113

111114
feature_extractor = CLIPFeatureExtractor.from_pretrained(clip_model_id, device_map="auto")
112-
clip_model = CLIPModel.from_pretrained(clip_model_id, torch_dtype=torch.float16, device_map="auto")
115+
clip_model = CLIPModel.from_pretrained(clip_model_id, torch_dtype=torch.float16)
113116

114117
pipeline = DiffusionPipeline.from_pretrained(
115118
"CompVis/stable-diffusion-v1-4",
@@ -380,10 +383,11 @@ def test_from_pretrained_hub(self):
380383
scheduler = DDPMScheduler(num_train_timesteps=10)
381384

382385
ddpm = DDPMPipeline.from_pretrained(model_path, scheduler=scheduler, device_map="auto")
383-
ddpm.to(torch_device)
386+
ddpm = ddpm.to(torch_device)
384387
ddpm.set_progress_bar_config(disable=None)
388+
385389
ddpm_from_hub = DiffusionPipeline.from_pretrained(model_path, scheduler=scheduler, device_map="auto")
386-
ddpm_from_hub.to(torch_device)
390+
ddpm_from_hub = ddpm_from_hub.to(torch_device)
387391
ddpm_from_hub.set_progress_bar_config(disable=None)
388392

389393
generator = torch.manual_seed(0)
@@ -404,11 +408,11 @@ def test_from_pretrained_hub_pass_model(self):
404408
ddpm_from_hub_custom_model = DiffusionPipeline.from_pretrained(
405409
model_path, unet=unet, scheduler=scheduler, device_map="auto"
406410
)
407-
ddpm_from_hub_custom_model.to(torch_device)
411+
ddpm_from_hub_custom_model = ddpm_from_hub_custom_model.to(torch_device)
408412
ddpm_from_hub_custom_model.set_progress_bar_config(disable=None)
409413

410414
ddpm_from_hub = DiffusionPipeline.from_pretrained(model_path, scheduler=scheduler, device_map="auto")
411-
ddpm_from_hub.to(torch_device)
415+
ddpm_from_hub = ddpm_from_hub.to(torch_device)
412416
ddpm_from_hub_custom_model.set_progress_bar_config(disable=None)
413417

414418
generator = torch.manual_seed(0)

0 commit comments

Comments
 (0)