



from __future__ import annotations

import inspect
import unittest

import numpy as np

from transformers import DeiTConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
  import tensorflow as tf

  from transformers import (
      TFDeiTForImageClassification,
      TFDeiTForImageClassificationWithTeacher,
      TFDeiTForMaskedImageModeling,
      TFDeiTModel,
  )
  from transformers.models.deit.modeling_tf_deit import TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image

  from transformers import DeiTImageProcessor
class    lowercase__     :







       '''simple docstring'''


       def __init__(							self    :						List[Any]	,       _UpperCAmelCase    :						List[Any]	,       _UpperCAmelCase    :						str=13	,       _UpperCAmelCase    :						List[Any]=30	,       _UpperCAmelCase    :						str=2	,       _UpperCAmelCase    :						List[str]=3	,       _UpperCAmelCase    :						Any=True	,       _UpperCAmelCase    :						Dict=True	,       _UpperCAmelCase    :						Optional[Any]=32	,       _UpperCAmelCase    :						List[Any]=2	,       _UpperCAmelCase    :						Optional[int]=4	,       _UpperCAmelCase    :						Optional[Any]=37	,       _UpperCAmelCase    :						Any="gelu"	,       _UpperCAmelCase    :						List[Any]=0.1	,       _UpperCAmelCase    :						Tuple=0.1	,       _UpperCAmelCase    :						Optional[int]=10	,       _UpperCAmelCase    :						Optional[int]=0.02	,       _UpperCAmelCase    :						List[Any]=3	,       _UpperCAmelCase    :						Tuple=None	,       _UpperCAmelCase    :						Any=2	,       )				->		Optional[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							parent
             UpperCAmelCase_    				=							batch_size
             UpperCAmelCase_    				=							image_size
             UpperCAmelCase_    				=							patch_size
             UpperCAmelCase_    				=							num_channels
             UpperCAmelCase_    				=							is_training
             UpperCAmelCase_    				=							use_labels
             UpperCAmelCase_    				=							hidden_size
             UpperCAmelCase_    				=							num_hidden_layers
             UpperCAmelCase_    				=							num_attention_heads
             UpperCAmelCase_    				=							intermediate_size
             UpperCAmelCase_    				=							hidden_act
             UpperCAmelCase_    				=							hidden_dropout_prob
             UpperCAmelCase_    				=							attention_probs_dropout_prob
             UpperCAmelCase_    				=							type_sequence_label_size
             UpperCAmelCase_    				=							initializer_range
             UpperCAmelCase_    				=							scope
             UpperCAmelCase_    				=							encoder_stride

             # in DeiT, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distilation tokens)
             UpperCAmelCase_    				=							(image_size // patch_size) ** 2
             UpperCAmelCase_    				=							num_patches + 2



       def   lowercase__       (							self    :						List[str]					)				->		Dict:


             '''simple docstring'''




             UpperCAmelCase_    				=							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

             UpperCAmelCase_    				=							None
             if self.use_labels:
                   UpperCAmelCase_    				=							ids_tensor([self.batch_size]	,       self.type_sequence_label_size					)

             UpperCAmelCase_    				=							self.get_config()

             return config, pixel_values, labels



       def   lowercase__       (							self    :						Dict					)				->		Optional[Any]:


             '''simple docstring'''




             return DeiTConfig(
                 image_size=self.image_size	,       patch_size=self.patch_size	,       num_channels=self.num_channels	,       hidden_size=self.hidden_size	,       num_hidden_layers=self.num_hidden_layers	,       num_attention_heads=self.num_attention_heads	,       intermediate_size=self.intermediate_size	,       hidden_act=self.hidden_act	,       hidden_dropout_prob=self.hidden_dropout_prob	,       attention_probs_dropout_prob=self.attention_probs_dropout_prob	,       is_decoder=_SCREAMING_SNAKE_CASE	,       initializer_range=self.initializer_range	,       encoder_stride=self.encoder_stride	,       )



       def   lowercase__       (							self    :						Union[str, Any]	,       _UpperCAmelCase    :						str	,       _UpperCAmelCase    :						List[Any]	,       _UpperCAmelCase    :						str					)				->		List[str]:


             '''simple docstring'''




             UpperCAmelCase_    				=							TFDeiTModel(config=_SCREAMING_SNAKE_CASE					)
             UpperCAmelCase_    				=							model(_SCREAMING_SNAKE_CASE					)
             self.parent.assertEqual(result.last_hidden_state.shape	,       (self.batch_size, self.seq_length, self.hidden_size)					)



       def   lowercase__       (							self    :						List[Any]	,       _UpperCAmelCase    :						str	,       _UpperCAmelCase    :						Optional[Any]	,       _UpperCAmelCase    :						Tuple					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_    				=							TFDeiTForMaskedImageModeling(config=_SCREAMING_SNAKE_CASE					)
             UpperCAmelCase_    				=							model(_SCREAMING_SNAKE_CASE					)
             self.parent.assertEqual(
                 result.reconstruction.shape	,       (self.batch_size, self.num_channels, self.image_size, self.image_size)					)

             # test greyscale images
             UpperCAmelCase_    				=							1
             UpperCAmelCase_    				=							TFDeiTForMaskedImageModeling(_SCREAMING_SNAKE_CASE					)

             UpperCAmelCase_    				=							floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
             UpperCAmelCase_    				=							model(_SCREAMING_SNAKE_CASE					)
             self.parent.assertEqual(result.reconstruction.shape	,       (self.batch_size, 1, self.image_size, self.image_size)					)



       def   lowercase__       (							self    :						List[Any]	,       _UpperCAmelCase    :						str	,       _UpperCAmelCase    :						Tuple	,       _UpperCAmelCase    :						List[Any]					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.type_sequence_label_size
             UpperCAmelCase_    				=							TFDeiTForImageClassification(_SCREAMING_SNAKE_CASE					)
             UpperCAmelCase_    				=							model(_SCREAMING_SNAKE_CASE	,       labels=_SCREAMING_SNAKE_CASE					)
             self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.type_sequence_label_size)					)

             # test greyscale images
             UpperCAmelCase_    				=							1
             UpperCAmelCase_    				=							TFDeiTForImageClassification(_SCREAMING_SNAKE_CASE					)

             UpperCAmelCase_    				=							floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
             UpperCAmelCase_    				=							model(_SCREAMING_SNAKE_CASE	,       labels=_SCREAMING_SNAKE_CASE					)
             self.parent.assertEqual(result.logits.shape	,       (self.batch_size, self.type_sequence_label_size)					)







       def   lowercase__       (							self    :						Tuple					)				->		str:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.prepare_config_and_inputs()
             UpperCAmelCase_				,					UpperCAmelCase_				,					UpperCAmelCase_    				=							config_and_inputs
             UpperCAmelCase_    				=							{"pixel_values": pixel_values}
             return config, inputs_dict



@require_tf
class    lowercase__     (					SCREAMING_SNAKE_CASE       ,      SCREAMING_SNAKE_CASE       ,      unittest.TestCase   ):







       '''simple docstring'''


       UpperCamelCase		=  (
           (
               TFDeiTModel,
               TFDeiTForImageClassification,
               TFDeiTForImageClassificationWithTeacher,
               TFDeiTForMaskedImageModeling,
           )
           if is_tf_available()
           else ()
       )
       UpperCamelCase		=  (
           {
               '''feature-extraction''': TFDeiTModel,
               '''image-classification''': (TFDeiTForImageClassification, TFDeiTForImageClassificationWithTeacher),
           }
           if is_tf_available()
           else {}
       )

       UpperCamelCase		=  False
       UpperCamelCase		=  False
       UpperCamelCase		=  False
       UpperCamelCase		=  False



       def   lowercase__       (							self    :						Dict					)				->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							TFDeiTModelTester(self					)
             UpperCAmelCase_    				=							ConfigTester(self	,       config_class=_SCREAMING_SNAKE_CASE	,       has_text_modality=_SCREAMING_SNAKE_CASE	,       hidden_size=37					)



       def   lowercase__       (							self    :						Any					)				->		str:


             '''simple docstring'''




             self.config_tester.run_common_tests()



       @unittest.skip(reason="DeiT does not use inputs_embeds"					)
       def   lowercase__       (							self    :						str					)				->		List[Any]:


             '''simple docstring'''




             pass



       def   lowercase__       (							self    :						Dict					)				->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_				,					UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   UpperCAmelCase_    				=							model_class(_SCREAMING_SNAKE_CASE					)
                   self.assertIsInstance(model.get_input_embeddings()	,       (tf.keras.layers.Layer)					)
                   UpperCAmelCase_    				=							model.get_output_embeddings()
                   self.assertTrue(x is None or isinstance(_SCREAMING_SNAKE_CASE	,       tf.keras.layers.Dense					)					)



       def   lowercase__       (							self    :						Union[str, Any]					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_				,					UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   UpperCAmelCase_    				=							model_class(_SCREAMING_SNAKE_CASE					)
                   UpperCAmelCase_    				=							inspect.signature(model.call					)
                   # signature.parameters is an OrderedDict => so arg_names order is deterministic
                   UpperCAmelCase_    				=							[*signature.parameters.keys()]

                   UpperCAmelCase_    				=							["pixel_values"]
                   self.assertListEqual(arg_names[:1]	,       _SCREAMING_SNAKE_CASE					)



       def   lowercase__       (							self    :						Optional[int]					)				->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE					)



       def   lowercase__       (							self    :						List[str]					)				->		Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_masked_image_modeling(*_SCREAMING_SNAKE_CASE					)



       def   lowercase__       (							self    :						Union[str, Any]					)				->		List[str]:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE					)



       def   lowercase__       (							self    :						Dict	,       _UpperCAmelCase    :						List[Any]	,       _UpperCAmelCase    :						Any	,       _UpperCAmelCase    :						List[str]=False					)				->		Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							super()._prepare_for_class(_SCREAMING_SNAKE_CASE	,       _SCREAMING_SNAKE_CASE	,       return_labels=_SCREAMING_SNAKE_CASE					)

             if return_labels:
                   if "labels" in inputs_dict and "labels" not in inspect.signature(model_class.call					).parameters:
                         del inputs_dict["labels"]

             return inputs_dict







       @slow
       def   lowercase__       (							self    :						Optional[Any]					)				->		str:


             '''simple docstring'''




             for model_name in TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   UpperCAmelCase_    				=							TFDeiTModel.from_pretrained(_SCREAMING_SNAKE_CASE					)
                   self.assertIsNotNone(_SCREAMING_SNAKE_CASE					)



def      a__			(   ):
      UpperCAmelCase_    				=							Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"   )
      return image


@require_tf
@require_vision
class    lowercase__     (					unittest.TestCase   ):







       '''simple docstring'''


       @cached_property
       def   lowercase__       (							self    :						Dict					)				->		Any:


             '''simple docstring'''




             return (
                 DeiTImageProcessor.from_pretrained("facebook/deit-base-distilled-patch16-224"					)
                 if is_vision_available()
                 else None
             )







       @slow
       def   lowercase__       (							self    :						List[Any]					)				->		int:


             '''simple docstring'''




             UpperCAmelCase_    				=							TFDeiTForImageClassificationWithTeacher.from_pretrained("facebook/deit-base-distilled-patch16-224"					)

             UpperCAmelCase_    				=							self.default_image_processor
             UpperCAmelCase_    				=							prepare_img()
             UpperCAmelCase_    				=							image_processor(images=_SCREAMING_SNAKE_CASE	,       return_tensors="tf"					)

             # forward pass
             UpperCAmelCase_    				=							model(**_SCREAMING_SNAKE_CASE					)

             # verify the logits
             UpperCAmelCase_    				=							tf.TensorShape((1, 1000)					)
             self.assertEqual(outputs.logits.shape	,       _SCREAMING_SNAKE_CASE					)

             UpperCAmelCase_    				=							tf.constant([-1.0266, 0.1912, -1.2861]					)

             self.assertTrue(np.allclose(outputs.logits[0, :3]	,       _SCREAMING_SNAKE_CASE	,       atol=1e-4					)					)









"""simple docstring"""





import string
def      a__			(   lowerCAmelCase__   ):
      for key in range(len(string.ascii_uppercase   )   ):
            UpperCAmelCase_    				=							""
            for symbol in message:
                  if symbol in string.ascii_uppercase:
                        UpperCAmelCase_    				=							string.ascii_uppercase.find(lowerCAmelCase__   )
                        UpperCAmelCase_    				=							num - key
                        if num < 0:
                              UpperCAmelCase_    				=							num + len(string.ascii_uppercase   )
                        UpperCAmelCase_    				=							translated + string.ascii_uppercase[num]
                  else:
                        UpperCAmelCase_    				=							translated + symbol
            print(f"""Decryption using Key #{key}: {translated}"""   )
def      a__			(   ):
      UpperCAmelCase_    				=							input("Encrypted message: "   )
      UpperCAmelCase_    				=							message.upper()
      decrypt(lowerCAmelCase__   )


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  main()




