


from typing import List, Optional, Union

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


UpperCamelCase								=	logging.get_logger(__name__)

UpperCamelCase								=	{
    """huggingface/time-series-transformer-tourism-monthly""": (
        """https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json"""
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}






class   _lowerCamelCase (					UpperCamelCase			):




       """simple docstring"""
       snake_case      =    "time_series_transformer"
       snake_case      =    {
           "hidden_size": "d_model",
           "num_attention_heads": "encoder_attention_heads",
           "num_hidden_layers": "encoder_layers",
       }



       def __init__(      self				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = "student_t"				,       _SCREAMING_SNAKE_CASE = "nll"				,       _SCREAMING_SNAKE_CASE = 1				,       _SCREAMING_SNAKE_CASE = [1, 2, 3, 4, 5, 6, 7]				,       _SCREAMING_SNAKE_CASE = "mean"				,       _SCREAMING_SNAKE_CASE = 0				,       _SCREAMING_SNAKE_CASE = 0				,       _SCREAMING_SNAKE_CASE = 0				,       _SCREAMING_SNAKE_CASE = 0				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = None				,       _SCREAMING_SNAKE_CASE = 32				,       _SCREAMING_SNAKE_CASE = 32				,       _SCREAMING_SNAKE_CASE = 2				,       _SCREAMING_SNAKE_CASE = 2				,       _SCREAMING_SNAKE_CASE = 2				,       _SCREAMING_SNAKE_CASE = 2				,       _SCREAMING_SNAKE_CASE = True				,       _SCREAMING_SNAKE_CASE = "gelu"				,       _SCREAMING_SNAKE_CASE = 64				,       _SCREAMING_SNAKE_CASE = 0.1				,       _SCREAMING_SNAKE_CASE = 0.1				,       _SCREAMING_SNAKE_CASE = 0.1				,       _SCREAMING_SNAKE_CASE = 0.1				,       _SCREAMING_SNAKE_CASE = 0.1				,       _SCREAMING_SNAKE_CASE = 100				,       _SCREAMING_SNAKE_CASE = 0.0_2				,       _SCREAMING_SNAKE_CASE=True				,       **_SCREAMING_SNAKE_CASE				,       )->List[Any]:




         '''simple docstring'''





         A_      :				str		     =					prediction_length
         A_      :				Optional[int]		     =					context_length or prediction_length
         A_      :				List[Any]		     =					distribution_output
         A_      :				List[str]		     =					loss
         A_      :				List[Any]		     =					input_size
         A_      :				Any		     =					num_time_features
         A_      :				Optional[int]		     =					lags_sequence
         A_      :				int		     =					scaling
         A_      :				Optional[int]		     =					num_dynamic_real_features
         A_      :				int		     =					num_static_real_features
         A_      :				List[Any]		     =					num_static_categorical_features
         if cardinality and num_static_categorical_features > 0:
           if len(_SCREAMING_SNAKE_CASE		) != num_static_categorical_features:
             raise ValueError(
                 '''The cardinality should be a list of the same length as `num_static_categorical_features`'''		)
           A_      :				Optional[Any]		     =					cardinality
         else:
           A_      :				Dict		     =					[0]
         if embedding_dimension and num_static_categorical_features > 0:
           if len(_SCREAMING_SNAKE_CASE		) != num_static_categorical_features:
             raise ValueError(
                 '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''		)
           A_      :				List[Any]		     =					embedding_dimension
         else:
           A_      :				Optional[int]		     =					[min(50				,       (cat + 1) // 2		) for cat in self.cardinality]
         A_      :				int		     =					num_parallel_samples

         # Transformer architecture configuration
         A_      :				Optional[Any]		     =					input_size * len(_SCREAMING_SNAKE_CASE		) + self._number_of_features
         A_      :				Union[str, Any]		     =					d_model
         A_      :				Dict		     =					encoder_attention_heads
         A_      :				Any		     =					decoder_attention_heads
         A_      :				Union[str, Any]		     =					encoder_ffn_dim
         A_      :				Tuple		     =					decoder_ffn_dim
         A_      :				List[Any]		     =					encoder_layers
         A_      :				Optional[Any]		     =					decoder_layers

         A_      :				Optional[int]		     =					dropout
         A_      :				Optional[Any]		     =					attention_dropout
         A_      :				Union[str, Any]		     =					activation_dropout
         A_      :				Any		     =					encoder_layerdrop
         A_      :				str		     =					decoder_layerdrop

         A_      :				Optional[Any]		     =					activation_function
         A_      :				Tuple		     =					init_std

         A_      :				Any		     =					use_cache

         super().__init__(is_encoder_decoder=_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)







       @property
       def        _snake_case       (      self		)->int:




         '''simple docstring'''





         return (
             sum(self.embedding_dimension		)
             + self.num_dynamic_real_features
             + self.num_time_features
             + self.num_static_real_features
             + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
         )








import copy
import os
from typing import Union

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


UpperCamelCase								=	logging.get_logger(__name__)

UpperCamelCase								=	{
    """google/pix2struct-textcaps-base""": (
        """https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json"""
    ),
}






class   _lowerCamelCase (					UpperCamelCase			):




       """simple docstring"""
       snake_case      =    "pix2struct_text_model"
       snake_case      =    ["past_key_values"]
       snake_case      =    {
           "hidden_size": "hidden_size",
           "num_attention_heads": "num_heads",
           "num_hidden_layers": "num_layers",
       }



       def __init__(      self				,       _SCREAMING_SNAKE_CASE=5_0244				,       _SCREAMING_SNAKE_CASE=768				,       _SCREAMING_SNAKE_CASE=64				,       _SCREAMING_SNAKE_CASE=2048				,       _SCREAMING_SNAKE_CASE=12				,       _SCREAMING_SNAKE_CASE=12				,       _SCREAMING_SNAKE_CASE=32				,       _SCREAMING_SNAKE_CASE=128				,       _SCREAMING_SNAKE_CASE=0.1				,       _SCREAMING_SNAKE_CASE=1e-6				,       _SCREAMING_SNAKE_CASE=1.0				,       _SCREAMING_SNAKE_CASE="gelu_new"				,       _SCREAMING_SNAKE_CASE=0				,       _SCREAMING_SNAKE_CASE=False				,       _SCREAMING_SNAKE_CASE=0				,       _SCREAMING_SNAKE_CASE=1				,       _SCREAMING_SNAKE_CASE=False				,       _SCREAMING_SNAKE_CASE=True				,       **_SCREAMING_SNAKE_CASE				,       )->int:




         '''simple docstring'''





         A_      :				Optional[int]		     =					vocab_size
         A_      :				Any		     =					hidden_size
         A_      :				Optional[Any]		     =					d_kv
         A_      :				int		     =					d_ff
         A_      :				int		     =					num_layers
         A_      :				Dict		     =					num_heads
         A_      :				Any		     =					relative_attention_num_buckets
         A_      :				int		     =					relative_attention_max_distance
         A_      :				Optional[Any]		     =					dropout_rate
         A_      :				Optional[Any]		     =					layer_norm_epsilon
         A_      :				List[Any]		     =					initializer_factor
         A_      :				Optional[int]		     =					use_cache

         A_      :				Optional[Any]		     =					eos_token_id
         A_      :				List[Any]		     =					decoder_start_token_id

         # for backwards compatibility
         A_      :				int		     =					dense_act_fn

         super().__init__(
             pad_token_id=_SCREAMING_SNAKE_CASE				,       eos_token_id=_SCREAMING_SNAKE_CASE				,       decoder_start_token_id=_SCREAMING_SNAKE_CASE				,       tie_word_embeddings=_SCREAMING_SNAKE_CASE				,       is_decoder=_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE				,       )







       @classmethod
       def        _snake_case       (      cls				,       _SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->"PretrainedConfig":




         '''simple docstring'''





         cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE		)

         A_     ,       A_      :				Union[str, Any]		     =					cls.get_config_dict(_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)

         # get the text config dict if we are loading from Pix2StructConfig
         if config_dict.get('''model_type'''		) == "pix2struct":
           A_      :				Any		     =					config_dict['''text_config''']

         if "model_type" in config_dict and hasattr(cls				,       '''model_type'''		) and config_dict["model_type"] != cls.model_type:
           logger.warning(
               F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
               F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''		)

         return cls.from_dict(_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)






class   _lowerCamelCase (					UpperCamelCase			):




       """simple docstring"""
       snake_case      =    "pix2struct_vision_model"



       def __init__(      self				,       _SCREAMING_SNAKE_CASE=768				,       _SCREAMING_SNAKE_CASE=768				,       _SCREAMING_SNAKE_CASE=2048				,       _SCREAMING_SNAKE_CASE=64				,       _SCREAMING_SNAKE_CASE=12				,       _SCREAMING_SNAKE_CASE=12				,       _SCREAMING_SNAKE_CASE="gelu_new"				,       _SCREAMING_SNAKE_CASE=1e-6				,       _SCREAMING_SNAKE_CASE=0.0				,       _SCREAMING_SNAKE_CASE=0.0				,       _SCREAMING_SNAKE_CASE=1e-10				,       _SCREAMING_SNAKE_CASE=1.0				,       _SCREAMING_SNAKE_CASE=4096				,       _SCREAMING_SNAKE_CASE=32				,       _SCREAMING_SNAKE_CASE=128				,       **_SCREAMING_SNAKE_CASE				,       )->Optional[int]:




         '''simple docstring'''





         super().__init__(**_SCREAMING_SNAKE_CASE		)

         A_      :				Dict		     =					hidden_size
         A_      :				Union[str, Any]		     =					patch_embed_hidden_size
         A_      :				Optional[Any]		     =					d_ff
         A_      :				Optional[Any]		     =					dropout_rate
         A_      :				int		     =					num_hidden_layers
         A_      :				Tuple		     =					num_attention_heads
         A_      :				List[str]		     =					initializer_range
         A_      :				List[str]		     =					initializer_factor
         A_      :				Union[str, Any]		     =					attention_dropout
         A_      :				Union[str, Any]		     =					layer_norm_eps
         A_      :				Dict		     =					dense_act_fn
         A_      :				Union[str, Any]		     =					seq_len
         A_      :				Optional[Any]		     =					relative_attention_num_buckets
         A_      :				Tuple		     =					relative_attention_max_distance
         A_      :				List[Any]		     =					d_kv







       @classmethod
       def        _snake_case       (      cls				,       _SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->"PretrainedConfig":




         '''simple docstring'''





         cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE		)

         A_     ,       A_      :				str		     =					cls.get_config_dict(_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)

         # get the vision config dict if we are loading from Pix2StructConfig
         if config_dict.get('''model_type'''		) == "pix2struct":
           A_      :				Any		     =					config_dict['''vision_config''']

         if "model_type" in config_dict and hasattr(cls				,       '''model_type'''		) and config_dict["model_type"] != cls.model_type:
           logger.warning(
               F'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
               F'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''		)

         return cls.from_dict(_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)






class   _lowerCamelCase (					UpperCamelCase			):




       """simple docstring"""
       snake_case      =    "pix2struct"
       snake_case      =    True



       def __init__(      self				,       _SCREAMING_SNAKE_CASE=None				,       _SCREAMING_SNAKE_CASE=None				,       _SCREAMING_SNAKE_CASE=1.0				,       _SCREAMING_SNAKE_CASE=0.0_2				,       _SCREAMING_SNAKE_CASE=False				,       _SCREAMING_SNAKE_CASE=False				,       _SCREAMING_SNAKE_CASE=True				,       **_SCREAMING_SNAKE_CASE				,       )->Any:




         '''simple docstring'''





         super().__init__(tie_word_embeddings=_SCREAMING_SNAKE_CASE				,       is_encoder_decoder=_SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)

         if text_config is None:
           A_      :				Dict		     =					{}
           logger.info('''text_config is None. Initializing the Pix2StructTextConfig with default values.'''		)

         if vision_config is None:
           A_      :				List[Any]		     =					{}
           logger.info('''vision_config is None. Initializing the Pix2StructVisionConfig with default values.'''		)

         A_      :				int		     =					PixaStructTextConfig(**_SCREAMING_SNAKE_CASE		)
         A_      :				Dict		     =					PixaStructVisionConfig(**_SCREAMING_SNAKE_CASE		)

         A_      :				Optional[Any]		     =					self.text_config.decoder_start_token_id
         A_      :				Tuple		     =					self.text_config.pad_token_id
         A_      :				Union[str, Any]		     =					self.text_config.eos_token_id

         A_      :				str		     =					initializer_factor
         A_      :				Tuple		     =					initializer_range

         A_      :				List[str]		     =					self.initializer_range
         A_      :				int		     =					self.initializer_range

         A_      :				List[Any]		     =					is_vqa



       @classmethod
       def        _snake_case       (      cls				,       _SCREAMING_SNAKE_CASE				,       _SCREAMING_SNAKE_CASE				,       **_SCREAMING_SNAKE_CASE		)->Union[str, Any]:




         '''simple docstring'''





         return cls(text_config=text_config.to_dict()				,       vision_config=vision_config.to_dict()				,       **_SCREAMING_SNAKE_CASE		)







       def        _snake_case       (      self		)->Dict:




         '''simple docstring'''





         A_      :				List[Any]		     =					copy.deepcopy(self.__dict__		)
         A_      :				Dict		     =					self.text_config.to_dict()
         A_      :				int		     =					self.vision_config.to_dict()
         A_      :				List[str]		     =					self.__class__.model_type
         return output




