

'''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 MobileNetVaImageProcessor



class        lowercase_	(		unittest.TestCase ):

  '''simple docstring'''





  def __init__(     self   , a_   , a_=7   , a_=3   , a_=1_8   , a_=3_0   , a_=4_0_0   , a_=True   , a_=None   , a_=True   , a_=None   , )							->				List[str]:


    """simple docstring"""
    UpperCAmelCase													=	size if size is not None else {'shortest_edge': 2_0}
    UpperCAmelCase													=	crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}
    UpperCAmelCase													=	parent
    UpperCAmelCase													=	batch_size
    UpperCAmelCase													=	num_channels
    UpperCAmelCase													=	image_size
    UpperCAmelCase													=	min_resolution
    UpperCAmelCase													=	max_resolution
    UpperCAmelCase													=	do_resize
    UpperCAmelCase													=	size
    UpperCAmelCase													=	do_center_crop
    UpperCAmelCase													=	crop_size





  def 						snake_case_			(     self     )							->				Optional[int]:


    """simple docstring"""
    return {
        "do_resize": self.do_resize,
        "size": self.size,
        "do_center_crop": self.do_center_crop,
        "crop_size": self.crop_size,
    }




@require_torch
@require_vision
class        lowercase_	(		a ,       unittest.TestCase ):

  '''simple docstring'''





  __lowerCAmelCase					: Union[str, Any]      =   MobileNetVaImageProcessor if is_vision_available() else None
  def 						snake_case_			(     self     )							->				Dict:


    """simple docstring"""
    UpperCAmelCase													=	MobileNetVaImageProcessingTester(self     )
  @property
  def 						snake_case_			(     self     )							->				List[str]:


    """simple docstring"""
    return self.image_processor_tester.prepare_image_processor_dict()
  def 						snake_case_			(     self     )							->				Optional[int]:


    """simple docstring"""
    UpperCAmelCase													=	self.image_processing_class(**self.image_processor_dict     )
    self.assertTrue(hasattr(a_   , 'do_resize'     )     )
    self.assertTrue(hasattr(a_   , 'size'     )     )
    self.assertTrue(hasattr(a_   , 'do_center_crop'     )     )
    self.assertTrue(hasattr(a_   , 'center_crop'     )     )
  def 						snake_case_			(     self     )							->				str:


    """simple docstring"""
    UpperCAmelCase													=	self.image_processing_class.from_dict(self.image_processor_dict     )
    self.assertEqual(image_processor.size   , {'shortest_edge': 2_0}     )
    self.assertEqual(image_processor.crop_size   , {'height': 1_8, 'width': 1_8}     )

    UpperCAmelCase													=	self.image_processing_class.from_dict(self.image_processor_dict   , size=4_2   , crop_size=8_4     )
    self.assertEqual(image_processor.size   , {'shortest_edge': 4_2}     )
    self.assertEqual(image_processor.crop_size   , {'height': 8_4, 'width': 8_4}     )
  def 						snake_case_			(     self     )							->				List[str]:


    """simple docstring"""
    pass
  def 						snake_case_			(     self     )							->				List[Any]:


    """simple docstring"""
    # Initialize image_processing
    UpperCAmelCase													=	self.image_processing_class(**self.image_processor_dict     )
    # create random PIL images
    UpperCAmelCase													=	prepare_image_inputs(self.image_processor_tester   , equal_resolution=a_     )
    for image in image_inputs:
      self.assertIsInstance(a_   , Image.Image     )

    # Test not batched input
    UpperCAmelCase													=	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
    UpperCAmelCase													=	image_processing(a_   , 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 						snake_case_			(     self     )							->				str:


    """simple docstring"""
    # Initialize image_processing
    UpperCAmelCase													=	self.image_processing_class(**self.image_processor_dict     )
    # create random numpy tensors
    UpperCAmelCase													=	prepare_image_inputs(self.image_processor_tester   , equal_resolution=a_   , numpify=a_     )
    for image in image_inputs:
      self.assertIsInstance(a_   , np.ndarray     )

    # Test not batched input
    UpperCAmelCase													=	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
    UpperCAmelCase													=	image_processing(a_   , 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 						snake_case_			(     self     )							->				List[Any]:


    """simple docstring"""
    # Initialize image_processing
    UpperCAmelCase													=	self.image_processing_class(**self.image_processor_dict     )
    # create random PyTorch tensors
    UpperCAmelCase													=	prepare_image_inputs(self.image_processor_tester   , equal_resolution=a_   , torchify=a_     )
    for image in image_inputs:
      self.assertIsInstance(a_   , torch.Tensor     )

    # Test not batched input
    UpperCAmelCase													=	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
    UpperCAmelCase													=	image_processing(a_   , 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'],
        )   , )





'''simple docstring'''




from collections import OrderedDict
from typing import Mapping

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


_a				: Optional[int] 							=						logging.get_logger(__name__)

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



class        lowercase_	(		a ):

  '''simple docstring'''





  __lowerCAmelCase					: List[str]      =   "mega"
  def __init__(     self   , a_=3_0_5_2_2   , a_=1_2_8   , a_=4   , a_=2_5_6   , a_=1_6   , a_=True   , a_=6_4   , a_=False   , a_=-1   , a_=None   , a_=True   , a_="scalenorm"   , a_=True   , a_="silu"   , a_="softmax"   , a_=0.1   , a_=0.1   , a_=0.1   , a_=False   , a_=True   , a_=2_5_6   , a_=True   , a_=0.1   , a_=2_0_4_8   , a_=False   , a_=2   , a_=0.02   , a_=0.2   , a_=0.02   , a_=1.0   , a_=1   , a_=0   , a_=2   , a_="rotary"   , a_=None   , a_=True   , a_=True   , **a_   , )							->				Any:


    """simple docstring"""
    super().__init__(pad_token_id=a_   , bos_token_id=a_   , eos_token_id=a_   , **a_     )

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




class        lowercase_	(		a ):

  '''simple docstring'''





  @property
  def 						snake_case_			(     self     )							->				Mapping[str, Mapping[int, str]]:


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


