




from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
		import PIL


__UpperCamelCase   :			List[str]          = logging.get_logger(__name__)

class 						__lowerCAmelCase      (      snake_case_					):
							UpperCamelCase__   	=    ['''pixel_values''']
							def __init__(		self		:List[str]						, __magic_name__		:bool = True						, __magic_name__		:Dict[str, int] = None						, __magic_name__		:PILImageResampling = PILImageResampling.BICUBIC						, __magic_name__		:bool = True						, __magic_name__		:Union[int, float] = 1 / 255						, __magic_name__		:bool = True						, __magic_name__		:Optional[Union[float, List[float]]] = None						, __magic_name__		:Optional[Union[float, List[float]]] = None						, __magic_name__		:bool = True						, **__magic_name__		:str						, ):







								'''simple docstring'''







								super().__init__(**lowercase__							)
								a									=				size if size is not None else {"""height""": 384, """width""": 384}
								a									=				get_size_dict(lowercase__						, default_to_square=lowercase__							)

								a									=				do_resize
								a									=				size
								a									=				resample
								a									=				do_rescale
								a									=				rescale_factor
								a									=				do_normalize
								a									=				image_mean if image_mean is not None else OPENAI_CLIP_MEAN
								a									=				image_std if image_std is not None else OPENAI_CLIP_STD
								a									=				do_convert_rgb
							def  lowerCamelCase__				(		self		:int						, __magic_name__		:np.ndarray						, __magic_name__		:Dict[str, int]						, __magic_name__		:PILImageResampling = PILImageResampling.BICUBIC						, __magic_name__		:Optional[Union[str, ChannelDimension]] = None						, **__magic_name__		:Optional[int]						, ):







								'''simple docstring'''







								a									=				get_size_dict(lowercase__						, default_to_square=lowercase__							)
								if "height" not in size or "width" not in size:
									raise ValueError(F'The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'							)
								a									=				(size["""height"""], size["""width"""])
								return resize(lowercase__						, size=lowercase__						, resample=lowercase__						, data_format=lowercase__						, **lowercase__							)
							def  lowerCamelCase__				(		self		:Optional[int]						, __magic_name__		:np.ndarray						, __magic_name__		:Union[int, float]						, __magic_name__		:Optional[Union[str, ChannelDimension]] = None						, **__magic_name__		:List[str]						, ):







								'''simple docstring'''







								return rescale(lowercase__						, scale=lowercase__						, data_format=lowercase__						, **lowercase__							)
							def  lowerCamelCase__				(		self		:Tuple						, __magic_name__		:np.ndarray						, __magic_name__		:Union[float, List[float]]						, __magic_name__		:Union[float, List[float]]						, __magic_name__		:Optional[Union[str, ChannelDimension]] = None						, **__magic_name__		:List[Any]						, ):







								'''simple docstring'''







								return normalize(lowercase__						, mean=lowercase__						, std=lowercase__						, data_format=lowercase__						, **lowercase__							)





							def  lowerCamelCase__				(		self		:List[Any]						, __magic_name__		:ImageInput						, __magic_name__		:Optional[bool] = None						, __magic_name__		:Optional[Dict[str, int]] = None						, __magic_name__		:PILImageResampling = None						, __magic_name__		:Optional[bool] = None						, __magic_name__		:Optional[float] = None						, __magic_name__		:Optional[bool] = None						, __magic_name__		:Optional[Union[float, List[float]]] = None						, __magic_name__		:Optional[Union[float, List[float]]] = None						, __magic_name__		:Optional[Union[str, TensorType]] = None						, __magic_name__		:bool = None						, __magic_name__		:ChannelDimension = ChannelDimension.FIRST						, **__magic_name__		:Union[str, Any]						, ):







								'''simple docstring'''







								a									=				do_resize if do_resize is not None else self.do_resize
								a									=				resample if resample is not None else self.resample
								a									=				do_rescale if do_rescale is not None else self.do_rescale
								a									=				rescale_factor if rescale_factor is not None else self.rescale_factor
								a									=				do_normalize if do_normalize is not None else self.do_normalize
								a									=				image_mean if image_mean is not None else self.image_mean
								a									=				image_std if image_std is not None else self.image_std
								a									=				do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

								a									=				size if size is not None else self.size
								a									=				get_size_dict(lowercase__						, default_to_square=lowercase__							)

								a									=				make_list_of_images(lowercase__							)

								if not valid_images(lowercase__							):
									raise ValueError(
									    """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
									    """torch.Tensor, tf.Tensor or jax.ndarray."""							)

								if do_resize and size is None or resample is None:
									raise ValueError("""Size and resample must be specified if do_resize is True."""							)

								if do_rescale and rescale_factor is None:
									raise ValueError("""Rescale factor must be specified if do_rescale is True."""							)

								if do_normalize and (image_mean is None or image_std is None):
									raise ValueError("""Image mean and std must be specified if do_normalize is True."""							)

								# PIL RGBA images are converted to RGB
								if do_convert_rgb:
									a									=				[convert_to_rgb(lowercase__							) for image in images]

								# All transformations expect numpy arrays.
								a									=				[to_numpy_array(lowercase__							) for image in images]

								if do_resize:
									a									=				[self.resize(image=lowercase__						, size=lowercase__						, resample=lowercase__							) for image in images]

								if do_rescale:
									a									=				[self.rescale(image=lowercase__						, scale=lowercase__							) for image in images]

								if do_normalize:
									a									=				[self.normalize(image=lowercase__						, mean=lowercase__						, std=lowercase__							) for image in images]

								a									=				[to_channel_dimension_format(lowercase__						, lowercase__							) for image in images]

								a									=				BatchFeature(data={"""pixel_values""": images}						, tensor_type=lowercase__							)

								return encoded_outputs







'''simple docstring'''


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


lowerCAmelCase_      :  str				     =  logging.get_logger(__name__)

lowerCAmelCase_      :  Any				     =  {
    'transfo-xl-wt103': 'https://huggingface.co/transfo-xl-wt103/resolve/main/config.json',
}







class      SCREAMING_SNAKE_CASE    (						snake_case_				):
      __magic_name__  :       str   							=					'''transfo-xl'''
      __magic_name__  :       List[str]   							=					['''mems''']
      __magic_name__  :       Dict   							=					{
          '''n_token''': '''vocab_size''',
          '''hidden_size''': '''d_model''',
          '''num_attention_heads''': '''n_head''',
          '''num_hidden_layers''': '''n_layer''',
      }






      def __init__( self   :  Union[str, Any]						,						lowercase__   :  List[Any]=26_7735						,						lowercase__   :  Optional[Any]=[2_0000, 4_0000, 20_0000]						,						lowercase__   :  Optional[Any]=1024						,						lowercase__   :  str=1024						,						lowercase__   :  Any=16						,						lowercase__   :  int=64						,						lowercase__   :  str=4096						,						lowercase__   :  Union[str, Any]=4						,						lowercase__   :  List[Any]=False						,						lowercase__   :  List[Any]=18						,						lowercase__   :  str=1600						,						lowercase__   :  str=1000						,						lowercase__   :  Any=True						,						lowercase__   :  Optional[Any]=True						,						lowercase__   :  Union[str, Any]=0						,						lowercase__   :  str=-1						,						lowercase__   :  int=True						,						lowercase__   :  str=0.1						,						lowercase__   :  Optional[Any]=0.0						,						lowercase__   :  Tuple=True						,						lowercase__   :  Optional[int]="normal"						,						lowercase__   :  str=0.01						,						lowercase__   :  List[str]=0.01						,						lowercase__   :  Union[str, Any]=0.02						,						lowercase__   :  str=1e-5						,						lowercase__   :  Any=0						,						**lowercase__   :  List[str]						,						):


           '''simple docstring'''

           a_     :							Optional[Any]     						=  vocab_size
           a_     :							Optional[int]     						=  []
           self.cutoffs.extend(lowercase__       )
           if proj_share_all_but_first:
                a_     :							Any     						=  [False] + [True] * len(self.cutoffs       )
           else:
                a_     :							Tuple     						=  [False] + [False] * len(self.cutoffs       )
           a_     :							Tuple     						=  d_model
           a_     :							Optional[int]     						=  d_embed
           a_     :							List[Any]     						=  d_head
           a_     :							List[str]     						=  d_inner
           a_     :							Tuple     						=  div_val
           a_     :							Dict     						=  pre_lnorm
           a_     :							Optional[Any]     						=  n_layer
           a_     :							Dict     						=  n_head
           a_     :							Any     						=  mem_len
           a_     :							Union[str, Any]     						=  same_length
           a_     :							Dict     						=  attn_type
           a_     :							List[str]     						=  clamp_len
           a_     :							str     						=  sample_softmax
           a_     :							Any     						=  adaptive
           a_     :							List[Any]     						=  dropout
           a_     :							str     						=  dropatt
           a_     :							Dict     						=  untie_r
           a_     :							Tuple     						=  init
           a_     :							Optional[int]     						=  init_range
           a_     :							List[Any]     						=  proj_init_std
           a_     :							Optional[int]     						=  init_std
           a_     :							int     						=  layer_norm_epsilon
           super().__init__(eos_token_id=lowercase__						,						**lowercase__       )






      @property
      def 							lowercase_						( self   :  int       ):


           '''simple docstring'''

           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 							lowercase_						( self   :  Optional[int]						,						lowercase__   :  Tuple       ):


           '''simple docstring'''

           raise NotImplementedError(
               F"The model {self.model_type} is one of the few models that has no sequence length limit."       )
