@@ -609,11 +609,12 @@ def test_stable_diffusion_memory_chunking(self):
609609 assert mem_bytes > 3.75 * 10 ** 9
610610 assert np .abs (image_chunked .flatten () - image .flatten ()).max () < 1e-3
611611
612- def test_stable_diffusion_text2img_pipeline_fp16 (self ):
612+ def test_stable_diffusion_same_quality (self ):
613613 torch .cuda .reset_peak_memory_stats ()
614614 model_id = "stabilityai/stable-diffusion-2-base"
615615 pipe = StableDiffusionPipeline .from_pretrained (model_id , revision = "fp16" , torch_dtype = torch .float16 )
616616 pipe = pipe .to (torch_device )
617+ pipe .enable_attention_slicing ()
617618 pipe .set_progress_bar_config (disable = None )
618619
619620 prompt = "a photograph of an astronaut riding a horse"
@@ -624,18 +625,17 @@ def test_stable_diffusion_text2img_pipeline_fp16(self):
624625 )
625626 image_chunked = output_chunked .images
626627
628+ pipe = StableDiffusionPipeline .from_pretrained (model_id )
629+ pipe = pipe .to (torch_device )
627630 generator = torch .Generator (device = torch_device ).manual_seed (0 )
628- with torch .autocast (torch_device ):
629- output = pipe (
630- [prompt ], generator = generator , guidance_scale = 7.5 , num_inference_steps = 10 , output_type = "numpy"
631- )
632- image = output .images
631+ output = pipe ([prompt ], generator = generator , guidance_scale = 7.5 , num_inference_steps = 10 , output_type = "numpy" )
632+ image = output .images
633633
634634 # Make sure results are close enough
635635 diff = np .abs (image_chunked .flatten () - image .flatten ())
636636 # They ARE different since ops are not run always at the same precision
637637 # however, they should be extremely close.
638- assert diff .mean () < 2e -2
638+ assert diff .mean () < 5e -2
639639
640640 def test_stable_diffusion_text2img_pipeline_default (self ):
641641 expected_image = load_numpy (
@@ -669,7 +669,7 @@ def test_callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> No
669669 assert latents .shape == (1 , 4 , 64 , 64 )
670670 latents_slice = latents [0 , - 3 :, - 3 :, - 1 ]
671671 expected_slice = np .array ([1.8606 , 1.3169 , - 0.0691 , 1.2374 , - 2.309 , 1.077 , - 0.1084 , - 0.6774 , - 2.9594 ])
672- assert np .abs (latents_slice .flatten () - expected_slice ).max () < 1e -3
672+ assert np .abs (latents_slice .flatten () - expected_slice ).max () < 5e -3
673673 elif step == 20 :
674674 latents = latents .detach ().cpu ().numpy ()
675675 assert latents .shape == (1 , 4 , 64 , 64 )
0 commit comments