


import argparse
import collections

import jax
import jax.numpy as jnp
import torch
import torch.nn as nn
from clip.model import CLIP
from flax.training import checkpoints
from huggingface_hub import Repository

from transformers import (
    CLIPTokenizer,
    OwlViTConfig,
    OwlViTForObjectDetection,
    OwlViTImageProcessor,
    OwlViTModel,
    OwlViTProcessor,
)


UpperCAmelCase     =       {
    """vit_b32""": {
        """embed_dim""": 512,
        """image_resolution""": 768,
        """context_length""": 16,
        """vocab_size""": 4_9408,
        """vision_layers""": 12,
        """vision_width""": 768,
        """vision_patch_size""": 32,
        """transformer_width""": 512,
        """transformer_heads""": 8,
        """transformer_layers""": 12,
    },
    """vit_b16""": {
        """embed_dim""": 512,
        """image_resolution""": 768,
        """context_length""": 16,
        """vocab_size""": 4_9408,
        """vision_layers""": 12,
        """vision_width""": 768,
        """vision_patch_size""": 16,
        """transformer_width""": 512,
        """transformer_heads""": 8,
        """transformer_layers""": 12,
    },
    """vit_l14""": {
        """embed_dim""": 768,
        """image_resolution""": 840,
        """context_length""": 16,
        """vocab_size""": 4_9408,
        """vision_layers""": 24,
        """vision_width""": 1024,
        """vision_patch_size""": 14,
        """transformer_width""": 768,
        """transformer_heads""": 12,
        """transformer_layers""": 12,
    },
}






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE=""   ,   SCREAMING_SNAKE_CASE="/"   )->    Tuple:




      """simple docstring"""

      snake_case_			= []

      for k, v in params.items():
            snake_case_			= parent_key + sep + k if parent_key else k

            if isinstance(SCREAMING_SNAKE_CASE   ,   collections.MutableMapping   ):
                  items.extend(flatten_nested_dict(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ,   sep=SCREAMING_SNAKE_CASE   ).items()   )
            else:
                  items.append((new_key, v)   )
      return dict(SCREAMING_SNAKE_CASE   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   )->    Optional[int]:




      """simple docstring"""

      return jax.tree_util.tree_map(lambda SCREAMING_SNAKE_CASE   : x.astype(jnp.floataa   ) if x.dtype == jnp.bfloataa else x   ,   SCREAMING_SNAKE_CASE   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    List[str]:




      """simple docstring"""

      snake_case_			,       snake_case_			,       snake_case_			= pt_attn_layer.in_proj_weight.chunk(3   ,   dim=0   )
      snake_case_			,       snake_case_			,       snake_case_			= pt_attn_layer.in_proj_bias.chunk(3   ,   dim=0   )

      snake_case_			= pt_attn_layer.out_proj.weight
      snake_case_			= pt_attn_layer.out_proj.bias

      snake_case_			= q_proj
      snake_case_			= q_proj_bias

      snake_case_			= k_proj
      snake_case_			= k_proj_bias

      snake_case_			= v_proj
      snake_case_			= v_proj_bias

      snake_case_			= out_proj_weights
      snake_case_			= out_proj_bias






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    Optional[Any]:




      """simple docstring"""

      copy_linear(hf_mlp.fca   ,   pt_mlp.c_fc   )
      copy_linear(hf_mlp.fca   ,   pt_mlp.c_proj   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    Optional[Any]:




      """simple docstring"""

      snake_case_			= pt_linear.weight
      snake_case_			= pt_linear.bias






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    int:




      """simple docstring"""

      copy_linear(hf_layer.layer_norma   ,   pt_layer.ln_a   )
      copy_linear(hf_layer.layer_norma   ,   pt_layer.ln_a   )

      # copy MLP
      copy_mlp(hf_layer.mlp   ,   pt_layer.mlp   )

      # copy attn
      copy_attn_layer(hf_layer.self_attn   ,   pt_layer.attn   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    List[Any]:




      """simple docstring"""

      for hf_layer, pt_layer in zip(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ):
            copy_layer(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    List[str]:




      """simple docstring"""

      snake_case_			= pt_model.token_embedding.weight
      snake_case_			= pt_model.positional_embedding

      # copy layer norm
      copy_linear(hf_encoder.final_layer_norm   ,   pt_model.ln_final   )

      # copy hidden layers
      copy_layers(hf_encoder.encoder.layers   ,   pt_model.transformer.resblocks   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    List[Any]:




      """simple docstring"""

      snake_case_			= pt_model.text_projection.data.T

      # copy text encoder
      copy_encoder(hf_model.text_model   ,   SCREAMING_SNAKE_CASE   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    List[Any]:




      """simple docstring"""

      snake_case_			= pt_model.visual.proj.data.T

      # copy layer norms
      copy_linear(hf_model.vision_model.pre_layernorm   ,   pt_model.visual.ln_pre   )
      copy_linear(hf_model.vision_model.post_layernorm   ,   pt_model.visual.ln_post   )

      # copy embeds
      snake_case_			= pt_model.visual.conva.weight.data
      snake_case_			= pt_model.visual.class_embedding
      snake_case_			= pt_model.visual.positional_embedding.data

      # copy encoder
      copy_layers(hf_model.vision_model.encoder.layers   ,   pt_model.visual.transformer.resblocks   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    Optional[int]:




      """simple docstring"""

      snake_case_			= flatten_nested_dict(flax_params['''backbone''']['''merged_class_token''']   )

      snake_case_			= torch.from_numpy(flax_class_token_params['''scale''']   )
      snake_case_			= torch.from_numpy(flax_class_token_params['''bias''']   )
      snake_case_			= nn.Parameter(SCREAMING_SNAKE_CASE   )
      snake_case_			= nn.Parameter(SCREAMING_SNAKE_CASE   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    Any:




      """simple docstring"""

      snake_case_			= hf_model.state_dict()
      snake_case_			= {}

      # Rename class prediction head flax params to pytorch HF
      snake_case_			= flatten_nested_dict(flax_params['''class_head''']   )

      for flax_key, v in flax_class_params.items():
            snake_case_			= flax_key.replace('''/'''   ,   '''.'''   )
            snake_case_			= torch_key.replace('''.kernel'''   ,   '''.weight'''   )
            snake_case_			= torch_key.replace('''Dense_0'''   ,   '''dense0'''   )
            snake_case_			= '''class_head.''' + torch_key

            if "weight" in torch_key and v.ndim == 2:
                  snake_case_			= v.T

            snake_case_			= nn.Parameter(torch.from_numpy(SCREAMING_SNAKE_CASE   )   )

      # Rename box prediction box flax params to pytorch HF
      snake_case_			= flatten_nested_dict(flax_params['''obj_box_head''']   )

      for flax_key, v in flax_box_params.items():
            snake_case_			= flax_key.replace('''/'''   ,   '''.'''   )
            snake_case_			= torch_key.replace('''.kernel'''   ,   '''.weight'''   )
            snake_case_			= torch_key.replace('''_'''   ,   ''''''   ).lower()
            snake_case_			= '''box_head.''' + torch_key

            if "weight" in torch_key and v.ndim == 2:
                  snake_case_			= v.T

            snake_case_			= nn.Parameter(torch.from_numpy(SCREAMING_SNAKE_CASE   )   )

      # Copy flax params to PyTorch params
      for name, param in new_params.items():
            if name in pt_params.keys():
                  pt_params[name].copy_(SCREAMING_SNAKE_CASE   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    Union[str, Any]:




      """simple docstring"""

      for k, v in flax_attn_params.items():
            if k.startswith('''transformer'''   ):
                  snake_case_			= k.replace('''transformer.resblocks'''   ,   '''text_model.encoder.layers'''   )
            else:
                  snake_case_			= k.replace('''visual.transformer.resblocks'''   ,   '''vision_model.encoder.layers'''   )

            snake_case_			= torch_key.replace('''attn'''   ,   '''self_attn'''   )
            snake_case_			= torch_key.replace('''key'''   ,   '''k_proj'''   )
            snake_case_			= torch_key.replace('''value'''   ,   '''v_proj'''   )
            snake_case_			= torch_key.replace('''query'''   ,   '''q_proj'''   )
            snake_case_			= torch_key.replace('''out'''   ,   '''out_proj'''   )

            if "bias" in torch_key and v.ndim == 2:
                  snake_case_			= v.shape[0] * v.shape[1]
                  snake_case_			= v.reshape(SCREAMING_SNAKE_CASE   )

            if "weight" in torch_key and "out" in torch_key:
                  snake_case_			= (v.shape[0] * v.shape[1], v.shape[2])
                  snake_case_			= v.reshape(SCREAMING_SNAKE_CASE   ).T

            if "weight" in torch_key and "out" not in torch_key:
                  snake_case_			= (v.shape[0], v.shape[1] * v.shape[2])
                  snake_case_			= v.reshape(SCREAMING_SNAKE_CASE   ).T

            # Copy flax CLIP attn params to HF PyTorch params
            snake_case_			= torch.from_numpy(SCREAMING_SNAKE_CASE   )
            hf_backbone.state_dict()[torch_key].copy_(SCREAMING_SNAKE_CASE   )






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   )->    Union[str, Any]:




      """simple docstring"""

      snake_case_			= {}
      snake_case_			= []

      for k, v in params.items():
            if "attn." in k:
                  snake_case_			= k[: k.rindex('''attn.'''   ) + 5]
                  if base in processed_attn_layers:
                        continue

                  processed_attn_layers.append(SCREAMING_SNAKE_CASE   )
                  snake_case_			= params[base + '''out.weight'''].shape[-1]
                  snake_case_			= params[base + '''out.weight'''].reshape(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ).T
                  snake_case_			= params[base + '''out.bias''']
            else:
                  snake_case_			= v
      return new_params






def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )->    Any:




      """simple docstring"""

      snake_case_			= CLIP(**SCREAMING_SNAKE_CASE   )
      torch_model.eval()
      snake_case_			= torch_model.state_dict()

      snake_case_			= flatten_nested_dict(flax_params['''backbone''']['''clip''']   )
      snake_case_			= {}

      for flax_key, v in flax_clip_params.items():
            snake_case_			= flax_key.replace('''/'''   ,   '''.'''   )
            snake_case_			= torch_key.replace('''text.token_embedding.embedding'''   ,   '''token_embedding.kernel'''   )

            if (
                torch_key.startswith('''text.transformer'''   )
                or torch_key.startswith('''text.text_projection'''   )
                or torch_key.startswith('''text.ln_final'''   )
                or torch_key.startswith('''text.positional_embedding'''   )
            ):
                  snake_case_			= torch_key[5:]

            snake_case_			= torch_key.replace('''text_projection.kernel'''   ,   '''text_projection'''   )
            snake_case_			= torch_key.replace('''visual.proj.kernel'''   ,   '''visual.proj'''   )
            snake_case_			= torch_key.replace('''.scale'''   ,   '''.weight'''   )
            snake_case_			= torch_key.replace('''.kernel'''   ,   '''.weight'''   )

            if "conv" in torch_key or "downsample.0.weight" in torch_key:
                  snake_case_			= v.transpose(3   ,   2   ,   0   ,   1   )

            elif "weight" in torch_key and v.ndim == 2 and "embedding" not in torch_key:
                  # Fully connected layers are transposed, embeddings are not
                  snake_case_			= v.T

            snake_case_			= v

      snake_case_			= _convert_attn_layers(SCREAMING_SNAKE_CASE   )
      new_torch_params.update(SCREAMING_SNAKE_CASE   )
      snake_case_			= {}

      # Copy flax CLIP backbone params to PyTorch params
      for name, param in new_torch_params.items():
            if name in torch_clip_params.keys():
                  snake_case_			= torch.from_numpy(new_torch_params[name]   )
                  torch_clip_params[name].copy_(SCREAMING_SNAKE_CASE   )
            else:
                  snake_case_			= param

      return torch_clip_params, torch_model, attn_params






@torch.no_grad()
def 			__lowerCAmelCase       (SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE=None   )->    Tuple:




      """simple docstring"""

      snake_case_			= Repository(SCREAMING_SNAKE_CASE   ,   clone_from=f'''google/{pytorch_dump_folder_path}'''   )
      repo.git_pull()

      if config_path is not None:
            snake_case_			= OwlViTConfig.from_pretrained(SCREAMING_SNAKE_CASE   )
      else:
            snake_case_			= OwlViTConfig()

      snake_case_			= OwlViTModel(SCREAMING_SNAKE_CASE   ).eval()
      snake_case_			= OwlViTForObjectDetection(SCREAMING_SNAKE_CASE   ).eval()

      copy_text_model_and_projection(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )
      copy_vision_model_and_projection(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )
      snake_case_			= pt_backbone.logit_scale
      copy_flax_attn_params(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )

      snake_case_			= hf_backbone
      copy_class_merge_token(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )
      copy_class_box_heads(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )

      # Save HF model
      hf_model.save_pretrained(repo.local_dir   )

      # Initialize image processor
      snake_case_			= OwlViTImageProcessor(
          size=config.vision_config.image_size   ,   crop_size=config.vision_config.image_size   )
      # Initialize tokenizer
      snake_case_			= CLIPTokenizer.from_pretrained('''openai/clip-vit-base-patch32'''   ,   pad_token='''!'''   ,   model_max_length=16   )

      # Initialize processor
      snake_case_			= OwlViTProcessor(image_processor=SCREAMING_SNAKE_CASE   ,   tokenizer=SCREAMING_SNAKE_CASE   )
      image_processor.save_pretrained(repo.local_dir   )
      processor.save_pretrained(repo.local_dir   )

      repo.git_add()
      repo.git_commit('''Upload model and processor'''   )
      repo.git_push()


if __name__ == "__main__":
   UpperCAmelCase     =       argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       """--owlvit_version""",
       default=None,
       type=str,
       required=True,
       help="""OWL-ViT model name [clip_b16, clip_b32, clip_l14].""",
   )
   parser.add_argument(
       """--owlvit_checkpoint""", default=None, type=str, required=True, help="""Path to flax model checkpoint."""
   )
   parser.add_argument("""--hf_config""", default=None, type=str, required=True, help="""Path to HF model config.""")
   parser.add_argument(
       """--pytorch_dump_folder_path""", default="""hf_model""", type=str, help="""Path to the output PyTorch model."""
   )
   UpperCAmelCase     =       parser.parse_args()

   # Initialize PyToch clip model
   UpperCAmelCase     =       args.owlvit_version
   if model_name == "clip_b16":
      UpperCAmelCase     =       CONFIGS["""vit_b16"""]
   elif model_name == "clip_b32":
      UpperCAmelCase     =       CONFIGS["""vit_b32"""]
   elif model_name == "clip_l14":
      UpperCAmelCase     =       CONFIGS["""vit_l14"""]

   # Load from checkpoint and convert params to float-32
   UpperCAmelCase     =       checkpoints.restore_checkpoint(args.owlvit_checkpoint, target=None)["""optimizer"""]["""target"""]
   UpperCAmelCase     =       jax.tree_util.tree_map(lambda x: x.astype(jnp.floataa) if x.dtype == jnp.bfloataa else x, variables)
   del variables

   # Convert CLIP backbone
   UpperCAmelCase,				UpperCAmelCase,				UpperCAmelCase     =       convert_clip_backbone(flax_params, torch_config)

   convert_owlvit_checkpoint(clip_pt, flax_params, attn_params, args.pytorch_dump_folder_path, args.hf_config)



import random
import unittest

import numpy as np
import torch
from PIL import Image
from torch import nn
from transformers import (
    CLIPImageProcessor,
    CLIPTextConfig,
    CLIPTextModelWithProjection,
    CLIPTokenizer,
    CLIPVisionConfig,
    CLIPVisionModelWithProjection,
)

from diffusers import KandinskyVaaPriorEmbaEmbPipeline, PriorTransformer, UnCLIPScheduler
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, skip_mps

from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()







class lowerCAmelCase_		(					lowerCamelCase__   ,		unittest.TestCase			):

 '''simple docstring'''

 __snake_case				=    KandinskyVaaPriorEmbaEmbPipeline
 __snake_case				=    ["prompt", "image"]
 __snake_case				=    ["prompt", "image"]
 __snake_case				=    [
     "num_images_per_prompt",
     "strength",
     "generator",
     "num_inference_steps",
     "latents",
     "negative_prompt",
     "guidance_scale",
     "output_type",
     "return_dict",
 ]
 __snake_case				=    False



 @property
 def 		UpperCamelCase__	(      self   ):
       return 32



 @property
 def 		UpperCamelCase__	(      self   ):
       return 32



 @property
 def 		UpperCamelCase__	(      self   ):
       return self.time_input_dim



 @property
 def 		UpperCamelCase__	(      self   ):
       return self.time_input_dim * 4



 @property
 def 		UpperCamelCase__	(      self   ):
       return 1_00



 @property
 def 		UpperCamelCase__	(      self   ):
       snake_case_			= CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''   )
       return tokenizer



 @property
 def 		UpperCamelCase__	(      self   ):
       torch.manual_seed(0   )
       snake_case_			= CLIPTextConfig(
           bos_token_id=0						, eos_token_id=2						, hidden_size=self.text_embedder_hidden_size						, projection_dim=self.text_embedder_hidden_size						, intermediate_size=37						, layer_norm_eps=1E-05						, num_attention_heads=4						, num_hidden_layers=5						, pad_token_id=1						, vocab_size=10_00						, )
       return CLIPTextModelWithProjection(_UpperCAmelCase   )



 @property
 def 		UpperCamelCase__	(      self   ):
       torch.manual_seed(0   )

       snake_case_			= {
           '''num_attention_heads''': 2,
           '''attention_head_dim''': 12,
           '''embedding_dim''': self.text_embedder_hidden_size,
           '''num_layers''': 1,
       }

       snake_case_			= PriorTransformer(**_UpperCAmelCase   )
       # clip_std and clip_mean is initialized to be 0 so PriorTransformer.post_process_latents will always return 0 - set clip_std to be 1 so it won't return 0
       snake_case_			= nn.Parameter(torch.ones(model.clip_std.shape   )   )
       return model



 @property
 def 		UpperCamelCase__	(      self   ):
       torch.manual_seed(0   )
       snake_case_			= CLIPVisionConfig(
           hidden_size=self.text_embedder_hidden_size						, image_size=2_24						, projection_dim=self.text_embedder_hidden_size						, intermediate_size=37						, num_attention_heads=4						, num_channels=3						, num_hidden_layers=5						, patch_size=14						, )

       snake_case_			= CLIPVisionModelWithProjection(_UpperCAmelCase   )
       return model



 @property
 def 		UpperCamelCase__	(      self   ):
       snake_case_			= CLIPImageProcessor(
           crop_size=2_24						, do_center_crop=_UpperCAmelCase						, do_normalize=_UpperCAmelCase						, do_resize=_UpperCAmelCase						, image_mean=[0.48_145_466, 0.4_578_275, 0.40_821_073]						, image_std=[0.26_862_954, 0.26_130_258, 0.27_577_711]						, resample=3						, size=2_24						, )

       return image_processor



 def 		UpperCamelCase__	(      self   ):
       snake_case_			= self.dummy_prior
       snake_case_			= self.dummy_image_encoder
       snake_case_			= self.dummy_text_encoder
       snake_case_			= self.dummy_tokenizer
       snake_case_			= self.dummy_image_processor

       snake_case_			= UnCLIPScheduler(
           variance_type='''fixed_small_log'''						, prediction_type='''sample'''						, num_train_timesteps=10_00						, clip_sample=_UpperCAmelCase						, clip_sample_range=10.0						, )

       snake_case_			= {
           '''prior''': prior,
           '''image_encoder''': image_encoder,
           '''text_encoder''': text_encoder,
           '''tokenizer''': tokenizer,
           '''scheduler''': scheduler,
           '''image_processor''': image_processor,
       }

       return components



 def 		UpperCamelCase__	(      self						, _UpperCAmelCase						, _UpperCAmelCase=0   ):
       if str(_UpperCAmelCase   ).startswith('''mps'''   ):
             snake_case_			= torch.manual_seed(_UpperCAmelCase   )
       else:
             snake_case_			= torch.Generator(device=_UpperCAmelCase   ).manual_seed(_UpperCAmelCase   )

       snake_case_			= floats_tensor((1, 3, 64, 64)						, rng=random.Random(_UpperCAmelCase   )   ).to(_UpperCAmelCase   )
       snake_case_			= image.cpu().permute(0						, 2						, 3						, 1   )[0]
       snake_case_			= Image.fromarray(np.uinta(_UpperCAmelCase   )   ).convert('''RGB'''   ).resize((2_56, 2_56)   )

       snake_case_			= {
           '''prompt''': '''horse''',
           '''image''': init_image,
           '''strength''': 0.5,
           '''generator''': generator,
           '''guidance_scale''': 4.0,
           '''num_inference_steps''': 2,
           '''output_type''': '''np''',
       }
       return inputs



 def 		UpperCamelCase__	(      self   ):
       snake_case_			= '''cpu'''

       snake_case_			= self.get_dummy_components()

       snake_case_			= self.pipeline_class(**_UpperCAmelCase   )
       snake_case_			= pipe.to(_UpperCAmelCase   )

       pipe.set_progress_bar_config(disable=_UpperCAmelCase   )

       snake_case_			= pipe(**self.get_dummy_inputs(_UpperCAmelCase   )   )
       snake_case_			= output.image_embeds

       snake_case_			= pipe(
           **self.get_dummy_inputs(_UpperCAmelCase   )						, return_dict=_UpperCAmelCase						, )[0]

       snake_case_			= image[0, -10:]
       snake_case_			= image_from_tuple[0, -10:]

       assert image.shape == (1, 32)

       snake_case_			= np.array(
           [
               0.1_071_284,
               1.3_330_271,
               0.61_260_223,
               -0.6_691_065,
               -0.3_846_852,
               -1.0_303_661,
               0.22_716_111,
               0.03_348_901,
               0.30_040_675,
               -0.24_805_029,
           ]   )

       assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2
       assert np.abs(image_from_tuple_slice.flatten() - expected_slice   ).max() < 1E-2



 @skip_mps
 def 		UpperCamelCase__	(      self   ):
       snake_case_			= torch_device == '''cpu'''
       snake_case_			= True
       snake_case_			= False

       self._test_inference_batch_single_identical(
           test_max_difference=_UpperCAmelCase						, relax_max_difference=_UpperCAmelCase						, test_mean_pixel_difference=_UpperCAmelCase						, )





 @skip_mps
 def 		UpperCamelCase__	(      self   ):
       snake_case_			= torch_device == '''cpu'''
       snake_case_			= False

       self._test_attention_slicing_forward_pass(
           test_max_difference=_UpperCAmelCase						, test_mean_pixel_difference=_UpperCAmelCase						, )