




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

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


_lowerCamelCase			:	Any							 =     logging.get_logger(__name__)

_lowerCamelCase			:	Optional[int]							 =     {
    """Helsinki-NLP/opus-mt-en-de""": """https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json""",
    # See all Marian models at https://huggingface.co/models?filter=marian
}


class        UpperCamelCase_					(				UpperCAmelCase__  ):

    '''simple docstring'''






    UpperCAmelCase__													=   '''marian'''
    UpperCAmelCase__													=   ['''past_key_values''']
    UpperCAmelCase__													=   {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}


    def __init__(    self   :			Union[str, Any]      ,				UpperCAmelCase__   :			Dict=58_101      ,				UpperCAmelCase__   :			Any=None      ,				UpperCAmelCase__   :			Optional[Any]=1_024      ,				UpperCAmelCase__   :			Tuple=12      ,				UpperCAmelCase__   :			str=4_096      ,				UpperCAmelCase__   :			Union[str, Any]=16      ,				UpperCAmelCase__   :			Union[str, Any]=12      ,				UpperCAmelCase__   :			Union[str, Any]=4_096      ,				UpperCAmelCase__   :			Optional[Any]=16      ,				UpperCAmelCase__   :			Optional[Any]=0.0      ,				UpperCAmelCase__   :			Optional[Any]=0.0      ,				UpperCAmelCase__   :			Optional[int]=True      ,				UpperCAmelCase__   :			Optional[Any]=True      ,				UpperCAmelCase__   :			Any="gelu"      ,				UpperCAmelCase__   :			str=1_024      ,				UpperCAmelCase__   :			Optional[int]=0.1      ,				UpperCAmelCase__   :			List[Any]=0.0      ,				UpperCAmelCase__   :			str=0.0      ,				UpperCAmelCase__   :			Union[str, Any]=0.02      ,				UpperCAmelCase__   :			Optional[Any]=58_100      ,				UpperCAmelCase__   :			int=False      ,				UpperCAmelCase__   :			str=58_100      ,				UpperCAmelCase__   :			Optional[int]=0      ,				UpperCAmelCase__   :			List[str]=0      ,				UpperCAmelCase__   :			List[str]=True      ,				**UpperCAmelCase__   :			int      ,				)		->Optional[Any]:





           '''simple docstring'''

           A__   				=					vocab_size
           A__   				=					decoder_vocab_size or vocab_size
           A__   				=					max_position_embeddings
           A__   				=					d_model
           A__   				=					encoder_ffn_dim
           A__   				=					encoder_layers
           A__   				=					encoder_attention_heads
           A__   				=					decoder_ffn_dim
           A__   				=					decoder_layers
           A__   				=					decoder_attention_heads
           A__   				=					dropout
           A__   				=					attention_dropout
           A__   				=					activation_dropout
           A__   				=					activation_function
           A__   				=					init_std
           A__   				=					encoder_layerdrop
           A__   				=					decoder_layerdrop
           A__   				=					use_cache
           A__   				=					encoder_layers
           A__   				=					scale_embedding  # scale factor will be sqrt(d_model) if True
           A__   				=					share_encoder_decoder_embeddings
           super().__init__(
               pad_token_id=UpperCAmelCase__      ,				eos_token_id=UpperCAmelCase__      ,				is_encoder_decoder=UpperCAmelCase__      ,				decoder_start_token_id=UpperCAmelCase__      ,				forced_eos_token_id=UpperCAmelCase__      ,				**UpperCAmelCase__      ,				)


class        UpperCamelCase_					(				UpperCAmelCase__  ):

    '''simple docstring'''






    @property
    # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->Mapping[str, Mapping[int, str]]:





           '''simple docstring'''

           if self.task in ["default", "seq2seq-lm"]:
                  A__   				=					OrderedDict(
                      [
                          ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                          ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                      ])

                  if self.use_past:
                         A__   				=					{0: '''batch'''}
                         A__   				=					{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
                  else:
                         A__   				=					{0: '''batch''', 1: '''decoder_sequence'''}
                         A__   				=					{0: '''batch''', 1: '''decoder_sequence'''}

                  if self.use_past:
                         self.fill_with_past_key_values_(UpperCAmelCase__      ,				direction='''inputs''')
           elif self.task == "causal-lm":
                  # TODO: figure this case out.
                  A__   				=					OrderedDict(
                      [
                          ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                          ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                      ])
                  if self.use_past:
                         A__				,							A__   				=					self.num_layers
                         for i in range(UpperCAmelCase__):
                                A__   				=					{0: '''batch''', 2: '''past_sequence + sequence'''}
                                A__   				=					{0: '''batch''', 2: '''past_sequence + sequence'''}
           else:
                  A__   				=					OrderedDict(
                      [
                          ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                          ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                          ('''decoder_input_ids''', {0: '''batch''', 1: '''decoder_sequence'''}),
                          ('''decoder_attention_mask''', {0: '''batch''', 1: '''decoder_sequence'''}),
                      ])

           return common_inputs


    @property
    # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->Mapping[str, Mapping[int, str]]:





           '''simple docstring'''

           if self.task in ["default", "seq2seq-lm"]:
                  A__   				=					super().outputs
           else:
                  A__   				=					super(UpperCAmelCase__      ,				self).outputs
                  if self.use_past:
                         A__				,							A__   				=					self.num_layers
                         for i in range(UpperCAmelCase__):
                                A__   				=					{0: '''batch''', 2: '''past_sequence + sequence'''}
                                A__   				=					{0: '''batch''', 2: '''past_sequence + sequence'''}
           return common_outputs


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict      ,				UpperCAmelCase__   :			PreTrainedTokenizer      ,				UpperCAmelCase__   :			int = -1      ,				UpperCAmelCase__   :			int = -1      ,				UpperCAmelCase__   :			bool = False      ,				UpperCAmelCase__   :			Optional[TensorType] = None      ,				)		->Mapping[str, Any]:





           '''simple docstring'''

           A__   				=					self._generate_dummy_inputs_for_encoder_and_decoder(
               UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__)

           # Generate decoder inputs
           A__   				=					seq_length if not self.use_past else 1
           A__   				=					self._generate_dummy_inputs_for_encoder_and_decoder(
               UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__)
           A__   				=					{f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
           A__   				=					dict(**UpperCAmelCase__      ,				**UpperCAmelCase__)

           if self.use_past:
                  if not is_torch_available():
                         raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.''')
                  else:
                         import torch
                  A__				,							A__   				=					common_inputs['''input_ids'''].shape
                  A__   				=					common_inputs['''decoder_input_ids'''].shape[1]
                  A__				,							A__   				=					self.num_attention_heads
                  A__   				=					(
                      batch,
                      num_encoder_attention_heads,
                      encoder_seq_length,
                      self._config.hidden_size // num_encoder_attention_heads,
                  )
                  A__   				=					decoder_seq_length + 3
                  A__   				=					(
                      batch,
                      num_decoder_attention_heads,
                      decoder_past_length,
                      self._config.hidden_size // num_decoder_attention_heads,
                  )

                  A__   				=					torch.cat(
                      [common_inputs['''decoder_attention_mask'''], torch.ones(UpperCAmelCase__      ,				UpperCAmelCase__)]      ,				dim=1)

                  A__   				=					[]
                  # If the number of encoder and decoder layers are present in the model configuration, both are considered
                  A__				,							A__   				=					self.num_layers
                  A__   				=					min(UpperCAmelCase__      ,				UpperCAmelCase__)
                  A__   				=					max(UpperCAmelCase__      ,				UpperCAmelCase__) - min_num_layers
                  A__   				=					'''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

                  for _ in range(UpperCAmelCase__):
                         common_inputs["past_key_values"].append(
                             (
                                 torch.zeros(UpperCAmelCase__),
                                 torch.zeros(UpperCAmelCase__),
                                 torch.zeros(UpperCAmelCase__),
                                 torch.zeros(UpperCAmelCase__),
                             ))
                  # TODO: test this.
                  A__   				=					encoder_shape if remaining_side_name == '''encoder''' else decoder_shape
                  for _ in range(UpperCAmelCase__      ,				UpperCAmelCase__):
                         common_inputs["past_key_values"].append((torch.zeros(UpperCAmelCase__), torch.zeros(UpperCAmelCase__)))
           return common_inputs


    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any]      ,				UpperCAmelCase__   :			PreTrainedTokenizer      ,				UpperCAmelCase__   :			int = -1      ,				UpperCAmelCase__   :			int = -1      ,				UpperCAmelCase__   :			bool = False      ,				UpperCAmelCase__   :			Optional[TensorType] = None      ,				)		->Mapping[str, Any]:





           '''simple docstring'''

           A__   				=					self._generate_dummy_inputs_for_encoder_and_decoder(
               UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__)

           if self.use_past:
                  if not is_torch_available():
                         raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.''')
                  else:
                         import torch
                  A__				,							A__   				=					common_inputs['''input_ids'''].shape
                  # Not using the same length for past_key_values
                  A__   				=					seqlen + 2
                  A__				,							A__   				=					self.num_layers
                  A__				,							A__   				=					self.num_attention_heads
                  A__   				=					(
                      batch,
                      num_encoder_attention_heads,
                      past_key_values_length,
                      self._config.hidden_size // num_encoder_attention_heads,
                  )

                  A__   				=					common_inputs['''attention_mask'''].dtype
                  A__   				=					torch.cat(
                      [common_inputs['''attention_mask'''], torch.ones(UpperCAmelCase__      ,				UpperCAmelCase__      ,				dtype=UpperCAmelCase__)]      ,				dim=1)
                  A__   				=					[
                      (torch.zeros(UpperCAmelCase__), torch.zeros(UpperCAmelCase__)) for _ in range(UpperCAmelCase__)
                  ]
           return common_inputs


    def  SCREAMING_SNAKE_CASE							(    self   :			int      ,				UpperCAmelCase__   :			PreTrainedTokenizer      ,				UpperCAmelCase__   :			int = -1      ,				UpperCAmelCase__   :			int = -1      ,				UpperCAmelCase__   :			bool = False      ,				UpperCAmelCase__   :			Optional[TensorType] = None      ,				)		->Mapping[str, Any]:





           '''simple docstring'''

           A__   				=					compute_effective_axis_dimension(
               UpperCAmelCase__      ,				fixed_dimension=OnnxConfig.default_fixed_batch      ,				num_token_to_add=0)

           # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
           A__   				=					tokenizer.num_special_tokens_to_add(UpperCAmelCase__)
           A__   				=					compute_effective_axis_dimension(
               UpperCAmelCase__      ,				fixed_dimension=OnnxConfig.default_fixed_sequence      ,				num_token_to_add=UpperCAmelCase__)

           # Generate dummy inputs according to compute batch and sequence
           A__   				=					[''' '''.join([tokenizer.unk_token]) * seq_length] * batch_size
           A__   				=					dict(tokenizer(UpperCAmelCase__      ,				return_tensors=UpperCAmelCase__))
           return common_inputs


    def  SCREAMING_SNAKE_CASE							(    self   :			Any      ,				UpperCAmelCase__   :			PreTrainedTokenizer      ,				UpperCAmelCase__   :			int = -1      ,				UpperCAmelCase__   :			int = -1      ,				UpperCAmelCase__   :			bool = False      ,				UpperCAmelCase__   :			Optional[TensorType] = None      ,				)		->Mapping[str, Any]:





           '''simple docstring'''

           if self.task in ["default", "seq2seq-lm"]:
                  A__   				=					self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                      UpperCAmelCase__      ,				batch_size=UpperCAmelCase__      ,				seq_length=UpperCAmelCase__      ,				is_pair=UpperCAmelCase__      ,				framework=UpperCAmelCase__)

           else:
                  A__   				=					self._generate_dummy_inputs_for_causal_lm(
                      UpperCAmelCase__      ,				batch_size=UpperCAmelCase__      ,				seq_length=UpperCAmelCase__      ,				is_pair=UpperCAmelCase__      ,				framework=UpperCAmelCase__)

           return common_inputs


    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			List[str])		->List[Any]:





           '''simple docstring'''

           if self.task in ["default", "seq2seq-lm"]:
                  A__   				=					super()._flatten_past_key_values_(UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__)
           else:
                  A__   				=					super(UpperCAmelCase__      ,				self)._flatten_past_key_values_(
                      UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__      ,				UpperCAmelCase__)





    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			List[str])		->float:





           '''simple docstring'''

           return 1e-4








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


_lowerCamelCase			:	Tuple							 =     logging.get_logger(__name__)

_lowerCamelCase			:	Tuple							 =     {
    """tiiuae/falcon-40b""": """https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json""",
    """tiiuae/falcon-7b""": """https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json""",
}


class        UpperCamelCase_					(				UpperCAmelCase__  ):

    '''simple docstring'''






    UpperCAmelCase__													=   '''falcon'''
    UpperCAmelCase__													=   ['''past_key_values''']


    def __init__(    self   :			Optional[Any]      ,				UpperCAmelCase__   :			str=65_024      ,				UpperCAmelCase__   :			List[Any]=4_544      ,				UpperCAmelCase__   :			Optional[Any]=32      ,				UpperCAmelCase__   :			Dict=71      ,				UpperCAmelCase__   :			Any=1e-5      ,				UpperCAmelCase__   :			Optional[int]=0.02      ,				UpperCAmelCase__   :			Optional[int]=True      ,				UpperCAmelCase__   :			Union[str, Any]=0.0      ,				UpperCAmelCase__   :			List[str]=0.0      ,				UpperCAmelCase__   :			str=None      ,				UpperCAmelCase__   :			Dict=False      ,				UpperCAmelCase__   :			List[str]=False      ,				UpperCAmelCase__   :			Optional[Any]=True      ,				UpperCAmelCase__   :			Optional[Any]=True      ,				UpperCAmelCase__   :			Optional[Any]=False      ,				UpperCAmelCase__   :			Dict=11      ,				UpperCAmelCase__   :			str=11      ,				**UpperCAmelCase__   :			Dict      ,				)		->Any:





           '''simple docstring'''

           A__   				=					vocab_size
           # Backward compatibility with n_embed kwarg
           A__   				=					kwargs.pop('''n_embed'''      ,				UpperCAmelCase__)
           A__   				=					hidden_size if n_embed is None else n_embed
           A__   				=					num_hidden_layers
           A__   				=					num_attention_heads
           A__   				=					layer_norm_epsilon
           A__   				=					initializer_range
           A__   				=					use_cache
           A__   				=					hidden_dropout
           A__   				=					attention_dropout

           A__   				=					bos_token_id
           A__   				=					eos_token_id
           A__   				=					num_attention_heads if num_kv_heads is None else num_kv_heads
           A__   				=					alibi
           A__   				=					new_decoder_architecture
           A__   				=					multi_query  # Ignored when new_decoder_architecture is True
           A__   				=					parallel_attn
           A__   				=					bias

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


    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->int:





           '''simple docstring'''

           return self.hidden_size // self.num_attention_heads





    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->Dict:





           '''simple docstring'''

           return not self.alibi


