



'''simple docstring'''







from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


SCREAMING_SNAKE_CASE__     : int				=   logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__     : Tuple				=   {
    "facebook/mbart-large-cc25": "https://huggingface.co/facebook/mbart-large-cc25/resolve/main/config.json",
    # See all MBART models at https://huggingface.co/models?filter=mbart
}




class 				__lowerCAmelCase(							SCREAMING_SNAKE_CASE__      ):
			__snake_case  :		List[str]		=      'mbart'
			__snake_case  :		str		=      ['past_key_values']
			__snake_case  :		List[str]		=      {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}






			def __init__(   self  :							Tuple      ,       SCREAMING_SNAKE_CASE  :							Union[str, Any]=50_265      ,       SCREAMING_SNAKE_CASE  :							Union[str, Any]=1_024      ,       SCREAMING_SNAKE_CASE  :							Optional[int]=12      ,       SCREAMING_SNAKE_CASE  :							str=4_096      ,       SCREAMING_SNAKE_CASE  :							Optional[Any]=16      ,       SCREAMING_SNAKE_CASE  :							str=12      ,       SCREAMING_SNAKE_CASE  :							Union[str, Any]=4_096      ,       SCREAMING_SNAKE_CASE  :							List[Any]=16      ,       SCREAMING_SNAKE_CASE  :							Optional[Any]=0.0      ,       SCREAMING_SNAKE_CASE  :							int=0.0      ,       SCREAMING_SNAKE_CASE  :							Any=True      ,       SCREAMING_SNAKE_CASE  :							Optional[Any]=True      ,       SCREAMING_SNAKE_CASE  :							Any="gelu"      ,       SCREAMING_SNAKE_CASE  :							int=1_024      ,       SCREAMING_SNAKE_CASE  :							Any=0.1      ,       SCREAMING_SNAKE_CASE  :							Optional[int]=0.0      ,       SCREAMING_SNAKE_CASE  :							Tuple=0.0      ,       SCREAMING_SNAKE_CASE  :							Optional[Any]=0.02      ,       SCREAMING_SNAKE_CASE  :							Any=0.0      ,       SCREAMING_SNAKE_CASE  :							Optional[Any]=False      ,       SCREAMING_SNAKE_CASE  :							Any=1      ,       SCREAMING_SNAKE_CASE  :							Optional[Any]=0      ,       SCREAMING_SNAKE_CASE  :							List[str]=2      ,       SCREAMING_SNAKE_CASE  :							Any=2      ,       **SCREAMING_SNAKE_CASE  :							int      ,       ):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:str										=      vocab_size
					SCREAMING_SNAKE_CASE_						:List[str]										=      max_position_embeddings
					SCREAMING_SNAKE_CASE_						:List[Any]										=      d_model
					SCREAMING_SNAKE_CASE_						:List[str]										=      encoder_ffn_dim
					SCREAMING_SNAKE_CASE_						:Any										=      encoder_layers
					SCREAMING_SNAKE_CASE_						:List[str]										=      encoder_attention_heads
					SCREAMING_SNAKE_CASE_						:List[str]										=      decoder_ffn_dim
					SCREAMING_SNAKE_CASE_						:Optional[Any]										=      decoder_layers
					SCREAMING_SNAKE_CASE_						:Any										=      decoder_attention_heads
					SCREAMING_SNAKE_CASE_						:List[Any]										=      dropout
					SCREAMING_SNAKE_CASE_						:Dict										=      attention_dropout
					SCREAMING_SNAKE_CASE_						:List[str]										=      activation_dropout
					SCREAMING_SNAKE_CASE_						:str										=      activation_function
					SCREAMING_SNAKE_CASE_						:Optional[Any]										=      init_std
					SCREAMING_SNAKE_CASE_						:Optional[Any]										=      encoder_layerdrop
					SCREAMING_SNAKE_CASE_						:int										=      decoder_layerdrop
					SCREAMING_SNAKE_CASE_						:List[str]										=      classifier_dropout
					SCREAMING_SNAKE_CASE_						:Any										=      use_cache
					SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      encoder_layers
					SCREAMING_SNAKE_CASE_						:Optional[Any]										=      scale_embedding  # scale factor will be sqrt(d_model) if True
					super().__init__(
					    pad_token_id=a_      ,       bos_token_id=a_      ,       eos_token_id=a_      ,       is_encoder_decoder=a_      ,       forced_eos_token_id=a_      ,       **a_      ,       )




class 				__lowerCAmelCase(							SCREAMING_SNAKE_CASE__      ):






			@property
			def 				_lowercase	(   self  :							Optional[Any]	):




					"""simple docstring"""







					if self.task in ["default", "seq2seq-lm"]:
							SCREAMING_SNAKE_CASE_						:Optional[Any]										=      OrderedDict(
							    [
							        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
							        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
							    ]	)

							if self.use_past:
									SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      {0: 'batch'}
									SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      {0: 'batch', 1: 'past_decoder_sequence + sequence'}
							else:
									SCREAMING_SNAKE_CASE_						:str										=      {0: 'batch', 1: 'decoder_sequence'}
									SCREAMING_SNAKE_CASE_						:Tuple										=      {0: 'batch', 1: 'decoder_sequence'}

							if self.use_past:
									self.fill_with_past_key_values_(a_      ,       direction='inputs'	)
					elif self.task == "causal-lm":
							# TODO: figure this case out.
							SCREAMING_SNAKE_CASE_						:Dict										=      OrderedDict(
							    [
							        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
							        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
							    ]	)
							if self.use_past:
									SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:Dict										=      self.num_layers
									for i in range(a_	):
											SCREAMING_SNAKE_CASE_						:Dict										=      {0: 'batch', 2: 'past_sequence + sequence'}
											SCREAMING_SNAKE_CASE_						:str										=      {0: 'batch', 2: 'past_sequence + sequence'}
					else:
							SCREAMING_SNAKE_CASE_						:Optional[Any]										=      OrderedDict(
							    [
							        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
							        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
							        ('decoder_input_ids', {0: 'batch', 1: 'decoder_sequence'}),
							        ('decoder_attention_mask', {0: 'batch', 1: 'decoder_sequence'}),
							    ]	)

					return common_inputs






			@property
			def 				_lowercase	(   self  :							Any	):




					"""simple docstring"""







					if self.task in ["default", "seq2seq-lm"]:
							SCREAMING_SNAKE_CASE_						:Optional[Any]										=      super().outputs
					else:
							SCREAMING_SNAKE_CASE_						:List[Any]										=      super(a_      ,       self	).outputs
							if self.use_past:
									SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:List[Any]										=      self.num_layers
									for i in range(a_	):
											SCREAMING_SNAKE_CASE_						:Any										=      {0: 'batch', 2: 'past_sequence + sequence'}
											SCREAMING_SNAKE_CASE_						:Optional[Any]										=      {0: 'batch', 2: 'past_sequence + sequence'}
					return common_outputs






			def 				_lowercase	(   self  :							str      ,       SCREAMING_SNAKE_CASE  :							PreTrainedTokenizer      ,       SCREAMING_SNAKE_CASE  :							int = -1      ,       SCREAMING_SNAKE_CASE  :							int = -1      ,       SCREAMING_SNAKE_CASE  :							bool = False      ,       SCREAMING_SNAKE_CASE  :							Optional[TensorType] = None      ,       ):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Tuple										=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
					    a_      ,       a_      ,       a_      ,       a_      ,       a_	)

					# Generate decoder inputs
					SCREAMING_SNAKE_CASE_						:List[Any]										=      seq_length if not self.use_past else 1
					SCREAMING_SNAKE_CASE_						:List[Any]										=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
					    a_      ,       a_      ,       a_      ,       a_      ,       a_	)
					SCREAMING_SNAKE_CASE_						:Dict										=      {f'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
					SCREAMING_SNAKE_CASE_						:Tuple										=      dict(**a_      ,       **a_	)

					if self.use_past:
							if not is_torch_available():
									raise ValueError('Cannot generate dummy past_keys inputs without PyTorch installed.'	)
							else:
									import torch
							SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:int										=      common_inputs['input_ids'].shape
							SCREAMING_SNAKE_CASE_						:List[Any]										=      common_inputs['decoder_input_ids'].shape[1]
							SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:str										=      self.num_attention_heads
							SCREAMING_SNAKE_CASE_						:int										=      (
							    batch,
							    num_encoder_attention_heads,
							    encoder_seq_length,
							    self._config.hidden_size // num_encoder_attention_heads,
							)
							SCREAMING_SNAKE_CASE_						:List[Any]										=      decoder_seq_length + 3
							SCREAMING_SNAKE_CASE_						:str										=      (
							    batch,
							    num_decoder_attention_heads,
							    decoder_past_length,
							    self._config.hidden_size // num_decoder_attention_heads,
							)

							SCREAMING_SNAKE_CASE_						:Optional[int]										=      torch.cat(
							    [common_inputs['decoder_attention_mask'], torch.ones(a_      ,       a_	)]      ,       dim=1	)

							SCREAMING_SNAKE_CASE_						:int										=      []
							# If the number of encoder and decoder layers are present in the model configuration, both are considered
							SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:str										=      self.num_layers
							SCREAMING_SNAKE_CASE_						:Any										=      min(a_      ,       a_	)
							SCREAMING_SNAKE_CASE_						:Dict										=      max(a_      ,       a_	) - min_num_layers
							SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      'encoder' if num_encoder_layers > num_decoder_layers else 'decoder'

							for _ in range(a_	):
									common_inputs["past_key_values"].append(
									    (
									        torch.zeros(a_	),
									        torch.zeros(a_	),
									        torch.zeros(a_	),
									        torch.zeros(a_	),
									    )	)
							# TODO: test this.
							SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      encoder_shape if remaining_side_name == 'encoder' else decoder_shape
							for _ in range(a_      ,       a_	):
									common_inputs["past_key_values"].append((torch.zeros(a_	), torch.zeros(a_	))	)
					return common_inputs






			def 				_lowercase	(   self  :							Optional[int]      ,       SCREAMING_SNAKE_CASE  :							PreTrainedTokenizer      ,       SCREAMING_SNAKE_CASE  :							int = -1      ,       SCREAMING_SNAKE_CASE  :							int = -1      ,       SCREAMING_SNAKE_CASE  :							bool = False      ,       SCREAMING_SNAKE_CASE  :							Optional[TensorType] = None      ,       ):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
					    a_      ,       a_      ,       a_      ,       a_      ,       a_	)

					if self.use_past:
							if not is_torch_available():
									raise ValueError('Cannot generate dummy past_keys inputs without PyTorch installed.'	)
							else:
									import torch
							SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:str										=      common_inputs['input_ids'].shape
							# Not using the same length for past_key_values
							SCREAMING_SNAKE_CASE_						:List[str]										=      seqlen + 2
							SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:List[Any]										=      self.num_layers
							SCREAMING_SNAKE_CASE_						,		SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      self.num_attention_heads
							SCREAMING_SNAKE_CASE_						:Union[str, Any]										=      (
							    batch,
							    num_encoder_attention_heads,
							    past_key_values_length,
							    self._config.hidden_size // num_encoder_attention_heads,
							)

							SCREAMING_SNAKE_CASE_						:Any										=      common_inputs['attention_mask'].dtype
							SCREAMING_SNAKE_CASE_						:List[str]										=      torch.cat(
							    [common_inputs['attention_mask'], torch.ones(a_      ,       a_      ,       dtype=a_	)]      ,       dim=1	)
							SCREAMING_SNAKE_CASE_						:List[str]										=      [
							    (torch.zeros(a_	), torch.zeros(a_	)) for _ in range(a_	)
							]
					return common_inputs






			def 				_lowercase	(   self  :							List[Any]      ,       SCREAMING_SNAKE_CASE  :							PreTrainedTokenizer      ,       SCREAMING_SNAKE_CASE  :							int = -1      ,       SCREAMING_SNAKE_CASE  :							int = -1      ,       SCREAMING_SNAKE_CASE  :							bool = False      ,       SCREAMING_SNAKE_CASE  :							Optional[TensorType] = None      ,       ):




					"""simple docstring"""







					SCREAMING_SNAKE_CASE_						:Dict										=      compute_effective_axis_dimension(
					    a_      ,       fixed_dimension=OnnxConfig.default_fixed_batch      ,       num_token_to_add=0	)

					# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
					SCREAMING_SNAKE_CASE_						:str										=      tokenizer.num_special_tokens_to_add(a_	)
					SCREAMING_SNAKE_CASE_						:int										=      compute_effective_axis_dimension(
					    a_      ,       fixed_dimension=OnnxConfig.default_fixed_sequence      ,       num_token_to_add=a_	)

					# Generate dummy inputs according to compute batch and sequence
					SCREAMING_SNAKE_CASE_						:List[str]										=      [' '.join([tokenizer.unk_token]	) * seq_length] * batch_size
					SCREAMING_SNAKE_CASE_						:List[Any]										=      dict(tokenizer(a_      ,       return_tensors=a_	)	)
					return common_inputs






			def 				_lowercase	(   self  :							Union[str, Any]      ,       SCREAMING_SNAKE_CASE  :							PreTrainedTokenizer      ,       SCREAMING_SNAKE_CASE  :							int = -1      ,       SCREAMING_SNAKE_CASE  :							int = -1      ,       SCREAMING_SNAKE_CASE  :							bool = False      ,       SCREAMING_SNAKE_CASE  :							Optional[TensorType] = None      ,       ):




					"""simple docstring"""







					if self.task in ["default", "seq2seq-lm"]:
							SCREAMING_SNAKE_CASE_						:Dict										=      self._generate_dummy_inputs_for_default_and_seqaseq_lm(
							    a_      ,       batch_size=a_      ,       seq_length=a_      ,       is_pair=a_      ,       framework=a_	)

					elif self.task == "causal-lm":
							SCREAMING_SNAKE_CASE_						:List[Any]										=      self._generate_dummy_inputs_for_causal_lm(
							    a_      ,       batch_size=a_      ,       seq_length=a_      ,       is_pair=a_      ,       framework=a_	)
					else:
							SCREAMING_SNAKE_CASE_						:Dict										=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    a_      ,       batch_size=a_      ,       seq_length=a_      ,       is_pair=a_      ,       framework=a_	)

					return common_inputs






			def 				_lowercase	(   self  :							Dict      ,       SCREAMING_SNAKE_CASE  :							int      ,       SCREAMING_SNAKE_CASE  :							str      ,       SCREAMING_SNAKE_CASE  :							List[Any]      ,       SCREAMING_SNAKE_CASE  :							int	):




					"""simple docstring"""







					if self.task in ["default", "seq2seq-lm"]:
							SCREAMING_SNAKE_CASE_						:List[str]										=      super()._flatten_past_key_values_(a_      ,       a_      ,       a_      ,       a_	)
					else:
							SCREAMING_SNAKE_CASE_						:List[str]										=      super(a_      ,       self	)._flatten_past_key_values_(
							    a_      ,       a_      ,       a_      ,       a_	)




'''simple docstring'''

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 			UpperCAmelCase			(							SCREAMING_SNAKE_CASE__		,      unittest.TestCase):
 _lowerCamelCase			:       List[Any]            =       KandinskyVaaPriorEmbaEmbPipeline
 _lowerCamelCase			:       Tuple            =       ['prompt', 'image']
 _lowerCamelCase			:       List[str]            =       ['prompt', 'image']
 _lowerCamelCase			:       List[str]            =       [
     'num_images_per_prompt',
     'strength',
     'generator',
     'num_inference_steps',
     'latents',
     'negative_prompt',
     'guidance_scale',
     'output_type',
     'return_dict',
 ]
 _lowerCamelCase			:       List[str]            =       False

 @property
 def 		lowercase_    (			self			:						int       ):





    """simple docstring"""



    return 32

 @property
 def 		lowercase_    (			self			:						Union[str, Any]       ):





    """simple docstring"""



    return 32

 @property
 def 		lowercase_    (			self			:						Any       ):





    """simple docstring"""



    return self.time_input_dim

 @property
 def 		lowercase_    (			self			:						Dict       ):





    """simple docstring"""



    return self.time_input_dim * 4

 @property
 def 		lowercase_    (			self			:						str       ):





    """simple docstring"""



    return 100

 @property
 def 		lowercase_    (			self			:						Any       ):





    """simple docstring"""



    UpperCamelCase__			    =    CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"       )
    return tokenizer

 @property
 def 		lowercase_    (			self			:						Optional[int]       ):





    """simple docstring"""



    torch.manual_seed(0       )
    UpperCamelCase__			    =    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-0_5,       num_attention_heads=4,       num_hidden_layers=5,       pad_token_id=1,       vocab_size=1000,       )
    return CLIPTextModelWithProjection(a_       )

 @property
 def 		lowercase_    (			self			:						str       ):





    """simple docstring"""



    torch.manual_seed(0       )

    UpperCamelCase__			    =    {
        "num_attention_heads": 2,
        "attention_head_dim": 12,
        "embedding_dim": self.text_embedder_hidden_size,
        "num_layers": 1,
    }

    UpperCamelCase__			    =    PriorTransformer(**a_       )
    # 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
    UpperCamelCase__			    =    nn.Parameter(torch.ones(model.clip_std.shape       )       )
    return model

 @property
 def 		lowercase_    (			self			:						Any       ):





    """simple docstring"""



    torch.manual_seed(0       )
    UpperCamelCase__			    =    CLIPVisionConfig(
        hidden_size=self.text_embedder_hidden_size,       image_size=224,       projection_dim=self.text_embedder_hidden_size,       intermediate_size=37,       num_attention_heads=4,       num_channels=3,       num_hidden_layers=5,       patch_size=14,       )

    UpperCamelCase__			    =    CLIPVisionModelWithProjection(a_       )
    return model

 @property
 def 		lowercase_    (			self			:						Dict       ):





    """simple docstring"""



    UpperCamelCase__			    =    CLIPImageProcessor(
        crop_size=224,       do_center_crop=a_,       do_normalize=a_,       do_resize=a_,       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=224,       )

    return image_processor

 def 		lowercase_    (			self			:						Optional[int]       ):





    """simple docstring"""



    UpperCamelCase__			    =    self.dummy_prior
    UpperCamelCase__			    =    self.dummy_image_encoder
    UpperCamelCase__			    =    self.dummy_text_encoder
    UpperCamelCase__			    =    self.dummy_tokenizer
    UpperCamelCase__			    =    self.dummy_image_processor

    UpperCamelCase__			    =    UnCLIPScheduler(
        variance_type="fixed_small_log",       prediction_type="sample",       num_train_timesteps=1000,       clip_sample=a_,       clip_sample_range=10.0,       )

    UpperCamelCase__			    =    {
        "prior": prior,
        "image_encoder": image_encoder,
        "text_encoder": text_encoder,
        "tokenizer": tokenizer,
        "scheduler": scheduler,
        "image_processor": image_processor,
    }

    return components

 def 		lowercase_    (			self			:						Union[str, Any],       a_			:						List[str],       a_			:						Union[str, Any]=0       ):





    """simple docstring"""



    if str(a_       ).startswith("mps"       ):
       UpperCamelCase__			    =    torch.manual_seed(a_       )
    else:
       UpperCamelCase__			    =    torch.Generator(device=a_       ).manual_seed(a_       )

    UpperCamelCase__			    =    floats_tensor((1, 3, 64, 64),       rng=random.Random(a_       )       ).to(a_       )
    UpperCamelCase__			    =    image.cpu().permute(0,       2,       3,       1       )[0]
    UpperCamelCase__			    =    Image.fromarray(np.uinta(a_       )       ).convert("RGB"       ).resize((256, 256)       )

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

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





    """simple docstring"""



    UpperCamelCase__			    =    "cpu"

    UpperCamelCase__			    =    self.get_dummy_components()

    UpperCamelCase__			    =    self.pipeline_class(**a_       )
    UpperCamelCase__			    =    pipe.to(a_       )

    pipe.set_progress_bar_config(disable=a_       )

    UpperCamelCase__			    =    pipe(**self.get_dummy_inputs(a_       )       )
    UpperCamelCase__			    =    output.image_embeds

    UpperCamelCase__			    =    pipe(
        **self.get_dummy_inputs(a_       ),       return_dict=a_,       )[0]

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

    assert image.shape == (1, 32)

    UpperCamelCase__			    =    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 		lowercase_    (			self			:						Optional[int]       ):





    """simple docstring"""



    UpperCamelCase__			    =    torch_device == "cpu"
    UpperCamelCase__			    =    True
    UpperCamelCase__			    =    False

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

 @skip_mps
 def 		lowercase_    (			self			:						Optional[int]       ):





    """simple docstring"""



    UpperCamelCase__			    =    torch_device == "cpu"
    UpperCamelCase__			    =    False

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