@@ -265,6 +265,25 @@ def test_stable_diffusion_v_pred_default(self):
265
265
expected_slice = np .array ([0.0567 , 0.057 , 0.0416 , 0.0463 , 0.0433 , 0.06 , 0.0517 , 0.0526 , 0.0866 ])
266
266
assert np .abs (image_slice .flatten () - expected_slice ).max () < 1e-2
267
267
268
+ def test_stable_diffusion_v_pred_upcast_attention (self ):
269
+ sd_pipe = StableDiffusionPipeline .from_pretrained (
270
+ "stabilityai/stable-diffusion-2-1" , torch_dtype = torch .float16
271
+ )
272
+ sd_pipe = sd_pipe .to (torch_device )
273
+ sd_pipe .enable_attention_slicing ()
274
+ sd_pipe .set_progress_bar_config (disable = None )
275
+
276
+ prompt = "A painting of a squirrel eating a burger"
277
+ generator = torch .Generator (device = torch_device ).manual_seed (0 )
278
+ output = sd_pipe ([prompt ], generator = generator , guidance_scale = 7.5 , num_inference_steps = 20 , output_type = "np" )
279
+
280
+ image = output .images
281
+ image_slice = image [0 , 253 :256 , 253 :256 , - 1 ]
282
+
283
+ assert image .shape == (1 , 768 , 768 , 3 )
284
+ expected_slice = np .array ([0.0461 , 0.0483 , 0.0566 , 0.0512 , 0.0446 , 0.0751 , 0.0664 , 0.0551 , 0.0488 ])
285
+ assert np .abs (image_slice .flatten () - expected_slice ).max () < 1e-2
286
+
268
287
def test_stable_diffusion_v_pred_euler (self ):
269
288
scheduler = EulerDiscreteScheduler .from_pretrained ("stabilityai/stable-diffusion-2" , subfolder = "scheduler" )
270
289
sd_pipe = StableDiffusionPipeline .from_pretrained ("stabilityai/stable-diffusion-2" , scheduler = scheduler )
0 commit comments