

"""simple docstring"""





from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


_a       =							logging.get_logger(__name__)


_a       =							{
    'Salesforce/codegen-350M-nl': 'https://huggingface.co/Salesforce/codegen-350M-nl/resolve/main/config.json',
    'Salesforce/codegen-350M-multi': 'https://huggingface.co/Salesforce/codegen-350M-multi/resolve/main/config.json',
    'Salesforce/codegen-350M-mono': 'https://huggingface.co/Salesforce/codegen-350M-mono/resolve/main/config.json',
    'Salesforce/codegen-2B-nl': 'https://huggingface.co/Salesforce/codegen-2B-nl/resolve/main/config.json',
    'Salesforce/codegen-2B-multi': 'https://huggingface.co/Salesforce/codegen-2B-multi/resolve/main/config.json',
    'Salesforce/codegen-2B-mono': 'https://huggingface.co/Salesforce/codegen-2B-mono/resolve/main/config.json',
    'Salesforce/codegen-6B-nl': 'https://huggingface.co/Salesforce/codegen-6B-nl/resolve/main/config.json',
    'Salesforce/codegen-6B-multi': 'https://huggingface.co/Salesforce/codegen-6B-multi/resolve/main/config.json',
    'Salesforce/codegen-6B-mono': 'https://huggingface.co/Salesforce/codegen-6B-mono/resolve/main/config.json',
    'Salesforce/codegen-16B-nl': 'https://huggingface.co/Salesforce/codegen-16B-nl/resolve/main/config.json',
    'Salesforce/codegen-16B-multi': 'https://huggingface.co/Salesforce/codegen-16B-multi/resolve/main/config.json',
    'Salesforce/codegen-16B-mono': 'https://huggingface.co/Salesforce/codegen-16B-mono/resolve/main/config.json',
}




class 					_lowerCAmelCase  (	lowercase   ):







 """simple docstring"""







 __UpperCAmelCase	:					List[str]   		=	"codegen"
 __UpperCAmelCase	:					int   		=	{
     "max_position_embeddings": "n_positions",
     "hidden_size": "n_embd",
     "num_attention_heads": "n_head",
     "num_hidden_layers": "n_layer",
 }


 def __init__(			self							:			Optional[Any],					UpperCAmelCase__							:			Union[str, Any]=5_0_4_0_0,					UpperCAmelCase__							:			int=2_0_4_8,					UpperCAmelCase__							:			Tuple=2_0_4_8,					UpperCAmelCase__							:			Optional[Any]=4_0_9_6,					UpperCAmelCase__							:			Optional[int]=2_8,					UpperCAmelCase__							:			List[Any]=1_6,					UpperCAmelCase__							:			Union[str, Any]=6_4,					UpperCAmelCase__							:			Union[str, Any]=None,					UpperCAmelCase__							:			Optional[int]="gelu_new",					UpperCAmelCase__							:			Union[str, Any]=0.0,					UpperCAmelCase__							:			int=0.0,					UpperCAmelCase__							:			List[str]=0.0,					UpperCAmelCase__							:			int=1E-5,					UpperCAmelCase__							:			int=0.02,					UpperCAmelCase__							:			Optional[Any]=True,					UpperCAmelCase__							:			int=5_0_2_5_6,					UpperCAmelCase__							:			Tuple=5_0_2_5_6,					UpperCAmelCase__							:			int=False,					**UpperCAmelCase__							:			Any,					):
    __lowercase								=						vocab_size
    __lowercase								=						n_ctx
    __lowercase								=						n_positions
    __lowercase								=						n_embd
    __lowercase								=						n_layer
    __lowercase								=						n_head
    __lowercase								=						n_inner
    __lowercase								=						rotary_dim
    __lowercase								=						activation_function
    __lowercase								=						resid_pdrop
    __lowercase								=						embd_pdrop
    __lowercase								=						attn_pdrop
    __lowercase								=						layer_norm_epsilon
    __lowercase								=						initializer_range
    __lowercase								=						use_cache

    __lowercase								=						bos_token_id
    __lowercase								=						eos_token_id

    super().__init__(
        bos_token_id=UpperCAmelCase__,					eos_token_id=UpperCAmelCase__,					tie_word_embeddings=UpperCAmelCase__,					**UpperCAmelCase__	)







class 					_lowerCAmelCase  (	lowercase   ):







 """simple docstring"""







 def __init__(			self							:			Dict,					UpperCAmelCase__							:			PretrainedConfig,					UpperCAmelCase__							:			str = "default",					UpperCAmelCase__							:			List[PatchingSpec] = None,					UpperCAmelCase__							:			bool = False,					):
    super().__init__(UpperCAmelCase__,					task=UpperCAmelCase__,					patching_specs=UpperCAmelCase__,					use_past=UpperCAmelCase__	)
    if not getattr(self._config,					"pad_token_id",					UpperCAmelCase__	):
       # TODO: how to do that better?
       __lowercase								=						0


 @property
 def 					_lowercase (			self							:			int	):
    __lowercase								=						OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}	)
    if self.use_past:
       self.fill_with_past_key_values_(UpperCAmelCase__,					direction="inputs"	)
       __lowercase								=						{0: "batch", 1: "past_sequence + sequence"}
    else:
       __lowercase								=						{0: "batch", 1: "sequence"}

    return common_inputs


 @property
 def 					_lowercase (			self							:			Any	):
    return self._config.n_layer


 @property
 def 					_lowercase (			self							:			int	):
    return self._config.n_head


 def 					_lowercase (			self							:			Optional[int],					UpperCAmelCase__							:			PreTrainedTokenizer,					UpperCAmelCase__							:			int = -1,					UpperCAmelCase__							:			int = -1,					UpperCAmelCase__							:			bool = False,					UpperCAmelCase__							:			Optional[TensorType] = None,					):
    __lowercase								=						super(UpperCAmelCase__,					self	).generate_dummy_inputs(
        UpperCAmelCase__,					batch_size=UpperCAmelCase__,					seq_length=UpperCAmelCase__,					is_pair=UpperCAmelCase__,					framework=UpperCAmelCase__	)

    # We need to order the input in the way they appears in the forward()
    __lowercase								=						OrderedDict({"input_ids": common_inputs["input_ids"]}	)

    # Need to add the past_keys
    if self.use_past:
       if not is_torch_available():
          raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."	)
       else:
          import torch

          __lowercase		,__lowercase								=						common_inputs["input_ids"].shape
          # Not using the same length for past_key_values
          __lowercase								=						seqlen + 2
          __lowercase								=						(
              batch,
              self.num_attention_heads,
              past_key_values_length,
              self._config.hidden_size // self.num_attention_heads,
          )
          __lowercase								=						[
              (torch.zeros(UpperCAmelCase__	), torch.zeros(UpperCAmelCase__	)) for _ in range(self.num_layers	)
          ]

    __lowercase								=						common_inputs["attention_mask"]
    if self.use_past:
       __lowercase								=						ordered_inputs["attention_mask"].dtype
       __lowercase								=						torch.cat(
           [ordered_inputs["attention_mask"], torch.ones(UpperCAmelCase__,					UpperCAmelCase__,					dtype=UpperCAmelCase__	)],					dim=1	)

    return ordered_inputs



 @property
 def 					_lowercase (			self							:			str	):
    return 1_3







"""simple docstring"""





from typing import List, Optional, Union

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


_a       =							logging.get_logger(__name__)

_a       =							{
    '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  (	lowercase   ):







 """simple docstring"""







 __UpperCAmelCase	:					int   		=	"time_series_transformer"
 __UpperCAmelCase	:					Any   		=	{
     "hidden_size": "d_model",
     "num_attention_heads": "encoder_attention_heads",
     "num_hidden_layers": "encoder_layers",
 }


 def __init__(			self							:			int,					UpperCAmelCase__							:			Optional[int] = None,					UpperCAmelCase__							:			Optional[int] = None,					UpperCAmelCase__							:			str = "student_t",					UpperCAmelCase__							:			str = "nll",					UpperCAmelCase__							:			int = 1,					UpperCAmelCase__							:			List[int] = [1, 2, 3, 4, 5, 6, 7],					UpperCAmelCase__							:			Optional[Union[str, bool]] = "mean",					UpperCAmelCase__							:			int = 0,					UpperCAmelCase__							:			int = 0,					UpperCAmelCase__							:			int = 0,					UpperCAmelCase__							:			int = 0,					UpperCAmelCase__							:			Optional[List[int]] = None,					UpperCAmelCase__							:			Optional[List[int]] = None,					UpperCAmelCase__							:			int = 3_2,					UpperCAmelCase__							:			int = 3_2,					UpperCAmelCase__							:			int = 2,					UpperCAmelCase__							:			int = 2,					UpperCAmelCase__							:			int = 2,					UpperCAmelCase__							:			int = 2,					UpperCAmelCase__							:			bool = True,					UpperCAmelCase__							:			str = "gelu",					UpperCAmelCase__							:			int = 6_4,					UpperCAmelCase__							:			float = 0.1,					UpperCAmelCase__							:			float = 0.1,					UpperCAmelCase__							:			float = 0.1,					UpperCAmelCase__							:			float = 0.1,					UpperCAmelCase__							:			float = 0.1,					UpperCAmelCase__							:			int = 1_0_0,					UpperCAmelCase__							:			float = 0.02,					UpperCAmelCase__							:			Any=True,					**UpperCAmelCase__							:			List[str],					):
    # time series specific configuration
    __lowercase								=						prediction_length
    __lowercase								=						context_length or prediction_length
    __lowercase								=						distribution_output
    __lowercase								=						loss
    __lowercase								=						input_size
    __lowercase								=						num_time_features
    __lowercase								=						lags_sequence
    __lowercase								=						scaling
    __lowercase								=						num_dynamic_real_features
    __lowercase								=						num_static_real_features
    __lowercase								=						num_static_categorical_features
    if cardinality and num_static_categorical_features > 0:
       if len(UpperCAmelCase__	) != num_static_categorical_features:
          raise ValueError(
              "The cardinality should be a list of the same length as `num_static_categorical_features`"	)
       __lowercase								=						cardinality
    else:
       __lowercase								=						[0]
    if embedding_dimension and num_static_categorical_features > 0:
       if len(UpperCAmelCase__	) != num_static_categorical_features:
          raise ValueError(
              "The embedding dimension should be a list of the same length as `num_static_categorical_features`"	)
       __lowercase								=						embedding_dimension
    else:
       __lowercase								=						[min(5_0,					(cat + 1) // 2	) for cat in self.cardinality]
    __lowercase								=						num_parallel_samples

    # Transformer architecture configuration
    __lowercase								=						input_size * len(UpperCAmelCase__	) + self._number_of_features
    __lowercase								=						d_model
    __lowercase								=						encoder_attention_heads
    __lowercase								=						decoder_attention_heads
    __lowercase								=						encoder_ffn_dim
    __lowercase								=						decoder_ffn_dim
    __lowercase								=						encoder_layers
    __lowercase								=						decoder_layers

    __lowercase								=						dropout
    __lowercase								=						attention_dropout
    __lowercase								=						activation_dropout
    __lowercase								=						encoder_layerdrop
    __lowercase								=						decoder_layerdrop

    __lowercase								=						activation_function
    __lowercase								=						init_std

    __lowercase								=						use_cache

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



 @property
 def 					_lowercase (			self							:			Optional[Any]	):
    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
    )




