





import copy
import tempfile
import unittest

from transformers import MaMaaaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import MaMaaaForConditionalGeneration, MaMaaaModel, MaMaaaTokenizer
 from transformers.models.mam_aaa.modeling_mam_aaa import MaMaaaDecoder, MaMaaaEncoder

def   __snake_case    (       _lowerCAmelCase			:			Optional[int]					,					_lowerCAmelCase			:			Tuple					,					_lowerCAmelCase			:			Optional[Any]					,					_lowerCAmelCase			:			Tuple=None					,					_lowerCAmelCase			:			List[str]=None					,					_lowerCAmelCase			:			Union[str, Any]=None					,					_lowerCAmelCase			:			List[str]=None					,					_lowerCAmelCase			:			Union[str, Any]=None					,					)			->    Any:
   if attention_mask is None:
      A_       :					Any        =      input_ids.ne(config.pad_token_id						)
   if decoder_attention_mask is None:
      A_       :					List[str]        =      decoder_input_ids.ne(config.pad_token_id						)
   if head_mask is None:
      A_       :					Union[str, Any]        =      torch.ones(config.encoder_layers					,					config.encoder_attention_heads					,					device=_lowerCAmelCase						)
   if decoder_head_mask is None:
      A_       :					List[str]        =      torch.ones(config.decoder_layers					,					config.decoder_attention_heads					,					device=_lowerCAmelCase						)
   if cross_attn_head_mask is None:
      A_       :					List[str]        =      torch.ones(config.decoder_layers					,					config.decoder_attention_heads					,					device=_lowerCAmelCase						)
   return {
       "input_ids": input_ids,
       "decoder_input_ids": decoder_input_ids,
       "attention_mask": attention_mask,
       "decoder_attention_mask": attention_mask,
       "head_mask": head_mask,
       "decoder_head_mask": decoder_head_mask,
       "cross_attn_head_mask": cross_attn_head_mask,
   }


class        __magic_name__	:





     """simple docstring"""



     def __init__(				self							:Optional[Any]      ,   snake_case							:List[Any]      ,   snake_case							:int=13      ,   snake_case							:List[Any]=7      ,   snake_case							:Optional[int]=True      ,   snake_case							:int=False      ,   snake_case							:Optional[int]=99      ,   snake_case							:Optional[int]=16      ,   snake_case							:Any=2      ,   snake_case							:Dict=4      ,   snake_case							:Any=4      ,   snake_case							:int="relu"      ,   snake_case							:str=0.1      ,   snake_case							:List[str]=0.1      ,   snake_case							:Tuple=0.0      ,   snake_case							:Tuple=0.0      ,   snake_case							:str=20      ,   snake_case							:str=2      ,   snake_case							:Union[str, Any]=1      ,   snake_case							:List[str]=0      ,   ):





        '''simple docstring'''




        A_       :					Optional[int]        =      parent
        A_       :					Any        =      batch_size
        A_       :					List[str]        =      seq_length
        A_       :					Any        =      is_training
        A_       :					str        =      use_labels
        A_       :					Tuple        =      vocab_size
        A_       :					List[Any]        =      hidden_size
        A_       :					Optional[int]        =      num_hidden_layers
        A_       :					int        =      num_attention_heads
        A_       :					List[Any]        =      intermediate_size
        A_       :					Optional[Any]        =      hidden_act
        A_       :					str        =      hidden_dropout_prob
        A_       :					Optional[int]        =      attention_probs_dropout_prob
        A_       :					List[str]        =      encoder_layerdrop
        A_       :					Optional[int]        =      decoder_layerdrop
        A_       :					str        =      max_position_embeddings
        A_       :					Optional[Any]        =      eos_token_id
        A_       :					List[Any]        =      pad_token_id
        A_       :					Union[str, Any]        =      bos_token_id



     def     SCREAMING_SNAKE_CASE		(				self							:Any	):





        '''simple docstring'''




        A_       :					Tuple        =      ids_tensor([self.batch_size, self.seq_length]      ,   self.vocab_size	)
        A_       :					Dict        =      self.eos_token_id  # Eos Token
        A_       :					List[Any]        =      ids_tensor([self.batch_size, self.seq_length]      ,   self.vocab_size	)

        # we need to clamp the input ids here to avoid having pad token in between
        # this is because for M2M100 the position_ids are prepared such that
        # all pad tokens have pos id = 2 and rest are between 2..seq_length
        # and the seq_length here is seq_length - num_pad_tokens
        # but when using past, there is no way of knowing if the past input ids had
        # pad tokens in them, which results in incorrect seq_lenth and which in turn results in
        # position_ids being off by num_pad_tokens in past input
        A_       :					Optional[int]        =      input_ids.clamp(self.pad_token_id + 1	)
        A_       :					Optional[int]        =      decoder_input_ids.clamp(self.pad_token_id + 1	)

        A_       :					Union[str, Any]        =      self.get_config()
        A_       :					Any        =      prepare_mam_aaa_inputs_dict(snake_case      ,   snake_case      ,   snake_case	)
        return config, inputs_dict



     def     SCREAMING_SNAKE_CASE		(				self							:Any	):





        '''simple docstring'''




        return MaMaaaConfig(
            vocab_size=self.vocab_size      ,   d_model=self.hidden_size      ,   encoder_layers=self.num_hidden_layers      ,   decoder_layers=self.num_hidden_layers      ,   encoder_attention_heads=self.num_attention_heads      ,   decoder_attention_heads=self.num_attention_heads      ,   encoder_ffn_dim=self.intermediate_size      ,   decoder_ffn_dim=self.intermediate_size      ,   dropout=self.hidden_dropout_prob      ,   attention_dropout=self.attention_probs_dropout_prob      ,   encoder_layerdrop=self.encoder_layerdrop      ,   decoder_layerdrop=self.decoder_layerdrop      ,   max_position_embeddings=self.max_position_embeddings      ,   eos_token_id=self.eos_token_id      ,   bos_token_id=self.bos_token_id      ,   pad_token_id=self.pad_token_id      ,   )



     def     SCREAMING_SNAKE_CASE		(				self							:Dict	):





        '''simple docstring'''




        A_   ,    A_       :					str        =      self.prepare_config_and_inputs()
        return config, inputs_dict



     def     SCREAMING_SNAKE_CASE		(				self							:int      ,   snake_case							:Any      ,   snake_case							:Any	):





        '''simple docstring'''




        A_       :					Tuple        =      MaMaaaModel(config=snake_case	).get_decoder().to(snake_case	).eval()
        A_       :					Dict        =      inputs_dict["input_ids"]
        A_       :					Union[str, Any]        =      inputs_dict["attention_mask"]
        A_       :					Union[str, Any]        =      inputs_dict["head_mask"]

        # first forward pass
        A_       :					Union[str, Any]        =      model(snake_case      ,   attention_mask=snake_case      ,   head_mask=snake_case      ,   use_cache=snake_case	)

        A_   ,    A_       :					Dict        =      outputs.to_tuple()

        # create hypothetical multiple next token and extent to next_input_ids
        A_       :					int        =      ids_tensor((self.batch_size, 3)      ,   config.vocab_size	)
        A_       :					List[str]        =      ids_tensor((self.batch_size, 3)      ,   2	)

        # append to next input_ids and
        A_       :					Optional[Any]        =      torch.cat([input_ids, next_tokens]      ,   dim=-1	)
        A_       :					List[Any]        =      torch.cat([attention_mask, next_attn_mask]      ,   dim=-1	)

        A_       :					List[str]        =      model(snake_case      ,   attention_mask=snake_case	)["last_hidden_state"]
        A_       :					Dict        =      model(snake_case      ,   attention_mask=snake_case      ,   past_key_values=snake_case	)[
            "last_hidden_state"
        ]

        # select random slice
        A_       :					Optional[Any]        =      ids_tensor((1,)      ,   output_from_past.shape[-1]	).item()
        A_       :					Optional[int]        =      output_from_no_past[:, -3:, random_slice_idx].detach()
        A_       :					List[Any]        =      output_from_past[:, :, random_slice_idx].detach()

        self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]	)

        # test that outputs are equal for slice
        self.parent.assertTrue(torch.allclose(snake_case      ,   snake_case      ,   atol=1e-2	)	)





     def     SCREAMING_SNAKE_CASE		(				self							:Any      ,   snake_case							:Any      ,   snake_case							:Any	):





        '''simple docstring'''




        A_       :					Dict        =      MaMaaaModel(config=snake_case	).to(snake_case	).eval()
        A_       :					int        =      model(**snake_case	)

        A_       :					Dict        =      outputs.encoder_last_hidden_state
        A_       :					List[Any]        =      outputs.last_hidden_state

        with tempfile.TemporaryDirectory() as tmpdirname:
           A_       :					int        =      model.get_encoder()
           encoder.save_pretrained(snake_case	)
           A_       :					Any        =      MaMaaaEncoder.from_pretrained(snake_case	).to(snake_case	)

        A_       :					List[Any]        =      encoder(inputs_dict["input_ids"]      ,   attention_mask=inputs_dict["attention_mask"]	)[
            0
        ]

        self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1e-3	)

        with tempfile.TemporaryDirectory() as tmpdirname:
           A_       :					str        =      model.get_decoder()
           decoder.save_pretrained(snake_case	)
           A_       :					List[Any]        =      MaMaaaDecoder.from_pretrained(snake_case	).to(snake_case	)

        A_       :					Tuple        =      decoder(
            input_ids=inputs_dict["decoder_input_ids"]      ,   attention_mask=inputs_dict["decoder_attention_mask"]      ,   encoder_hidden_states=snake_case      ,   encoder_attention_mask=inputs_dict["attention_mask"]      ,   )[0]

        self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1e-3	)




@require_torch
class        __magic_name__	(				lowerCamelCase__     ,					lowerCamelCase__     ,					lowerCamelCase__     ,					unittest.TestCase				):





     """simple docstring"""



     __UpperCamelCase            =  (
         (
             MaMaaaModel,
             MaMaaaForConditionalGeneration,
         )
         if is_torch_available()
         else ()
     )
     __UpperCamelCase            =  (MaMaaaForConditionalGeneration,) if is_torch_available() else ()
     __UpperCamelCase            =  (
         {
             '''conversational''': MaMaaaForConditionalGeneration,
             '''feature-extraction''': MaMaaaModel,
             '''summarization''': MaMaaaForConditionalGeneration,
             '''text2text-generation''': MaMaaaForConditionalGeneration,
             '''translation''': MaMaaaForConditionalGeneration,
         }
         if is_torch_available()
         else {}
     )
     __UpperCamelCase            =  True
     __UpperCamelCase            =  True
     __UpperCamelCase            =  False
     __UpperCamelCase            =  False



     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]      ,   snake_case							:List[Any]      ,   snake_case							:Tuple      ,   snake_case							:Optional[int]      ,   snake_case							:Optional[int]      ,   snake_case							:str	):





        '''simple docstring'''




        if pipeline_test_casse_name == "TranslationPipelineTests":
           # Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`.
           # `M2M100Config` was never used in pipeline tests: cannot create a simple tokenizer.
           return True

        return False



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





        '''simple docstring'''




        A_       :					Dict        =      MaMaaaModelTester(self	)
        A_       :					List[str]        =      ConfigTester(self      ,   config_class=snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]	):





        '''simple docstring'''




        self.config_tester.run_common_tests()



     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]	):





        '''simple docstring'''




        A_   ,    A_       :					List[str]        =      self.model_tester.prepare_config_and_inputs()
        for model_class in self.all_model_classes:
           A_       :					Union[str, Any]        =      model_class(snake_case	)

           with tempfile.TemporaryDirectory() as tmpdirname:
              model.save_pretrained(snake_case	)
              A_   ,    A_       :					Dict        =      model_class.from_pretrained(snake_case      ,   output_loading_info=snake_case	)
           self.assertEqual(info["missing_keys"]      ,   []	)



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





        '''simple docstring'''




        A_       :					List[str]        =      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_decoder_model_past_large_inputs(*snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        A_       :					List[str]        =      self.model_tester.prepare_config_and_inputs_for_common()
        self.model_tester.check_encoder_decoder_model_standalone(*snake_case	)



     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]	):





        '''simple docstring'''




        A_   ,    A_       :					int        =      self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
           A_       :					List[Any]        =      model_class(snake_case	)
           model.to(snake_case	)
           model.eval()

           A_       :					List[Any]        =      copy.deepcopy(self._prepare_for_class(snake_case      ,   snake_case	)	)

           if not self.is_encoder_decoder:
              A_       :					Dict        =      inputs["input_ids"]
              del inputs["input_ids"]
           else:
              A_       :					Dict        =      inputs["input_ids"]
              A_       :					List[str]        =      inputs.get("decoder_input_ids"      ,   snake_case	)
              del inputs["input_ids"]
              inputs.pop("decoder_input_ids"      ,   snake_case	)

           A_       :					Dict        =      model.get_input_embeddings()
           if not self.is_encoder_decoder:
              A_       :					Tuple        =      wte(snake_case	)
           else:
              A_       :					List[Any]        =      wte(snake_case	)
              A_       :					Tuple        =      wte(snake_case	)

           with torch.no_grad():
              model(**snake_case	)[0]





     def     SCREAMING_SNAKE_CASE		(				self							:str	):





        '''simple docstring'''




        A_   ,    A_       :					Optional[Any]        =      self.model_tester.prepare_config_and_inputs()
        A_       :					Tuple        =      input_dict["input_ids"]
        A_       :					List[Any]        =      input_ids.ne(1	).to(snake_case	)
        A_       :					List[Any]        =      MaMaaaForConditionalGeneration(snake_case	).eval().to(snake_case	)
        if torch_device == "cuda":
           model.half()
        model.generate(snake_case      ,   attention_mask=snake_case	)
        model.generate(num_beams=4      ,   do_sample=snake_case      ,   early_stopping=snake_case      ,   num_return_sequences=3	)




def   __snake_case    (       _lowerCAmelCase			:			int						)			->    Union[str, Any]:
   return torch.tensor(_lowerCAmelCase					,					dtype=torch.long					,					device=_lowerCAmelCase						)


_lowerCAmelCase				:   Optional[Any]						       =						1e-4





@require_torch
@require_sentencepiece
@require_tokenizers
@slow
class        __magic_name__	(				unittest.TestCase				):





     """simple docstring"""



     @cached_property
     def     SCREAMING_SNAKE_CASE		(				self							:Optional[int]	):





        '''simple docstring'''




        return MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"	)



     def     SCREAMING_SNAKE_CASE		(				self							:List[str]	):





        '''simple docstring'''




        A_       :					Any        =      MaMaaaModel.from_pretrained("facebook/m2m100_418M"	).to(snake_case	)
        A_       :					int        =      _long_tensor([[128_028, 98, 12, 30_527, 2_732, 159, 7_755, 61_904, 39_144, 38, 2]]	)
        A_       :					Union[str, Any]        =      _long_tensor([[2, 128_028, 98, 12, 30_527, 2_732, 159, 7_755, 61_904, 39_144, 38]]	)
        A_       :					Dict        =      prepare_mam_aaa_inputs_dict(model.config      ,   snake_case      ,   snake_case	)
        with torch.no_grad():
           A_       :					Optional[Any]        =      model(**snake_case	)[0]
        A_       :					str        =      torch.Size((1, 11, 1_024)	)
        self.assertEqual(output.shape      ,   snake_case	)
        # change to expected output here
        A_       :					Union[str, Any]        =      torch.tensor(
            [[-0.7780, -0.1676, 0.1038], [-6.7556, -1.3992, 0.0567], [-7.5383, -0.5920, -0.2779]]      ,   device=snake_case	)
        self.assertTrue(torch.allclose(output[:, :3, :3]      ,   snake_case      ,   atol=snake_case	)	)



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





        '''simple docstring'''




        A_       :					Optional[int]        =      MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"	).to(snake_case	)

        # change to intended input
        A_       :					int        =      _long_tensor([[128_028, 98, 12, 30_527, 2_732, 159, 7_755, 61_904, 39_144, 38, 2]]	)
        A_       :					List[Any]        =      _long_tensor([[2, 128_028, 98, 12, 30_527, 2_732, 159, 7_755, 61_904, 39_144, 38]]	)
        A_       :					Any        =      prepare_mam_aaa_inputs_dict(model.config      ,   snake_case      ,   snake_case	)
        with torch.no_grad():
           A_       :					Optional[int]        =      model(**snake_case	)[0]
        A_       :					int        =      torch.Size((1, 11, model.config.vocab_size)	)
        self.assertEqual(output.shape      ,   snake_case	)
        # change to expected output here
        A_       :					str        =      torch.tensor(
            [[-1.0448, -1.0411, 3.7992], [-3.2191, -3.2386, -1.3451], [-3.6210, -3.5993, 0.4925]]      ,   device=snake_case	)
        self.assertTrue(torch.allclose(output[:, :3, :3]      ,   snake_case      ,   atol=snake_case	)	)





     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]	):





        '''simple docstring'''




        A_       :					Union[str, Any]        =      MaMaaaForConditionalGeneration.from_pretrained("facebook/m2m100_418M"	).to(snake_case	)
        A_       :					Optional[Any]        =      MaMaaaTokenizer.from_pretrained("facebook/m2m100_418M"      ,   src_lang="fr"      ,   tgt_lang="en"	)

        A_       :					Optional[Any]        =      [
            "L'affaire NSA souligne l'absence totale de débat sur le renseignement",
            "Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.",
            "Lorsque François Hollande téléphone à Barack Obama ou quand le ministre des affaires étrangères Laurent"
            " Fabius convoque l'ambassadeur des Etats-Unis, ils réagissent à une vraie découverte, qui est celle de"
            " l'ampleur de la surveillance américaine sur l'ensemble des communications en France.",
        ]

        # The below article tests that we don't add any hypotheses outside of the top n_beams
        A_       :					str        =      tokenizer(snake_case      ,   padding=snake_case      ,   return_tensors="pt"	)

        A_       :					Union[str, Any]        =      model.generate(
            input_ids=dct["input_ids"].to(snake_case	)      ,   attention_mask=dct["attention_mask"].to(snake_case	)      ,   num_beams=5      ,   forced_bos_token_id=tokenizer.get_lang_id("en"	)      ,   )

        A_       :					str        =      [
            "The NSA case highlights the total absence of intelligence debate",
            "I think there are two levels of response from the French government.",
            "When François Hollande calls Barack Obama or when Foreign Minister Laurent Fabius calls the U.S."
            " Ambassador, they respond to a real discovery, which is that of the scale of U.S. surveillance on all"
            " communications in France.",
        ]

        A_       :					Tuple        =      tokenizer.batch_decode(
            hypotheses_batch.tolist()      ,   clean_up_tokenization_spaces=snake_case      ,   skip_special_tokens=snake_case	)
        assert generated == expected_en







import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel

from diffusers import DDIMScheduler, LDMPipeline, UNetaDModel, VQModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()


class        __magic_name__	(				unittest.TestCase				):





     """simple docstring"""



     @property
     def     SCREAMING_SNAKE_CASE		(				self							:List[str]	):





        '''simple docstring'''




        torch.manual_seed(0	)
        A_       :					Optional[Any]        =      UNetaDModel(
            block_out_channels=(32, 64)      ,   layers_per_block=2      ,   sample_size=32      ,   in_channels=3      ,   out_channels=3      ,   down_block_types=("DownBlock2D", "AttnDownBlock2D")      ,   up_block_types=("AttnUpBlock2D", "UpBlock2D")      ,   )
        return model



     @property
     def     SCREAMING_SNAKE_CASE		(				self							:int	):





        '''simple docstring'''




        torch.manual_seed(0	)
        A_       :					Any        =      VQModel(
            block_out_channels=[32, 64]      ,   in_channels=3      ,   out_channels=3      ,   down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]      ,   up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]      ,   latent_channels=3      ,   )
        return model



     @property
     def     SCREAMING_SNAKE_CASE		(				self							:Any	):





        '''simple docstring'''




        torch.manual_seed(0	)
        A_       :					int        =      CLIPTextConfig(
            bos_token_id=0      ,   eos_token_id=2      ,   hidden_size=32      ,   intermediate_size=37      ,   layer_norm_eps=1e-05      ,   num_attention_heads=4      ,   num_hidden_layers=5      ,   pad_token_id=1      ,   vocab_size=1_000      ,   )
        return CLIPTextModel(snake_case	)





     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        A_       :					Dict        =      self.dummy_uncond_unet
        A_       :					Any        =      DDIMScheduler()
        A_       :					List[str]        =      self.dummy_vq_model

        A_       :					Union[str, Any]        =      LDMPipeline(unet=snake_case      ,   vqvae=snake_case      ,   scheduler=snake_case	)
        ldm.to(snake_case	)
        ldm.set_progress_bar_config(disable=snake_case	)

        A_       :					Any        =      torch.manual_seed(0	)
        A_       :					Optional[Any]        =      ldm(generator=snake_case      ,   num_inference_steps=2      ,   output_type="numpy"	).images

        A_       :					Dict        =      torch.manual_seed(0	)
        A_       :					Any        =      ldm(generator=snake_case      ,   num_inference_steps=2      ,   output_type="numpy"      ,   return_dict=snake_case	)[0]

        A_       :					int        =      image[0, -3:, -3:, -1]
        A_       :					Any        =      image_from_tuple[0, -3:, -3:, -1]

        assert image.shape == (1, 64, 64, 3)
        A_       :					str        =      np.array([0.8512, 0.818, 0.6411, 0.6808, 0.4465, 0.5618, 0.46, 0.6231, 0.5172]	)
        A_       :					List[str]        =      1e-2 if torch_device != "mps" else 3e-2

        assert np.abs(image_slice.flatten() - expected_slice	).max() < tolerance
        assert np.abs(image_from_tuple_slice.flatten() - expected_slice	).max() < tolerance




@slow
@require_torch
class        __magic_name__	(				unittest.TestCase				):





     """simple docstring"""



     def     SCREAMING_SNAKE_CASE		(				self							:Tuple	):





        '''simple docstring'''




        A_       :					int        =      LDMPipeline.from_pretrained("CompVis/ldm-celebahq-256"	)
        ldm.to(snake_case	)
        ldm.set_progress_bar_config(disable=snake_case	)

        A_       :					int        =      torch.manual_seed(0	)
        A_       :					List[str]        =      ldm(generator=snake_case      ,   num_inference_steps=5      ,   output_type="numpy"	).images

        A_       :					Tuple        =      image[0, -3:, -3:, -1]

        assert image.shape == (1, 256, 256, 3)
        A_       :					Any        =      np.array([0.4399, 0.44975, 0.46825, 0.474, 0.4359, 0.4581, 0.45095, 0.4341, 0.4447]	)
        A_       :					List[Any]        =      1e-2 if torch_device != "mps" else 3e-2

        assert np.abs(image_slice.flatten() - expected_slice	).max() < tolerance
