'''simple docstring'''
import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor






class 			__lowercase		(						unittest.TestCase						):







     """simple docstring"""






     def __init__(		self     ,			_lowerCamelCase     ,			_lowerCamelCase=7     ,			_lowerCamelCase=3     ,			_lowerCamelCase=1_8     ,			_lowerCamelCase=3_0     ,			_lowerCamelCase=4_0_0     ,			_lowerCamelCase=True     ,			_lowerCamelCase=None     ,			_lowerCamelCase=True     ,			_lowerCamelCase=False     ,			_lowerCamelCase=True     ,			_lowerCamelCase=True     ,			_lowerCamelCase=[0.5, 0.5, 0.5]     ,			_lowerCamelCase=[0.5, 0.5, 0.5]     ,			):
         __UpperCamelCase	:	Tuple		    =  parent
         __UpperCamelCase	:	Union[str, Any]		    =  batch_size
         __UpperCamelCase	:	Dict		    =  num_channels
         __UpperCamelCase	:	Dict		    =  image_size
         __UpperCamelCase	:	int		    =  min_resolution
         __UpperCamelCase	:	Optional[int]		    =  max_resolution
         __UpperCamelCase	:	int		    =  do_resize
         __UpperCamelCase	:	Optional[int]		    =  size if size is not None else {'height': 1_8, 'width': 2_0}
         __UpperCamelCase	:	str		    =  do_thumbnail
         __UpperCamelCase	:	Any		    =  do_align_axis
         __UpperCamelCase	:	Union[str, Any]		    =  do_pad
         __UpperCamelCase	:	str		    =  do_normalize
         __UpperCamelCase	:	Any		    =  image_mean
         __UpperCamelCase	:	List[str]		    =  image_std







     def lowerCAmelCase     (		self    ):
         return {
             "do_resize": self.do_resize,
             "size": self.size,
             "do_thumbnail": self.do_thumbnail,
             "do_align_long_axis": self.do_align_axis,
             "do_pad": self.do_pad,
             "do_normalize": self.do_normalize,
             "image_mean": self.image_mean,
             "image_std": self.image_std,
         }






@require_torch
@require_vision
class 			__lowercase		(						_lowerCamelCase			,							unittest.TestCase						):







     """simple docstring"""






     SCREAMING_SNAKE_CASE__		   =						DonutImageProcessor if is_vision_available() else None







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	List[Any]		    =  DonutImageProcessingTester(self    )







     @property
     def lowerCAmelCase     (		self    ):
         return self.image_processor_tester.prepare_image_processor_dict()







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Tuple		    =  self.image_processing_class(**self.image_processor_dict    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'do_resize'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'size'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'do_thumbnail'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'do_align_long_axis'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'do_pad'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'do_normalize'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'image_mean'    )    )
         self.assertTrue(hasattr(_lowerCamelCase     ,			'image_std'    )    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	List[str]		    =  self.image_processing_class.from_dict(self.image_processor_dict    )
         self.assertEqual(image_processor.size     ,			{'height': 1_8, 'width': 2_0}    )

         __UpperCamelCase	:	int		    =  self.image_processing_class.from_dict(self.image_processor_dict     ,			size=4_2    )
         self.assertEqual(image_processor.size     ,			{'height': 4_2, 'width': 4_2}    )

         # Previous config had dimensions in (width, height) order
         __UpperCamelCase	:	List[str]		    =  self.image_processing_class.from_dict(self.image_processor_dict     ,			size=(4_2, 8_4)    )
         self.assertEqual(image_processor.size     ,			{'height': 8_4, 'width': 4_2}    )







     def lowerCAmelCase     (		self    ):
         pass







     @is_flaky()
     def lowerCAmelCase     (		self    ):
         # Initialize image_processing
         __UpperCamelCase	:	Dict		    =  self.image_processing_class(**self.image_processor_dict    )
         # create random PIL images
         __UpperCamelCase	:	Any		    =  prepare_image_inputs(self.image_processor_tester     ,			equal_resolution=_lowerCamelCase    )
         for image in image_inputs:
             self.assertIsInstance(_lowerCamelCase     ,			Image.Image    )

         # Test not batched input
         __UpperCamelCase	:	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.size['height'],
                 self.image_processor_tester.size['width'],
             )     ,			)

         # Test batched
         __UpperCamelCase	:	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.size['height'],
                 self.image_processor_tester.size['width'],
             )     ,			)







     @is_flaky()
     def lowerCAmelCase     (		self    ):
         # Initialize image_processing
         __UpperCamelCase	:	List[str]		    =  self.image_processing_class(**self.image_processor_dict    )
         # create random numpy tensors
         __UpperCamelCase	:	Tuple		    =  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
         __UpperCamelCase	:	Optional[int]		    =  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.size['height'],
                 self.image_processor_tester.size['width'],
             )     ,			)

         # Test batched
         __UpperCamelCase	:	Optional[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.size['height'],
                 self.image_processor_tester.size['width'],
             )     ,			)







     @is_flaky()
     def lowerCAmelCase     (		self    ):
         # Initialize image_processing
         __UpperCamelCase	:	Union[str, Any]		    =  self.image_processing_class(**self.image_processor_dict    )
         # create random PyTorch tensors
         __UpperCamelCase	:	Any		    =  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
         __UpperCamelCase	:	int		    =  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.size['height'],
                 self.image_processor_tester.size['width'],
             )     ,			)

         # Test batched
         __UpperCamelCase	:	Union[str, Any]		    =  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.size['height'],
                 self.image_processor_tester.size['width'],
             )     ,			)




'''simple docstring'''
import warnings

from ...configuration_utils import PretrainedConfig
from ...utils import logging


a=  logging.get_logger(__name__)

a=  {
    '''xlnet-base-cased''': '''https://huggingface.co/xlnet-base-cased/resolve/main/config.json''',
    '''xlnet-large-cased''': '''https://huggingface.co/xlnet-large-cased/resolve/main/config.json''',
}






class 			__lowercase		(						_lowerCamelCase						):







     """simple docstring"""






     SCREAMING_SNAKE_CASE__		   =						'''xlnet'''
     SCREAMING_SNAKE_CASE__		   =						['''mems''']
     SCREAMING_SNAKE_CASE__		   =						{
         '''n_token''': '''vocab_size''',  # Backward compatibility
         '''hidden_size''': '''d_model''',
         '''num_attention_heads''': '''n_head''',
         '''num_hidden_layers''': '''n_layer''',
     }







     def __init__(		self     ,			_lowerCamelCase=3_2_0_0_0     ,			_lowerCamelCase=1_0_2_4     ,			_lowerCamelCase=2_4     ,			_lowerCamelCase=1_6     ,			_lowerCamelCase=4_0_9_6     ,			_lowerCamelCase="gelu"     ,			_lowerCamelCase=True     ,			_lowerCamelCase="bi"     ,			_lowerCamelCase=0.0_2     ,			_lowerCamelCase=1E-1_2     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=5_1_2     ,			_lowerCamelCase=None     ,			_lowerCamelCase=True     ,			_lowerCamelCase=False     ,			_lowerCamelCase=False     ,			_lowerCamelCase=-1     ,			_lowerCamelCase=False     ,			_lowerCamelCase="last"     ,			_lowerCamelCase=True     ,			_lowerCamelCase="tanh"     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=5     ,			_lowerCamelCase=5     ,			_lowerCamelCase=5     ,			_lowerCamelCase=1     ,			_lowerCamelCase=2     ,			**_lowerCamelCase     ,			):
         __UpperCamelCase	:	List[str]		    =  vocab_size
         __UpperCamelCase	:	List[Any]		    =  d_model
         __UpperCamelCase	:	List[str]		    =  n_layer
         __UpperCamelCase	:	Optional[Any]		    =  n_head
         if d_model % n_head != 0:
             raise ValueError(f"""'d_model % n_head' ({d_model % n_head}) should be equal to 0"""    )
         if "d_head" in kwargs:
             if kwargs["d_head"] != d_model // n_head:
                 raise ValueError(
                     f"""`d_head` ({kwargs['d_head']}) should be equal to `d_model // n_head` ({d_model // n_head})"""    )
         __UpperCamelCase	:	str		    =  d_model // n_head
         __UpperCamelCase	:	Union[str, Any]		    =  ff_activation
         __UpperCamelCase	:	str		    =  d_inner
         __UpperCamelCase	:	Any		    =  untie_r
         __UpperCamelCase	:	List[Any]		    =  attn_type

         __UpperCamelCase	:	str		    =  initializer_range
         __UpperCamelCase	:	Optional[int]		    =  layer_norm_eps

         __UpperCamelCase	:	Union[str, Any]		    =  dropout
         __UpperCamelCase	:	List[str]		    =  mem_len
         __UpperCamelCase	:	Optional[int]		    =  reuse_len
         __UpperCamelCase	:	str		    =  bi_data
         __UpperCamelCase	:	Tuple		    =  clamp_len
         __UpperCamelCase	:	List[Any]		    =  same_length

         __UpperCamelCase	:	Optional[Any]		    =  summary_type
         __UpperCamelCase	:	List[str]		    =  summary_use_proj
         __UpperCamelCase	:	Union[str, Any]		    =  summary_activation
         __UpperCamelCase	:	str		    =  summary_last_dropout
         __UpperCamelCase	:	Union[str, Any]		    =  start_n_top
         __UpperCamelCase	:	str		    =  end_n_top

         __UpperCamelCase	:	Optional[int]		    =  bos_token_id
         __UpperCamelCase	:	Optional[Any]		    =  pad_token_id
         __UpperCamelCase	:	List[Any]		    =  eos_token_id

         if "use_cache" in kwargs:
             warnings.warn(
                 'The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`'
                 ' instead.'     ,			_lowerCamelCase     ,			)
             __UpperCamelCase	:	Optional[int]		    =  kwargs['use_cache']

         __UpperCamelCase	:	Optional[int]		    =  use_mems_eval
         __UpperCamelCase	:	Tuple		    =  use_mems_train
         super().__init__(pad_token_id=_lowerCamelCase     ,			bos_token_id=_lowerCamelCase     ,			eos_token_id=_lowerCamelCase     ,			**_lowerCamelCase    )







     @property
     def lowerCAmelCase     (		self    ):
         logger.info(f"""The model {self.model_type} is one of the few models that has no sequence length limit."""    )
         return -1







     @max_position_embeddings.setter
     def lowerCAmelCase     (		self     ,			_lowerCamelCase    ):
         # Message copied from Transformer-XL documentation
         raise NotImplementedError(
             f"""The model {self.model_type} is one of the few models that has no sequence length limit."""    )



