





'''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 ViTImageProcessor
class 							__lowerCAmelCase	(       unittest.TestCase					):






       """simple docstring"""





       def __init__(				self  :						str			,					lowerCAmelCase__  :						Optional[int]			,					lowerCAmelCase__  :						int=13			,					lowerCAmelCase__  :						Any=3			,					lowerCAmelCase__  :						Optional[Any]=224			,					lowerCAmelCase__  :						str=30			,					lowerCAmelCase__  :						int=400			,					lowerCAmelCase__  :						Union[str, Any]=True			,					lowerCAmelCase__  :						Union[str, Any]=None			,					lowerCAmelCase__  :						List[str]=True			,					lowerCAmelCase__  :						int=[0.5, 0.5, 0.5]			,					lowerCAmelCase__  :						Optional[Any]=[0.5, 0.5, 0.5]			,					)       ->	str:

            '''simple docstring'''




            _UpperCamelCase							       =			size if size is not None else {'''height''': 18, '''width''': 18}
            _UpperCamelCase							       =			parent
            _UpperCamelCase							       =			batch_size
            _UpperCamelCase							       =			num_channels
            _UpperCamelCase							       =			image_size
            _UpperCamelCase							       =			min_resolution
            _UpperCamelCase							       =			max_resolution
            _UpperCamelCase							       =			do_resize
            _UpperCamelCase							       =			size
            _UpperCamelCase							       =			do_normalize
            _UpperCamelCase							       =			image_mean
            _UpperCamelCase							       =			image_std







       def snake_case__		(				self  :						Any	)       ->	str:

            '''simple docstring'''




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

@require_torch
@require_vision
class 							__lowerCAmelCase	(       __magic_name__		,		unittest.TestCase					):






       """simple docstring"""
       _snake_case      :	Union[str, Any]									=       ViTImageProcessor if is_vision_available() else None





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

            '''simple docstring'''




            _UpperCamelCase							       =			EfficientFormerImageProcessorTester(self	)





       @property
       def snake_case__		(				self  :						Dict	)       ->	Any:

            '''simple docstring'''




            return self.image_proc_tester.prepare_image_processor_dict()





       def snake_case__		(				self  :						Dict	)       ->	Tuple:

            '''simple docstring'''




            _UpperCamelCase							       =			self.image_processing_class(**self.image_processor_dict	)
            self.assertTrue(hasattr(lowerCAmelCase__			,					'''image_mean'''	)	)
            self.assertTrue(hasattr(lowerCAmelCase__			,					'''image_std'''	)	)
            self.assertTrue(hasattr(lowerCAmelCase__			,					'''do_normalize'''	)	)
            self.assertTrue(hasattr(lowerCAmelCase__			,					'''do_resize'''	)	)
            self.assertTrue(hasattr(lowerCAmelCase__			,					'''size'''	)	)





       def snake_case__		(				self  :						Tuple	)       ->	List[Any]:

            '''simple docstring'''




            pass





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

            '''simple docstring'''




            _UpperCamelCase							       =			self.image_processing_class(**self.image_processor_dict	)
            # create random PIL images
            _UpperCamelCase							       =			prepare_image_inputs(self.image_proc_tester			,					equal_resolution=lowerCAmelCase__	)
            for image in image_inputs:
                 self.assertIsInstance(lowerCAmelCase__			,					Image.Image	)

            # Test not batched input
            _UpperCamelCase							       =			image_processor(image_inputs[0]			,					return_tensors='''pt'''	).pixel_values
            self.assertEqual(
                encoded_images.shape			,					(
                    1,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size['''height'''],
                    self.image_proc_tester.size['''width'''],
                )			,					)

            # Test batched
            _UpperCamelCase							       =			image_processor(lowerCAmelCase__			,					return_tensors='''pt'''	).pixel_values
            self.assertEqual(
                encoded_images.shape			,					(
                    self.image_proc_tester.batch_size,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size['''height'''],
                    self.image_proc_tester.size['''width'''],
                )			,					)





       def snake_case__		(				self  :						str	)       ->	str:

            '''simple docstring'''




            _UpperCamelCase							       =			self.image_processing_class(**self.image_processor_dict	)
            # create random numpy tensors
            _UpperCamelCase							       =			prepare_image_inputs(self.image_proc_tester			,					equal_resolution=lowerCAmelCase__			,					numpify=lowerCAmelCase__	)
            for image in image_inputs:
                 self.assertIsInstance(lowerCAmelCase__			,					np.ndarray	)

            # Test not batched input
            _UpperCamelCase							       =			image_processor(image_inputs[0]			,					return_tensors='''pt'''	).pixel_values
            self.assertEqual(
                encoded_images.shape			,					(
                    1,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size['''height'''],
                    self.image_proc_tester.size['''width'''],
                )			,					)

            # Test batched
            _UpperCamelCase							       =			image_processor(lowerCAmelCase__			,					return_tensors='''pt'''	).pixel_values
            self.assertEqual(
                encoded_images.shape			,					(
                    self.image_proc_tester.batch_size,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size['''height'''],
                    self.image_proc_tester.size['''width'''],
                )			,					)







       def snake_case__		(				self  :						int	)       ->	Dict:

            '''simple docstring'''




            _UpperCamelCase							       =			self.image_processing_class(**self.image_processor_dict	)
            # create random PyTorch tensors
            _UpperCamelCase							       =			prepare_image_inputs(self.image_proc_tester			,					equal_resolution=lowerCAmelCase__			,					torchify=lowerCAmelCase__	)
            for image in image_inputs:
                 self.assertIsInstance(lowerCAmelCase__			,					torch.Tensor	)

            # Test not batched input
            _UpperCamelCase							       =			image_processor(image_inputs[0]			,					return_tensors='''pt'''	).pixel_values
            self.assertEqual(
                encoded_images.shape			,					(
                    1,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size['''height'''],
                    self.image_proc_tester.size['''width'''],
                )			,					)

            # Test batched
            _UpperCamelCase							       =			image_processor(lowerCAmelCase__			,					return_tensors='''pt'''	).pixel_values
            self.assertEqual(
                encoded_images.shape			,					(
                    self.image_proc_tester.batch_size,
                    self.image_proc_tester.num_channels,
                    self.image_proc_tester.size['''height'''],
                    self.image_proc_tester.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__					:			str          =     logging.get_logger(__name__)

a__					:			Any          =     {
    '''xlm-mlm-en-2048''': '''https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json''',
    '''xlm-mlm-ende-1024''': '''https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-enfr-1024''': '''https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json''',
    '''xlm-mlm-enro-1024''': '''https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json''',
    '''xlm-mlm-tlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-mlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-clm-enfr-1024''': '''https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json''',
    '''xlm-clm-ende-1024''': '''https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-17-1280''': '''https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json''',
    '''xlm-mlm-100-1280''': '''https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json''',
}






class 				__snake_case     (					__magic_name__							):
	__lowerCAmelCase       						=  '''xlm'''
	__lowerCAmelCase       						=  {
	    '''hidden_size''': '''emb_dim''',
	    '''num_attention_heads''': '''n_heads''',
	    '''num_hidden_layers''': '''n_layers''',
	    '''n_words''': '''vocab_size''',  # For backward compatibility
	}





	def __init__(		self      ,       UpperCamelCase_=3_0145      ,       UpperCamelCase_=2048      ,       UpperCamelCase_=12      ,       UpperCamelCase_=16      ,       UpperCamelCase_=0.1      ,       UpperCamelCase_=0.1      ,       UpperCamelCase_=True      ,       UpperCamelCase_=False      ,       UpperCamelCase_=False      ,       UpperCamelCase_=False      ,       UpperCamelCase_=1      ,       UpperCamelCase_=True      ,       UpperCamelCase_=512      ,       UpperCamelCase_=2048**-0.5      ,       UpperCamelCase_=1E-1_2      ,       UpperCamelCase_=0.0_2      ,       UpperCamelCase_=0      ,       UpperCamelCase_=1      ,       UpperCamelCase_=2      ,       UpperCamelCase_=3      ,       UpperCamelCase_=5      ,       UpperCamelCase_=True      ,       UpperCamelCase_="first"      ,       UpperCamelCase_=True      ,       UpperCamelCase_=None      ,       UpperCamelCase_=True      ,       UpperCamelCase_=0.1      ,       UpperCamelCase_=5      ,       UpperCamelCase_=5      ,       UpperCamelCase_=0      ,       UpperCamelCase_=0      ,       UpperCamelCase_=2      ,       UpperCamelCase_=0      ,       **UpperCamelCase_      ,       )      ->		List[str]:
		snake_case__	       =   vocab_size
		snake_case__	       =   emb_dim
		snake_case__	       =   n_layers
		snake_case__	       =   n_heads
		snake_case__	       =   dropout
		snake_case__	       =   attention_dropout
		snake_case__	       =   gelu_activation
		snake_case__	       =   sinusoidal_embeddings
		snake_case__	       =   causal
		snake_case__	       =   asm
		snake_case__	       =   n_langs
		snake_case__	       =   use_lang_emb
		snake_case__	       =   layer_norm_eps
		snake_case__	       =   bos_index
		snake_case__	       =   eos_index
		snake_case__	       =   pad_index
		snake_case__	       =   unk_index
		snake_case__	       =   mask_index
		snake_case__	       =   is_encoder
		snake_case__	       =   max_position_embeddings
		snake_case__	       =   embed_init_std
		snake_case__	       =   init_std
		snake_case__	       =   summary_type
		snake_case__	       =   summary_use_proj
		snake_case__	       =   summary_activation
		snake_case__	       =   summary_proj_to_labels
		snake_case__	       =   summary_first_dropout
		snake_case__	       =   start_n_top
		snake_case__	       =   end_n_top
		snake_case__	       =   mask_token_id
		snake_case__	       =   lang_id

		if "n_words" in kwargs:
			snake_case__	       =   kwargs['n_words']

		super().__init__(pad_token_id=UpperCamelCase_      ,       bos_token_id=UpperCamelCase_      ,       **UpperCamelCase_		)






class 				__snake_case     (					__magic_name__							):





	@property
	def   _snake_case   (		self		)      ->		Mapping[str, Mapping[int, str]]:
		if self.task == "multiple-choice":
			snake_case__	       =   {0: 'batch', 1: 'choice', 2: 'sequence'}
		else:
			snake_case__	       =   {0: 'batch', 1: 'sequence'}
		return OrderedDict(
		    [
		        ('input_ids', dynamic_axis),
		        ('attention_mask', dynamic_axis),
		        ('token_type_ids', dynamic_axis),
		    ]		)



