|
17 | 17 | from ...testing_utils import ( |
18 | 18 | backend_empty_cache, |
19 | 19 | backend_synchronize, |
| 20 | + nightly, |
| 21 | + require_big_accelerator, |
20 | 22 | require_torch_neuron, |
21 | 23 | torch_device, |
22 | 24 | ) |
@@ -183,6 +185,18 @@ def test_image_input(self): |
183 | 185 | # fmt: on |
184 | 186 | assert np.allclose(expected_slice, generated_slice, atol=1e-4, rtol=1e-4) |
185 | 187 |
|
| 188 | + def test_image_input_max_area(self): |
| 189 | + # `max_area` (previously hardcoded to 1024**2) is the condition-image downscale threshold: |
| 190 | + # condition images whose area exceeds it are downscaled while preserving aspect ratio. |
| 191 | + pipe = self.pipeline_class(**self.get_dummy_components()).to(torch_device) |
| 192 | + inputs = self.get_dummy_inputs(torch_device) |
| 193 | + height, width = inputs["height"], inputs["width"] |
| 194 | + |
| 195 | + inputs.update({"image": Image.new("RGB", (128, 128)), "max_area": 64 * 64}) |
| 196 | + image = pipe(**inputs).images[0] |
| 197 | + output_height, output_width, _ = image.shape |
| 198 | + self.assertEqual((output_height, output_width), (height, width)) |
| 199 | + |
186 | 200 | @unittest.skip("Needs to be revisited") |
187 | 201 | def test_encode_prompt_works_in_isolation(self): |
188 | 202 | pass |
@@ -279,3 +293,49 @@ def test_flux2_klein_neuron_compile_128(self): |
279 | 293 | (image >= 0.0).all() and (image <= 1.0).all(), |
280 | 294 | "Output pixel values outside [0, 1]", |
281 | 295 | ) |
| 296 | + |
| 297 | + |
| 298 | +@nightly |
| 299 | +@require_big_accelerator |
| 300 | +class Flux2KleinPipelineConditionImageSlowTests(unittest.TestCase): |
| 301 | + ckpt_id = "black-forest-labs/FLUX.2-klein-4B" |
| 302 | + prompt = "A small cactus with a happy face in the Sahara desert." |
| 303 | + |
| 304 | + def setUp(self): |
| 305 | + super().setUp() |
| 306 | + gc.collect() |
| 307 | + backend_empty_cache(torch_device) |
| 308 | + |
| 309 | + def tearDown(self): |
| 310 | + super().tearDown() |
| 311 | + gc.collect() |
| 312 | + backend_empty_cache(torch_device) |
| 313 | + |
| 314 | + def test_flux2_klein_2048_condition_image(self): |
| 315 | + # A 2048x2048 condition image used to be silently downscaled to fit the hardcoded |
| 316 | + # 1024**2 threshold; passing max_area=2048**2 lets the pipeline consume it at full |
| 317 | + # resolution. |
| 318 | + pipe = Flux2KleinPipeline.from_pretrained(self.ckpt_id, torch_dtype=torch.bfloat16) |
| 319 | + pipe.to(torch_device) |
| 320 | + pipe.set_progress_bar_config(disable=None) |
| 321 | + |
| 322 | + generator = torch.Generator("cpu").manual_seed(0) |
| 323 | + condition_image = Image.new("RGB", (2048, 2048), (128, 128, 128)) |
| 324 | + image = pipe( |
| 325 | + prompt=self.prompt, |
| 326 | + image=condition_image, |
| 327 | + height=512, |
| 328 | + width=512, |
| 329 | + num_inference_steps=4, |
| 330 | + guidance_scale=1.0, |
| 331 | + generator=generator, |
| 332 | + max_area=2048 * 2048, |
| 333 | + output_type="np", |
| 334 | + ).images |
| 335 | + |
| 336 | + self.assertEqual(image.shape, (1, 512, 512, 3)) |
| 337 | + self.assertFalse(np.isnan(image).any(), "Output contains NaN values") |
| 338 | + self.assertTrue( |
| 339 | + (image >= 0.0).all() and (image <= 1.0).all(), |
| 340 | + "Output pixel values outside [0, 1]", |
| 341 | + ) |
0 commit comments