77
88from diffusers import AutoencoderKL , FlowMatchEulerDiscreteScheduler , OmniGenPipeline , OmniGenTransformer2DModel
99from diffusers .utils .testing_utils import (
10+ Expectations ,
11+ backend_empty_cache ,
1012 numpy_cosine_similarity_distance ,
11- require_torch_gpu ,
13+ require_torch_accelerator ,
1214 slow ,
1315 torch_device ,
1416)
@@ -87,20 +89,20 @@ def test_inference(self):
8789
8890
8991@slow
90- @require_torch_gpu
92+ @require_torch_accelerator
9193class OmniGenPipelineSlowTests (unittest .TestCase ):
9294 pipeline_class = OmniGenPipeline
9395 repo_id = "shitao/OmniGen-v1-diffusers"
9496
9597 def setUp (self ):
9698 super ().setUp ()
9799 gc .collect ()
98- torch . cuda . empty_cache ( )
100+ backend_empty_cache ( torch_device )
99101
100102 def tearDown (self ):
101103 super ().tearDown ()
102104 gc .collect ()
103- torch . cuda . empty_cache ( )
105+ backend_empty_cache ( torch_device )
104106
105107 def get_inputs (self , device , seed = 0 ):
106108 if str (device ).startswith ("mps" ):
@@ -125,21 +127,56 @@ def test_omnigen_inference(self):
125127 image = pipe (** inputs ).images [0 ]
126128 image_slice = image [0 , :10 , :10 ]
127129
128- expected_slice = np .array (
129- [
130- [0.1783447 , 0.16772744 , 0.14339337 ],
131- [0.17066911 , 0.15521264 , 0.13757327 ],
132- [0.17072496 , 0.15531206 , 0.13524258 ],
133- [0.16746324 , 0.1564025 , 0.13794944 ],
134- [0.16490817 , 0.15258026 , 0.13697758 ],
135- [0.16971767 , 0.15826806 , 0.13928896 ],
136- [0.16782972 , 0.15547255 , 0.13783783 ],
137- [0.16464645 , 0.15281534 , 0.13522372 ],
138- [0.16535294 , 0.15301755 , 0.13526791 ],
139- [0.16365296 , 0.15092957 , 0.13443318 ],
140- ],
141- dtype = np .float32 ,
130+ expected_slices = Expectations (
131+ {
132+ ("xpu" , 3 ): np .array (
133+ [
134+ [0.05859375 , 0.05859375 , 0.04492188 ],
135+ [0.04882812 , 0.04101562 , 0.03320312 ],
136+ [0.04882812 , 0.04296875 , 0.03125 ],
137+ [0.04296875 , 0.0390625 , 0.03320312 ],
138+ [0.04296875 , 0.03710938 , 0.03125 ],
139+ [0.04492188 , 0.0390625 , 0.03320312 ],
140+ [0.04296875 , 0.03710938 , 0.03125 ],
141+ [0.04101562 , 0.03710938 , 0.02734375 ],
142+ [0.04101562 , 0.03515625 , 0.02734375 ],
143+ [0.04101562 , 0.03515625 , 0.02929688 ],
144+ ],
145+ dtype = np .float32 ,
146+ ),
147+ ("cuda" , 7 ): np .array (
148+ [
149+ [0.1783447 , 0.16772744 , 0.14339337 ],
150+ [0.17066911 , 0.15521264 , 0.13757327 ],
151+ [0.17072496 , 0.15531206 , 0.13524258 ],
152+ [0.16746324 , 0.1564025 , 0.13794944 ],
153+ [0.16490817 , 0.15258026 , 0.13697758 ],
154+ [0.16971767 , 0.15826806 , 0.13928896 ],
155+ [0.16782972 , 0.15547255 , 0.13783783 ],
156+ [0.16464645 , 0.15281534 , 0.13522372 ],
157+ [0.16535294 , 0.15301755 , 0.13526791 ],
158+ [0.16365296 , 0.15092957 , 0.13443318 ],
159+ ],
160+ dtype = np .float32 ,
161+ ),
162+ ("cuda" , 8 ): np .array (
163+ [
164+ [0.0546875 , 0.05664062 , 0.04296875 ],
165+ [0.046875 , 0.04101562 , 0.03320312 ],
166+ [0.05078125 , 0.04296875 , 0.03125 ],
167+ [0.04296875 , 0.04101562 , 0.03320312 ],
168+ [0.0390625 , 0.03710938 , 0.02929688 ],
169+ [0.04296875 , 0.03710938 , 0.03125 ],
170+ [0.0390625 , 0.03710938 , 0.02929688 ],
171+ [0.0390625 , 0.03710938 , 0.02734375 ],
172+ [0.0390625 , 0.03320312 , 0.02734375 ],
173+ [0.0390625 , 0.03320312 , 0.02734375 ],
174+ ],
175+ dtype = np .float32 ,
176+ ),
177+ }
142178 )
179+ expected_slice = expected_slices .get_expectation ()
143180
144181 max_diff = numpy_cosine_similarity_distance (expected_slice .flatten (), image_slice .flatten ())
145182
0 commit comments