





import gc
import random
import unittest

import torch

from diffusers import (
    IFImgaImgPipeline,
    IFImgaImgSuperResolutionPipeline,
    IFInpaintingPipeline,
    IFInpaintingSuperResolutionPipeline,
    IFPipeline,
    IFSuperResolutionPipeline,
)
from diffusers.models.attention_processor import AttnAddedKVProcessor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import floats_tensor, load_numpy, require_torch_gpu, skip_mps, slow, torch_device

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference
from . import IFPipelineTesterMixin

@skip_mps
class 		SCREAMING_SNAKE_CASE__				(       _UpperCAmelCase						,      _UpperCAmelCase						,      unittest.TestCase  ):
      A_						:				List[str]							=    IFPipeline
      A_						:				Tuple							=    TEXT_TO_IMAGE_PARAMS - {'width', 'height', 'latents'}
      A_						:				int							=    TEXT_TO_IMAGE_BATCH_PARAMS
      A_						:				int							=    PipelineTesterMixin.required_optional_params - {'latents'}


      def    a (self       :      List[Any]      ):





         """simple docstring"""



         return self._get_dummy_components()


      def    a (self       :      Union[str, Any]				,			a__       :      Dict				,			a__       :      str=0      ):





         """simple docstring"""



         if str(a__      ).startswith('''mps'''      ):
            __snake_case							       =   torch.manual_seed(a__      )
         else:
            __snake_case							       =   torch.Generator(device=a__      ).manual_seed(a__      )

         __snake_case							       =   {
             '''prompt''': '''A painting of a squirrel eating a burger''',
             '''generator''': generator,
             '''num_inference_steps''': 2,
             '''output_type''': '''numpy''',
         }

         return inputs


      def    a (self       :      Tuple      ):





         """simple docstring"""



         self._test_save_load_optional_components()


      @unittest.skipIf(torch_device != '''cuda'''				,			reason='''float16 requires CUDA'''      )
      def    a (self       :      Union[str, Any]      ):





         """simple docstring"""



         super().test_save_load_floataa(expected_max_diff=1E-1      )


      def    a (self       :      List[str]      ):





         """simple docstring"""



         self._test_attention_slicing_forward_pass(expected_max_diff=1E-2      )


      def    a (self       :      Union[str, Any]      ):





         """simple docstring"""



         self._test_save_load_local()


      def    a (self       :      Any      ):





         """simple docstring"""



         self._test_inference_batch_single_identical(
             expected_max_diff=1E-2				,			)


      @unittest.skipIf(
          torch_device != '''cuda''' or not is_xformers_available()				,			reason='''XFormers attention is only available with CUDA and `xformers` installed'''				,			)
      def    a (self       :      Any      ):





         """simple docstring"""



         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3      )






@slow
@require_torch_gpu
class 		SCREAMING_SNAKE_CASE__				(       unittest.TestCase  ):


      def    a (self       :      Union[str, Any]      ):





         """simple docstring"""



         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()


      def    a (self       :      int      ):





         """simple docstring"""



         __snake_case							       =   IFPipeline.from_pretrained('''DeepFloyd/IF-I-XL-v1.0'''				,			variant='''fp16'''				,			torch_dtype=torch.floataa      )

         __snake_case							       =   IFSuperResolutionPipeline.from_pretrained(
             '''DeepFloyd/IF-II-L-v1.0'''				,			variant='''fp16'''				,			torch_dtype=torch.floataa				,			text_encoder=a__				,			tokenizer=a__      )

         # pre compute text embeddings and remove T5 to save memory

         pipe_a.text_encoder.to('''cuda'''      )

         __snake_case       ,	__snake_case							       =   pipe_a.encode_prompt('''anime turtle'''				,			device='''cuda'''      )

         del pipe_a.tokenizer
         del pipe_a.text_encoder
         gc.collect()

         __snake_case							       =   None
         __snake_case							       =   None

         pipe_a.enable_model_cpu_offload()
         pipe_a.enable_model_cpu_offload()

         pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()      )
         pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()      )

         self._test_if(a__				,			a__				,			a__				,			a__      )

         pipe_a.remove_all_hooks()
         pipe_a.remove_all_hooks()

         # img2img

         __snake_case							       =   IFImgaImgPipeline(**pipe_a.components      )
         __snake_case							       =   IFImgaImgSuperResolutionPipeline(**pipe_a.components      )

         pipe_a.enable_model_cpu_offload()
         pipe_a.enable_model_cpu_offload()

         pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()      )
         pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()      )

         self._test_if_imgaimg(a__				,			a__				,			a__				,			a__      )

         pipe_a.remove_all_hooks()
         pipe_a.remove_all_hooks()

         # inpainting

         __snake_case							       =   IFInpaintingPipeline(**pipe_a.components      )
         __snake_case							       =   IFInpaintingSuperResolutionPipeline(**pipe_a.components      )

         pipe_a.enable_model_cpu_offload()
         pipe_a.enable_model_cpu_offload()

         pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()      )
         pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()      )

         self._test_if_inpainting(a__				,			a__				,			a__				,			a__      )


      def    a (self       :      str				,			a__       :      Optional[Any]				,			a__       :      List[Any]				,			a__       :      Tuple				,			a__       :      Optional[int]      ):





         """simple docstring"""



         _start_torch_memory_measurement()

         __snake_case							       =   torch.Generator(device='''cpu'''      ).manual_seed(0      )
         __snake_case							       =   pipe_a(
             prompt_embeds=a__				,			negative_prompt_embeds=a__				,			num_inference_steps=2				,			generator=a__				,			output_type='''np'''				,			)

         __snake_case							       =   output.images[0]

         assert image.shape == (64, 64, 3)

         __snake_case							       =   torch.cuda.max_memory_allocated()
         assert mem_bytes < 13 * 10**9

         __snake_case							       =   load_numpy(
             '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if.npy'''      )
         assert_mean_pixel_difference(a__				,			a__      )

         # pipeline 2

         _start_torch_memory_measurement()

         __snake_case							       =   torch.Generator(device='''cpu'''      ).manual_seed(0      )

         __snake_case							       =   floats_tensor((1, 3, 64, 64)				,			rng=random.Random(0      )      ).to(a__      )

         __snake_case							       =   pipe_a(
             prompt_embeds=a__				,			negative_prompt_embeds=a__				,			image=a__				,			generator=a__				,			num_inference_steps=2				,			output_type='''np'''				,			)

         __snake_case							       =   output.images[0]

         assert image.shape == (256, 256, 3)

         __snake_case							       =   torch.cuda.max_memory_allocated()
         assert mem_bytes < 4 * 10**9

         __snake_case							       =   load_numpy(
             '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_superresolution_stage_II.npy'''      )
         assert_mean_pixel_difference(a__				,			a__      )


      def    a (self       :      str				,			a__       :      List[Any]				,			a__       :      Optional[Any]				,			a__       :      Tuple				,			a__       :      str      ):





         """simple docstring"""



         _start_torch_memory_measurement()

         __snake_case							       =   floats_tensor((1, 3, 64, 64)				,			rng=random.Random(0      )      ).to(a__      )

         __snake_case							       =   torch.Generator(device='''cpu'''      ).manual_seed(0      )

         __snake_case							       =   pipe_a(
             prompt_embeds=a__				,			negative_prompt_embeds=a__				,			image=a__				,			num_inference_steps=2				,			generator=a__				,			output_type='''np'''				,			)

         __snake_case							       =   output.images[0]

         assert image.shape == (64, 64, 3)

         __snake_case							       =   torch.cuda.max_memory_allocated()
         assert mem_bytes < 10 * 10**9

         __snake_case							       =   load_numpy(
             '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_img2img.npy'''      )
         assert_mean_pixel_difference(a__				,			a__      )

         # pipeline 2

         _start_torch_memory_measurement()

         __snake_case							       =   torch.Generator(device='''cpu'''      ).manual_seed(0      )

         __snake_case							       =   floats_tensor((1, 3, 256, 256)				,			rng=random.Random(0      )      ).to(a__      )
         __snake_case							       =   floats_tensor((1, 3, 64, 64)				,			rng=random.Random(0      )      ).to(a__      )

         __snake_case							       =   pipe_a(
             prompt_embeds=a__				,			negative_prompt_embeds=a__				,			image=a__				,			original_image=a__				,			generator=a__				,			num_inference_steps=2				,			output_type='''np'''				,			)

         __snake_case							       =   output.images[0]

         assert image.shape == (256, 256, 3)

         __snake_case							       =   torch.cuda.max_memory_allocated()
         assert mem_bytes < 4 * 10**9

         __snake_case							       =   load_numpy(
             '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_img2img_superresolution_stage_II.npy'''      )
         assert_mean_pixel_difference(a__				,			a__      )


      def    a (self       :      List[str]				,			a__       :      List[str]				,			a__       :      int				,			a__       :      Union[str, Any]				,			a__       :      int      ):





         """simple docstring"""



         _start_torch_memory_measurement()

         __snake_case							       =   floats_tensor((1, 3, 64, 64)				,			rng=random.Random(0      )      ).to(a__      )
         __snake_case							       =   floats_tensor((1, 3, 64, 64)				,			rng=random.Random(1      )      ).to(a__      )

         __snake_case							       =   torch.Generator(device='''cpu'''      ).manual_seed(0      )
         __snake_case							       =   pipe_a(
             prompt_embeds=a__				,			negative_prompt_embeds=a__				,			image=a__				,			mask_image=a__				,			num_inference_steps=2				,			generator=a__				,			output_type='''np'''				,			)

         __snake_case							       =   output.images[0]

         assert image.shape == (64, 64, 3)

         __snake_case							       =   torch.cuda.max_memory_allocated()
         assert mem_bytes < 10 * 10**9

         __snake_case							       =   load_numpy(
             '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_inpainting.npy'''      )
         assert_mean_pixel_difference(a__				,			a__      )

         # pipeline 2

         _start_torch_memory_measurement()

         __snake_case							       =   torch.Generator(device='''cpu'''      ).manual_seed(0      )

         __snake_case							       =   floats_tensor((1, 3, 64, 64)				,			rng=random.Random(0      )      ).to(a__      )
         __snake_case							       =   floats_tensor((1, 3, 256, 256)				,			rng=random.Random(0      )      ).to(a__      )
         __snake_case							       =   floats_tensor((1, 3, 256, 256)				,			rng=random.Random(1      )      ).to(a__      )

         __snake_case							       =   pipe_a(
             prompt_embeds=a__				,			negative_prompt_embeds=a__				,			image=a__				,			mask_image=a__				,			original_image=a__				,			generator=a__				,			num_inference_steps=2				,			output_type='''np'''				,			)

         __snake_case							       =   output.images[0]

         assert image.shape == (256, 256, 3)

         __snake_case							       =   torch.cuda.max_memory_allocated()
         assert mem_bytes < 4 * 10**9

         __snake_case							       =   load_numpy(
             '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_inpainting_superresolution_stage_II.npy'''      )
         assert_mean_pixel_difference(a__				,			a__      )






def lowerCamelCase__    (							)      ->				List[Any]:
   torch.cuda.empty_cache()
   torch.cuda.reset_max_memory_allocated()
   torch.cuda.reset_peak_memory_stats()








'''simple docstring'''




import os
import tempfile
import unittest

import numpy as np

from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax, slow


if is_flax_available():
  import jax
  import jax.numpy as jnp
  from flax.jax_utils import replicate
  from flax.training.common_utils import shard

  from diffusers import FlaxDDIMScheduler, FlaxDiffusionPipeline, FlaxStableDiffusionPipeline


@require_flax
class  SCREAMING_SNAKE_CASE    (unittest.TestCase							):


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          with tempfile.TemporaryDirectory() as tmpdirname:
               # pipeline has Flax weights
               __A						: Union[str, Any]      =       FlaxDiffusionPipeline.from_pretrained(
                   'hf-internal-testing/tiny-stable-diffusion-pipe'						,	safety_checker=_UpperCAmelCase						,	cache_dir=_UpperCAmelCase)

               __A						: Optional[Any]      =       [t[-1] for t in os.walk(os.path.join(_UpperCAmelCase						,	os.listdir(_UpperCAmelCase)[0]						,	'snapshots'))]
               __A						: int      =       [item for sublist in all_root_files for item in sublist]

               # None of the downloaded files should be a PyTorch file even if we have some here:
               # https://huggingface.co/hf-internal-testing/tiny-stable-diffusion-pipe/blob/main/unet/diffusion_pytorch_model.bin
               assert not any(f.endswith('.bin') for f in files)




@slow
@require_flax
class  SCREAMING_SNAKE_CASE    (unittest.TestCase							):


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: Optional[int]      =       FlaxStableDiffusionPipeline.from_pretrained(
              'hf-internal-testing/tiny-stable-diffusion-pipe'						,	safety_checker=_UpperCAmelCase)

          __A						: Dict      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: Optional[Any]      =       jax.random.PRNGKey(0)
          __A						: int      =       4

          __A						: Tuple      =       jax.device_count()
          __A						: Union[str, Any]      =       num_samples * [prompt]
          __A						: Tuple      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: str      =       replicate(_UpperCAmelCase)
          __A						: Tuple      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: Union[str, Any]      =       shard(_UpperCAmelCase)

          __A						: Union[str, Any]      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 64, 64, 3)
          if jax.device_count() == 8:
               assert np.abs(np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 4.1514745) < 1e-3
               assert np.abs(np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 49947.875) < 5e-1

          __A						: List[str]      =       pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:])))
          assert len(_UpperCAmelCase) == num_samples


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: str      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='flax'						,	safety_checker=_UpperCAmelCase)

          __A						: List[Any]      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: Tuple      =       jax.random.PRNGKey(0)
          __A						: Any      =       50

          __A						: str      =       jax.device_count()
          __A						: Union[str, Any]      =       num_samples * [prompt]
          __A						: List[str]      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: Dict      =       replicate(_UpperCAmelCase)
          __A						: Optional[Any]      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: int      =       shard(_UpperCAmelCase)

          __A						: Tuple      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 512, 512, 3)
          if jax.device_count() == 8:
               assert np.abs((np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 0.05652401)) < 1e-3
               assert np.abs((np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 2383808.2)) < 5e-1


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: List[str]      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa						,	safety_checker=_UpperCAmelCase)

          __A						: List[Any]      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: str      =       jax.random.PRNGKey(0)
          __A						: Any      =       50

          __A						: Optional[int]      =       jax.device_count()
          __A						: int      =       num_samples * [prompt]
          __A						: Optional[int]      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: Optional[int]      =       replicate(_UpperCAmelCase)
          __A						: List[str]      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: Dict      =       shard(_UpperCAmelCase)

          __A						: str      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 512, 512, 3)
          if jax.device_count() == 8:
               assert np.abs((np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 0.04003906)) < 1e-3
               assert np.abs((np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 2373516.75)) < 5e-1


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: Optional[Any]      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa)

          __A						: Union[str, Any]      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: Any      =       jax.random.PRNGKey(0)
          __A						: List[str]      =       50

          __A						: Optional[int]      =       jax.device_count()
          __A						: List[Any]      =       num_samples * [prompt]
          __A						: List[Any]      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: Union[str, Any]      =       replicate(_UpperCAmelCase)
          __A						: Optional[Any]      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: List[str]      =       shard(_UpperCAmelCase)

          __A						: int      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 512, 512, 3)
          if jax.device_count() == 8:
               assert np.abs((np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 0.04003906)) < 1e-3
               assert np.abs((np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 2373516.75)) < 5e-1


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: List[Any]      =       FlaxDDIMScheduler(
              beta_start=0.00085						,	beta_end=0.012						,	beta_schedule='scaled_linear'						,	set_alpha_to_one=_UpperCAmelCase						,	steps_offset=1						,	)

          __A ,__A						: Any      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa						,	scheduler=_UpperCAmelCase						,	safety_checker=_UpperCAmelCase						,	)
          __A						: Optional[Any]      =       scheduler.create_state()

          __A						: Any      =       scheduler_state

          __A						: List[str]      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: Union[str, Any]      =       jax.random.PRNGKey(0)
          __A						: Optional[int]      =       50

          __A						: Optional[Any]      =       jax.device_count()
          __A						: Any      =       num_samples * [prompt]
          __A						: Optional[Any]      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: int      =       replicate(_UpperCAmelCase)
          __A						: Any      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: Tuple      =       shard(_UpperCAmelCase)

          __A						: Union[str, Any]      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 512, 512, 3)
          if jax.device_count() == 8:
               assert np.abs((np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 0.045043945)) < 1e-3
               assert np.abs((np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 2347693.5)) < 5e-1


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Dict      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: int      =       jax.device_count()
          __A						: List[Any]      =       num_samples * [prompt]
          __A						: List[Any]      =       jax.random.split(jax.random.PRNGKey(0)						,	_UpperCAmelCase)

          __A ,__A						: Tuple      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa						,	safety_checker=_UpperCAmelCase						,	)

          __A						: str      =       replicate(_UpperCAmelCase)
          __A						: str      =       pipeline.prepare_inputs(_UpperCAmelCase)
          __A						: str      =       shard(_UpperCAmelCase)
          __A						: int      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images
          assert images.shape == (num_samples, 1, 512, 512, 3)
          __A						: Any      =       images[2, 0, 256, 10:17, 1]

          # With memory efficient attention
          __A ,__A						: str      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa						,	safety_checker=_UpperCAmelCase						,	use_memory_efficient_attention=_UpperCAmelCase						,	)

          __A						: Any      =       replicate(_UpperCAmelCase)
          __A						: List[Any]      =       pipeline.prepare_inputs(_UpperCAmelCase)
          __A						: Optional[Any]      =       shard(_UpperCAmelCase)
          __A						: List[Any]      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images
          assert images_eff.shape == (num_samples, 1, 512, 512, 3)
          __A						: List[Any]      =       images[2, 0, 256, 10:17, 1]

          # I checked the results visually and they are very similar. However, I saw that the max diff is `1` and the `sum`
          # over the 8 images is exactly `256`, which is very suspicious. Testing a random slice for now.
          assert abs(slice_eff - slice).max() < 1e-2