
'''simple docstring'''
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import DeiTImageProcessor







class 			__A					(			unittest.TestCase      ):
 def __init__( self      :     Optional[int]					, lowerCamelCase      :     Union[str, Any]					, lowerCamelCase      :     str=7					, lowerCamelCase      :     str=3					, lowerCamelCase      :     Optional[Any]=18					, lowerCamelCase      :     Any=30					, lowerCamelCase      :     str=4_00					, lowerCamelCase      :     Optional[Any]=True					, lowerCamelCase      :     str=None					, lowerCamelCase      :     List[Any]=True					, lowerCamelCase      :     Optional[Any]=None					, lowerCamelCase      :     List[Any]=True					, lowerCamelCase      :     Dict=[0.5, 0.5, 0.5]					, lowerCamelCase      :     str=[0.5, 0.5, 0.5]					, ):



   """simple docstring"""





   __A		:  Any       				=		size if size is not None else {"""height""": 20, """width""": 20}
   __A		:  List[str]       				=		crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

   __A		:  int       				=		parent
   __A		:  Any       				=		batch_size
   __A		:  Optional[int]       				=		num_channels
   __A		:  int       				=		image_size
   __A		:  Dict       				=		min_resolution
   __A		:  List[str]       				=		max_resolution
   __A		:  int       				=		do_resize
   __A		:  Optional[Any]       				=		size
   __A		:  List[str]       				=		do_center_crop
   __A		:  Tuple       				=		crop_size
   __A		:  Optional[Any]       				=		do_normalize
   __A		:  int       				=		image_mean
   __A		:  Optional[int]       				=		image_std






 def 		lowercase_( self      :     List[str]							):



   """simple docstring"""





   return {
       "do_resize": self.do_resize,
       "size": self.size,
       "do_center_crop": self.do_center_crop,
       "crop_size": self.crop_size,
       "do_normalize": self.do_normalize,
       "image_mean": self.image_mean,
       "image_std": self.image_std,
   }







@require_torch
@require_vision
class 			__A					(			_UpperCAmelCase     ,    unittest.TestCase      ):
 lowerCamelCase												=DeiTImageProcessor if is_vision_available() else None
 lowerCamelCase												=True
 def 		lowercase_( self      :     Dict							):



   """simple docstring"""





   __A		:  Tuple       				=		DeiTImageProcessingTester(self							)
 @property
 def 		lowercase_( self      :     str							):



   """simple docstring"""





   return self.image_processor_tester.prepare_image_processor_dict()
 def 		lowercase_( self      :     List[Any]							):



   """simple docstring"""





   __A		:  str       				=		self.image_processing_class(**self.image_processor_dict							)
   self.assertTrue(hasattr(_lowerCAmelCase					, """do_resize"""							)							)
   self.assertTrue(hasattr(_lowerCAmelCase					, """size"""							)							)
   self.assertTrue(hasattr(_lowerCAmelCase					, """do_center_crop"""							)							)
   self.assertTrue(hasattr(_lowerCAmelCase					, """center_crop"""							)							)
   self.assertTrue(hasattr(_lowerCAmelCase					, """do_normalize"""							)							)
   self.assertTrue(hasattr(_lowerCAmelCase					, """image_mean"""							)							)
   self.assertTrue(hasattr(_lowerCAmelCase					, """image_std"""							)							)
 def 		lowercase_( self      :     Optional[Any]							):



   """simple docstring"""





   __A		:  List[str]       				=		self.image_processing_class.from_dict(self.image_processor_dict							)
   self.assertEqual(image_processor.size					, {"""height""": 20, """width""": 20}							)
   self.assertEqual(image_processor.crop_size					, {"""height""": 18, """width""": 18}							)

   __A		:  Dict       				=		self.image_processing_class.from_dict(self.image_processor_dict					, size=42					, crop_size=84							)
   self.assertEqual(image_processor.size					, {"""height""": 42, """width""": 42}							)
   self.assertEqual(image_processor.crop_size					, {"""height""": 84, """width""": 84}							)
 def 		lowercase_( self      :     List[Any]							):



   """simple docstring"""





   pass
 def 		lowercase_( self      :     Dict							):



   """simple docstring"""





   __A		:  List[Any]       				=		self.image_processing_class(**self.image_processor_dict							)
   # create random PIL images
   __A		:  str       				=		prepare_image_inputs(self.image_processor_tester					, equal_resolution=_lowerCAmelCase							)
   for image in image_inputs:
     self.assertIsInstance(_lowerCAmelCase					, Image.Image							)

   # Test not batched input
   __A		:  Optional[Any]       				=		image_processing(image_inputs[0]					, return_tensors="""pt"""							).pixel_values
   self.assertEqual(
       encoded_images.shape					, (
           1,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["""height"""],
           self.image_processor_tester.crop_size["""width"""],
       )					, )

   # Test batched
   __A		:  int       				=		image_processing(_lowerCAmelCase					, return_tensors="""pt"""							).pixel_values
   self.assertEqual(
       encoded_images.shape					, (
           self.image_processor_tester.batch_size,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["""height"""],
           self.image_processor_tester.crop_size["""width"""],
       )					, )
 def 		lowercase_( self      :     int							):



   """simple docstring"""





   __A		:  int       				=		self.image_processing_class(**self.image_processor_dict							)
   # create random numpy tensors
   __A		:  int       				=		prepare_image_inputs(self.image_processor_tester					, equal_resolution=_lowerCAmelCase					, numpify=_lowerCAmelCase							)
   for image in image_inputs:
     self.assertIsInstance(_lowerCAmelCase					, np.ndarray							)

   # Test not batched input
   __A		:  List[Any]       				=		image_processing(image_inputs[0]					, return_tensors="""pt"""							).pixel_values
   self.assertEqual(
       encoded_images.shape					, (
           1,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["""height"""],
           self.image_processor_tester.crop_size["""width"""],
       )					, )

   # Test batched
   __A		:  List[str]       				=		image_processing(_lowerCAmelCase					, return_tensors="""pt"""							).pixel_values
   self.assertEqual(
       encoded_images.shape					, (
           self.image_processor_tester.batch_size,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["""height"""],
           self.image_processor_tester.crop_size["""width"""],
       )					, )






 def 		lowercase_( self      :     Any							):



   """simple docstring"""





   __A		:  Dict       				=		self.image_processing_class(**self.image_processor_dict							)
   # create random PyTorch tensors
   __A		:  int       				=		prepare_image_inputs(self.image_processor_tester					, equal_resolution=_lowerCAmelCase					, torchify=_lowerCAmelCase							)
   for image in image_inputs:
     self.assertIsInstance(_lowerCAmelCase					, torch.Tensor							)

   # Test not batched input
   __A		:  Optional[Any]       				=		image_processing(image_inputs[0]					, return_tensors="""pt"""							).pixel_values
   self.assertEqual(
       encoded_images.shape					, (
           1,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["""height"""],
           self.image_processor_tester.crop_size["""width"""],
       )					, )

   # Test batched
   __A		:  Dict       				=		image_processing(_lowerCAmelCase					, return_tensors="""pt"""							).pixel_values
   self.assertEqual(
       encoded_images.shape					, (
           self.image_processor_tester.batch_size,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["""height"""],
           self.image_processor_tester.crop_size["""width"""],
       )					, )







from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCamelCase			:					List[Any]         =							logging.get_logger(__name__)

UpperCamelCase			:					Tuple         =							{
    '''mnaylor/mega-base-wikitext''': '''https://huggingface.co/mnaylor/mega-base-wikitext/resolve/main/config.json''',
}

class      __snake_case				(   _UpperCAmelCase):
					SCREAMING_SNAKE_CASE_		:       str								=			"mega"
					def __init__(						self       :						Optional[int]	,      _lowerCAmelCase       :						List[Any]=3_0_5_2_2	,      _lowerCAmelCase       :						List[str]=1_2_8	,      _lowerCAmelCase       :						Dict=4	,      _lowerCAmelCase       :						Optional[Any]=2_5_6	,      _lowerCAmelCase       :						Optional[Any]=1_6	,      _lowerCAmelCase       :						Dict=True	,      _lowerCAmelCase       :						Optional[Any]=6_4	,      _lowerCAmelCase       :						Optional[Any]=False	,      _lowerCAmelCase       :						Optional[int]=-1	,      _lowerCAmelCase       :						Any=None	,      _lowerCAmelCase       :						List[Any]=True	,      _lowerCAmelCase       :						List[Any]="scalenorm"	,      _lowerCAmelCase       :						str=True	,      _lowerCAmelCase       :						Union[str, Any]="silu"	,      _lowerCAmelCase       :						Optional[Any]="softmax"	,      _lowerCAmelCase       :						Optional[Any]=0.1	,      _lowerCAmelCase       :						Dict=0.1	,      _lowerCAmelCase       :						Any=0.1	,      _lowerCAmelCase       :						Optional[Any]=False	,      _lowerCAmelCase       :						Any=True	,      _lowerCAmelCase       :						int=2_5_6	,      _lowerCAmelCase       :						List[str]=True	,      _lowerCAmelCase       :						str=0.1	,      _lowerCAmelCase       :						List[str]=2_0_4_8	,      _lowerCAmelCase       :						Optional[Any]=False	,      _lowerCAmelCase       :						str=2	,      _lowerCAmelCase       :						Dict=0.02	,      _lowerCAmelCase       :						str=0.2	,      _lowerCAmelCase       :						List[str]=0.02	,      _lowerCAmelCase       :						int=1.0	,      _lowerCAmelCase       :						Optional[int]=1	,      _lowerCAmelCase       :						List[str]=0	,      _lowerCAmelCase       :						str=2	,      _lowerCAmelCase       :						Optional[Any]="rotary"	,      _lowerCAmelCase       :						int=None	,      _lowerCAmelCase       :						int=True	,      _lowerCAmelCase       :						Optional[Any]=True	,      **_lowerCAmelCase       :						str	,      )							->					Any:



											'''simple docstring'''





											super().__init__(pad_token_id=_lowerCAmelCase	,      bos_token_id=_lowerCAmelCase	,      eos_token_id=_lowerCAmelCase	,      **_lowerCAmelCase  )

											__magic_name__					=      vocab_size
											__magic_name__					=      hidden_size
											__magic_name__					=      num_hidden_layers
											__magic_name__					=      activation
											__magic_name__					=      attention_activation
											__magic_name__					=      intermediate_size
											__magic_name__					=      ema_projection_size
											__magic_name__					=      bidirectional
											__magic_name__					=      shared_representation_size
											__magic_name__					=      use_chunking
											__magic_name__					=      chunk_size
											__magic_name__					=      truncation
											__magic_name__					=      normalize_before_mega
											__magic_name__					=      normalization_type
											__magic_name__					=      norm_affine
											__magic_name__					=      dropout_prob
											__magic_name__					=      hidden_dropout_prob
											__magic_name__					=      attention_probs_dropout_prob
											__magic_name__					=      use_feature_dropout
											__magic_name__					=      use_normalized_ffn
											__magic_name__					=      nffn_hidden_size
											__magic_name__					=      normalize_before_ffn
											__magic_name__					=      nffn_activation_dropout_prob
											__magic_name__					=      max_positions
											__magic_name__					=      add_token_type_embeddings
											__magic_name__					=      type_vocab_size
											__magic_name__					=      initializer_range
											__magic_name__					=      ema_delta_alpha_range
											__magic_name__					=      ema_beta_range
											__magic_name__					=      ema_gamma_omega_range
											__magic_name__					=      relative_positional_bias
											__magic_name__					=      use_cache
											__magic_name__					=      classifier_dropout
											__magic_name__					=      add_lm_hidden_dense_layer
											__magic_name__					=      1  # not used but required by Hugging Face







class      __snake_case				(   _UpperCAmelCase):
					@property
					def 	a			(						self       :						int  )							->					Mapping[str, Mapping[int, str]]:



											'''simple docstring'''





											if self.task == "multiple-choice":
																	__magic_name__					=      {0: 'batch', 1: 'choice', 2: 'sequence'}
											else:
																	__magic_name__					=      {0: 'batch', 1: 'sequence'}
											return OrderedDict(
											    [
											        ('input_ids', dynamic_axis),
											        ('attention_mask', dynamic_axis),
											    ]  )

