1313# limitations under the License.
1414
1515import gc
16- import unittest
1716import tempfile
17+ import unittest
1818
1919import numpy as np
2020import torch
3232 enable_full_determinism ,
3333 nightly ,
3434 numpy_cosine_similarity_distance ,
35- require_torch_gpu ,
3635 require_accelerator ,
36+ require_torch_gpu ,
3737 slow ,
3838 torch_device ,
3939)
4040
41-
4241# from ..test_pipelines_common import PipelineTesterMixin, check_qkv_fused_layers_exist
43- from tests .pipelines .test_pipelines_common import PipelineTesterMixin ,to_np
42+ from tests .pipelines .test_pipelines_common import PipelineTesterMixin , to_np
4443
45- enable_full_determinism ()
4644
45+ enable_full_determinism ()
4746
4847
4948class BriaPipelineFastTests (PipelineTesterMixin , unittest .TestCase ):
@@ -56,7 +55,7 @@ class BriaPipelineFastTests(PipelineTesterMixin, unittest.TestCase):
5655 test_xformers_attention = False
5756 test_layerwise_casting = True
5857 test_group_offloading = True
59-
58+
6059 def get_dummy_components (self ):
6160 torch .manual_seed (0 )
6261 transformer = BriaTransformer2DModel (
@@ -123,8 +122,10 @@ def get_dummy_inputs(self, device, seed=0):
123122 "output_type" : "np" ,
124123 }
125124 return inputs
125+
126126 def test_encode_prompt_works_in_isolation (self ):
127127 pass
128+
128129 def test_bria_different_prompts (self ):
129130 pipe = self .pipeline_class (** self .get_dummy_components ()).to (torch_device )
130131 inputs = self .get_dummy_inputs (torch_device )
@@ -135,9 +136,6 @@ def test_bria_different_prompts(self):
135136 max_diff = np .abs (output_same_prompt - output_different_prompts ).max ()
136137 assert max_diff > 1e-6
137138
138-
139-
140-
141139 def test_image_output_shape (self ):
142140 pipe = self .pipeline_class (** self .get_dummy_components ()).to (torch_device )
143141 inputs = self .get_dummy_inputs (torch_device )
@@ -194,11 +192,7 @@ def test_save_load_float16(self, expected_max_diff=1e-2):
194192 self .assertLess (
195193 max_diff , expected_max_diff , "The output of the fp16 pipeline changed after saving and loading."
196194 )
197-
198-
199-
200195
201-
202196 def test_bria_image_output_shape (self ):
203197 pipe = self .pipeline_class (** self .get_dummy_components ()).to (torch_device )
204198 inputs = self .get_dummy_inputs (torch_device )
@@ -217,9 +211,9 @@ def test_to_dtype(self):
217211 components = self .get_dummy_components ()
218212 pipe = self .pipeline_class (** components )
219213 pipe .set_progress_bar_config (disable = None )
220-
214+
221215 model_dtypes = [component .dtype for component in components .values () if hasattr (component , "dtype" )]
222- self .assertTrue ([dtype == torch .float32 for dtype in model_dtypes ] == [False ,True ,True ])
216+ self .assertTrue ([dtype == torch .float32 for dtype in model_dtypes ] == [False , True , True ])
223217
224218 def test_torch_dtype_dict (self ):
225219 components = self .get_dummy_components ()
@@ -243,8 +237,6 @@ def test_torch_dtype_dict(self):
243237 self .assertEqual (loaded_pipe .text_encoder .dtype , torch .float16 )
244238 self .assertEqual (loaded_pipe .vae .dtype , torch .float16 )
245239
246-
247-
248240
249241@slow
250242@require_torch_gpu
@@ -265,9 +257,7 @@ def tearDown(self):
265257 def get_inputs (self , device , seed = 0 ):
266258 generator = torch .Generator (device = "cpu" ).manual_seed (seed )
267259 prompt_embeds = torch .load (
268- hf_hub_download (
269- repo_id = "diffusers/test-slices" , repo_type = "dataset" , filename = "bria_prompt_embeds.pt"
270- )
260+ hf_hub_download (repo_id = "diffusers/test-slices" , repo_type = "dataset" , filename = "bria_prompt_embeds.pt" )
271261 ).to (device )
272262 return {
273263 "prompt_embeds" : prompt_embeds ,
@@ -324,7 +314,7 @@ def test_bria_inference_bf16(self):
324314 )
325315 max_diff = numpy_cosine_similarity_distance (expected_slice , image_slice )
326316 self .assertLess (max_diff , 1e-4 , f"Image slice is different from expected slice: { max_diff :.4f} " )
327-
317+
328318 def test_to_dtype (self ):
329319 components = self .get_dummy_components ()
330320 pipe = self .pipeline_class (** components )
@@ -396,4 +386,3 @@ def test_bria_inference(self):
396386
397387 max_diff = numpy_cosine_similarity_distance (expected_slice , image_slice )
398388 self .assertLess (max_diff , 1e-4 , f"Image slice is different from expected slice: { max_diff :.4f} " )
399-
0 commit comments