@@ -229,8 +229,8 @@ def tearDown(self):
229229 gc .collect ()
230230 torch .cuda .empty_cache ()
231231
232- def get_inputs (self , device , dtype = torch . float32 , seed = 0 ):
233- generator = torch .Generator ( device = device ). manual_seed (seed )
232+ def get_inputs (self , seed = 0 ):
233+ generator = torch .manual_seed (seed )
234234 image = load_image (
235235 "https://huggingface.co/datasets/diffusers/test-arrays/resolve/main/stable_diffusion_pix2pix/example.jpg"
236236 )
@@ -253,12 +253,12 @@ def test_stable_diffusion_pix2pix_default(self):
253253 pipe .set_progress_bar_config (disable = None )
254254 pipe .enable_attention_slicing ()
255255
256- inputs = self .get_inputs (torch_device )
256+ inputs = self .get_inputs ()
257257 image = pipe (** inputs ).images
258258 image_slice = image [0 , - 3 :, - 3 :, - 1 ].flatten ()
259259
260260 assert image .shape == (1 , 512 , 512 , 3 )
261- expected_slice = np .array ([0.3214 , 0.3252 , 0.3313 , 0.3261 , 0.3332 , 0.3351 , 0.324 , 0.3296 , 0.3206 ])
261+ expected_slice = np .array ([0.5902 , 0.6015 , 0.6027 , 0.5983 , 0.6092 , 0.6061 , 0.5765 , 0.5785 , 0.5555 ])
262262 assert np .abs (expected_slice - image_slice ).max () < 1e-3
263263
264264 def test_stable_diffusion_pix2pix_k_lms (self ):
@@ -270,12 +270,12 @@ def test_stable_diffusion_pix2pix_k_lms(self):
270270 pipe .set_progress_bar_config (disable = None )
271271 pipe .enable_attention_slicing ()
272272
273- inputs = self .get_inputs (torch_device )
273+ inputs = self .get_inputs ()
274274 image = pipe (** inputs ).images
275275 image_slice = image [0 , - 3 :, - 3 :, - 1 ].flatten ()
276276
277277 assert image .shape == (1 , 512 , 512 , 3 )
278- expected_slice = np .array ([0.3893 , 0.393 , 0.3997 , 0.4196 , 0.4239 , 0.4307 , 0.4268 , 0.4317 , 0.419 ])
278+ expected_slice = np .array ([0.6578 , 0.6817 , 0.6972 , 0.6761 , 0.6856 , 0.6916 , 0.6428 , 0.6516 , 0.6301 ])
279279 assert np .abs (expected_slice - image_slice ).max () < 1e-3
280280
281281 def test_stable_diffusion_pix2pix_ddim (self ):
@@ -287,12 +287,12 @@ def test_stable_diffusion_pix2pix_ddim(self):
287287 pipe .set_progress_bar_config (disable = None )
288288 pipe .enable_attention_slicing ()
289289
290- inputs = self .get_inputs (torch_device )
290+ inputs = self .get_inputs ()
291291 image = pipe (** inputs ).images
292292 image_slice = image [0 , - 3 :, - 3 :, - 1 ].flatten ()
293293
294294 assert image .shape == (1 , 512 , 512 , 3 )
295- expected_slice = np .array ([0.5151 , 0.5186 , 0.5133 , 0.5176 , 0.5147 , 0.5198 , 0.522 , 0.5122 , 0.5244 ])
295+ expected_slice = np .array ([0.3828 , 0.3834 , 0.3818 , 0.3792 , 0.3865 , 0.3752 , 0.3792 , 0.3847 , 0.3753 ])
296296 assert np .abs (expected_slice - image_slice ).max () < 1e-3
297297
298298 def test_stable_diffusion_pix2pix_intermediate_state (self ):
@@ -306,13 +306,13 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None:
306306 latents = latents .detach ().cpu ().numpy ()
307307 assert latents .shape == (1 , 4 , 64 , 64 )
308308 latents_slice = latents [0 , - 3 :, - 3 :, - 1 ]
309- expected_slice = np .array ([- 0.7178 , - 0.9165 , - 1.3906 , 1.8174 , 1.9482 , 1.3652 , 1.1533 , 1.542 , 1.2461 ])
309+ expected_slice = np .array ([- 0.2388 , - 0.4673 , - 0.9775 , 1.5127 , 1.4414 , 0.7778 , 0.9907 , 0.8472 , 0.7788 ])
310310 assert np .abs (latents_slice .flatten () - expected_slice ).max () < 1e-3
311311 elif step == 2 :
312312 latents = latents .detach ().cpu ().numpy ()
313313 assert latents .shape == (1 , 4 , 64 , 64 )
314314 latents_slice = latents [0 , - 3 :, - 3 :, - 1 ]
315- expected_slice = np .array ([- 0.7183 , - 0.9253 , - 1.3857 , 1.8174 , 1.9766 , 1.3574 , 1.1533 , 1.5244 , 1.2539 ])
315+ expected_slice = np .array ([- 0.2568 , - 0.4648 , - 0.9639 , 1.5137 , 1.4609 , 0.7603 , 0.9795 , 0.8403 , 0.7949 ])
316316 assert np .abs (latents_slice .flatten () - expected_slice ).max () < 1e-3
317317
318318 callback_fn .has_been_called = False
@@ -324,7 +324,7 @@ def callback_fn(step: int, timestep: int, latents: torch.FloatTensor) -> None:
324324 pipe .set_progress_bar_config (disable = None )
325325 pipe .enable_attention_slicing ()
326326
327- inputs = self .get_inputs (torch_device , dtype = torch . float16 )
327+ inputs = self .get_inputs ()
328328 pipe (** inputs , callback = callback_fn , callback_steps = 1 )
329329 assert callback_fn .has_been_called
330330 assert number_of_steps == 3
@@ -342,15 +342,15 @@ def test_stable_diffusion_pipeline_with_sequential_cpu_offloading(self):
342342 pipe .enable_attention_slicing (1 )
343343 pipe .enable_sequential_cpu_offload ()
344344
345- inputs = self .get_inputs (torch_device , dtype = torch . float16 )
345+ inputs = self .get_inputs ()
346346 _ = pipe (** inputs )
347347
348348 mem_bytes = torch .cuda .max_memory_allocated ()
349349 # make sure that less than 2.2 GB is allocated
350350 assert mem_bytes < 2.2 * 10 ** 9
351351
352352 def test_stable_diffusion_pix2pix_pipeline_multiple_of_8 (self ):
353- inputs = self .get_inputs (torch_device )
353+ inputs = self .get_inputs ()
354354 # resize to resolution that is divisible by 8 but not 16 or 32
355355 inputs ["image" ] = inputs ["image" ].resize ((504 , 504 ))
356356
@@ -369,5 +369,5 @@ def test_stable_diffusion_pix2pix_pipeline_multiple_of_8(self):
369369 image_slice = image [255 :258 , 383 :386 , - 1 ]
370370
371371 assert image .shape == (504 , 504 , 3 )
372- expected_slice = np .array ([0.1834 , 0.2046 , 0.2429 , 0.1825 , 0.2201 , 0.2576 , 0.1968 , 0.2185 , 0.2487 ])
372+ expected_slice = np .array ([0.2726 , 0.2529 , 0.2664 , 0.2655 , 0.2641 , 0.2642 , 0.2591 , 0.2649 , 0.259 ])
373373 assert np .abs (image_slice .flatten () - expected_slice ).max () < 1e-3
0 commit comments