"""simple docstring"""







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

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


_SCREAMING_SNAKE_CASE	:		int   =   logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE	:		str   =   {
    '''facebook/blenderbot-3B''': '''https://huggingface.co/facebook/blenderbot-3B/resolve/main/config.json''',
    # See all Blenderbot models at https://huggingface.co/models?filter=blenderbot
}






class      _SCREAMING_SNAKE_CASE							(			_lowerCamelCase				):



   '''simple docstring'''



   __UpperCAmelCase	:							Optional[Any]    =    "blenderbot"
   __UpperCAmelCase	:							Union[str, Any]    =    ["past_key_values"]
   __UpperCAmelCase	:							List[Any]    =    {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}







   def __init__(	self ,				_SCREAMING_SNAKE_CASE=8008 ,				_SCREAMING_SNAKE_CASE=128 ,				_SCREAMING_SNAKE_CASE=2 ,				_SCREAMING_SNAKE_CASE=10240 ,				_SCREAMING_SNAKE_CASE=32 ,				_SCREAMING_SNAKE_CASE=24 ,				_SCREAMING_SNAKE_CASE=10240 ,				_SCREAMING_SNAKE_CASE=32 ,				_SCREAMING_SNAKE_CASE=0.0 ,				_SCREAMING_SNAKE_CASE=0.0 ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE=True ,				_SCREAMING_SNAKE_CASE="gelu" ,				_SCREAMING_SNAKE_CASE=2560 ,				_SCREAMING_SNAKE_CASE=0.1 ,				_SCREAMING_SNAKE_CASE=0.0 ,				_SCREAMING_SNAKE_CASE=0.0 ,				_SCREAMING_SNAKE_CASE=0.02 ,				_SCREAMING_SNAKE_CASE=1 ,				_SCREAMING_SNAKE_CASE=False ,				_SCREAMING_SNAKE_CASE=0 ,				_SCREAMING_SNAKE_CASE=1 ,				_SCREAMING_SNAKE_CASE=2 ,				_SCREAMING_SNAKE_CASE=3 ,				_SCREAMING_SNAKE_CASE=2 ,				**_SCREAMING_SNAKE_CASE ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					vocab_size
      __lowerCamelCase    		=					max_position_embeddings
      __lowerCamelCase    		=					d_model
      __lowerCamelCase    		=					encoder_ffn_dim
      __lowerCamelCase    		=					encoder_layers
      __lowerCamelCase    		=					encoder_attention_heads
      __lowerCamelCase    		=					decoder_ffn_dim
      __lowerCamelCase    		=					decoder_layers
      __lowerCamelCase    		=					decoder_attention_heads
      __lowerCamelCase    		=					dropout
      __lowerCamelCase    		=					attention_dropout
      __lowerCamelCase    		=					activation_dropout
      __lowerCamelCase    		=					activation_function
      __lowerCamelCase    		=					init_std
      __lowerCamelCase    		=					encoder_layerdrop
      __lowerCamelCase    		=					decoder_layerdrop
      __lowerCamelCase    		=					use_cache
      __lowerCamelCase    		=					encoder_layers
      __lowerCamelCase    		=					scale_embedding  # scale factor will be sqrt(d_model) if True

      super().__init__(
          pad_token_id=__UpperCamelCase ,				bos_token_id=__UpperCamelCase ,				eos_token_id=__UpperCamelCase ,				is_encoder_decoder=__UpperCamelCase ,				decoder_start_token_id=__UpperCamelCase ,				encoder_no_repeat_ngram_size=__UpperCamelCase ,				forced_eos_token_id=__UpperCamelCase ,				**__UpperCamelCase ,				)






class      _SCREAMING_SNAKE_CASE							(			_lowerCamelCase				):



   '''simple docstring'''



   @property
   def    _A				(	self	):


      '''simple docstring'''

      if self.task in ["default", "seq2seq-lm"]:
         __lowerCamelCase    		=					OrderedDict(
             [
                 ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                 ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
             ]	)
         if self.use_past:
            __lowerCamelCase    		=					{0: 'batch'}
            __lowerCamelCase    		=					{0: 'batch', 1: 'past_decoder_sequence + sequence'}
         else:
            __lowerCamelCase    		=					{0: 'batch', 1: 'decoder_sequence'}
            __lowerCamelCase    		=					{0: 'batch', 1: 'decoder_sequence'}
         if self.use_past:
            self.fill_with_past_key_values_(__UpperCamelCase ,				direction='inputs'	)
      elif self.task == "causal-lm":
         __lowerCamelCase    		=					OrderedDict(
             [
                 ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                 ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
             ]	)
         if self.use_past:
            __lowerCamelCase    		=					self.num_layers
            for i in range(__UpperCamelCase	):
               __lowerCamelCase    		=					{0: 'batch', 2: 'past_sequence + sequence'}
               __lowerCamelCase    		=					{0: 'batch', 2: 'past_sequence + sequence'}
      else:
         __lowerCamelCase    		=					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    _A				(	self	):


      '''simple docstring'''

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







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE = -1 ,				_SCREAMING_SNAKE_CASE = -1 ,				_SCREAMING_SNAKE_CASE = False ,				_SCREAMING_SNAKE_CASE = None ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          __UpperCamelCase ,				__UpperCamelCase ,				__UpperCamelCase ,				__UpperCamelCase ,				__UpperCamelCase	)
      # Generate decoder inputs
      __lowerCamelCase    		=					seq_length if not self.use_past else 1
      __lowerCamelCase    		=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          __UpperCamelCase ,				__UpperCamelCase ,				__UpperCamelCase ,				__UpperCamelCase ,				__UpperCamelCase	)
      __lowerCamelCase    		=					{F'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
      __lowerCamelCase    		=					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
         __lowerCamelCase    		=					common_inputs['input_ids'].shape
         __lowerCamelCase    		=					common_inputs['decoder_input_ids'].shape[1]
         __lowerCamelCase    		=					self.num_attention_heads
         __lowerCamelCase    		=					(
             batch,
             num_encoder_attention_heads,
             encoder_seq_length,
             self._config.hidden_size // num_encoder_attention_heads,
         )
         __lowerCamelCase    		=					decoder_seq_length
         __lowerCamelCase    		=					(
             batch,
             num_decoder_attention_heads,
             decoder_past_length,
             self._config.hidden_size // num_decoder_attention_heads,
         )
         __lowerCamelCase    		=					torch.cat(
             [common_inputs['decoder_attention_mask'], torch.ones(__UpperCamelCase ,				__UpperCamelCase	)] ,				dim=1	)
         __lowerCamelCase    		=					[]
         __lowerCamelCase    		=					self.num_layers

         for _ in range(__UpperCamelCase	):
            common_inputs["past_key_values"].append(
                (
                    torch.zeros(__UpperCamelCase	),
                    torch.zeros(__UpperCamelCase	),
                    torch.zeros(__UpperCamelCase	),
                    torch.zeros(__UpperCamelCase	),
                )	)
      return common_inputs







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE = -1 ,				_SCREAMING_SNAKE_CASE = -1 ,				_SCREAMING_SNAKE_CASE = False ,				_SCREAMING_SNAKE_CASE = None ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          __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
         __lowerCamelCase    		=					common_inputs['input_ids'].shape
         __lowerCamelCase    		=					seqlen
         __lowerCamelCase    		=					self.num_layers
         __lowerCamelCase    		=					self.num_attention_heads
         __lowerCamelCase    		=					(
             batch,
             num_encoder_attention_heads,
             past_key_values_length,
             self._config.hidden_size // num_encoder_attention_heads,
         )
         __lowerCamelCase    		=					common_inputs['attention_mask'].dtype
         __lowerCamelCase    		=					torch.cat(
             [common_inputs['attention_mask'], torch.ones(__UpperCamelCase ,				__UpperCamelCase ,				dtype=__UpperCamelCase	)] ,				dim=1	)
         __lowerCamelCase    		=					[
             (torch.zeros(__UpperCamelCase	), torch.zeros(__UpperCamelCase	)) for _ in range(__UpperCamelCase	)
         ]
      return common_inputs







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE = -1 ,				_SCREAMING_SNAKE_CASE = -1 ,				_SCREAMING_SNAKE_CASE = False ,				_SCREAMING_SNAKE_CASE = None ,				):


      '''simple docstring'''

      __lowerCamelCase    		=					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
      __lowerCamelCase    		=					tokenizer.num_special_tokens_to_add(__UpperCamelCase	)
      __lowerCamelCase    		=					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
      __lowerCamelCase    		=					[' '.join([tokenizer.unk_token]	) * seq_length] * batch_size
      __lowerCamelCase    		=					dict(tokenizer(__UpperCamelCase ,				return_tensors=__UpperCamelCase	)	)
      return common_inputs







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE = -1 ,				_SCREAMING_SNAKE_CASE = -1 ,				_SCREAMING_SNAKE_CASE = False ,				_SCREAMING_SNAKE_CASE = None ,				):


      '''simple docstring'''

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

      elif self.task == "causal-lm":
         __lowerCamelCase    		=					self._generate_dummy_inputs_for_causal_lm(
             __UpperCamelCase ,				batch_size=__UpperCamelCase ,				seq_length=__UpperCamelCase ,				is_pair=__UpperCamelCase ,				framework=__UpperCamelCase	)
      else:
         __lowerCamelCase    		=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             __UpperCamelCase ,				batch_size=__UpperCamelCase ,				seq_length=__UpperCamelCase ,				is_pair=__UpperCamelCase ,				framework=__UpperCamelCase	)

      return common_inputs







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE	):


      '''simple docstring'''

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







   def    _A				(	self ,				_SCREAMING_SNAKE_CASE ,				_SCREAMING_SNAKE_CASE	):


      '''simple docstring'''

      if direction not in ["inputs", "outputs"]:
         raise ValueError(F'''direction must either be \"inputs\" or \"outputs\", but {direction} was given'''	)

      __lowerCamelCase    		=					'past_key_values' if direction == 'inputs' else 'present'
      __lowerCamelCase    		=					self.num_layers

      __lowerCamelCase    		=					'past_encoder_sequence'
      __lowerCamelCase    		=					'past_decoder_sequence' if direction == 'inputs' else 'past_decoder_sequence + sequence'

      for i in range(__UpperCamelCase	):
         __lowerCamelCase    		=					{0: 'batch', 2: decoder_sequence}
         __lowerCamelCase    		=					{0: 'batch', 2: decoder_sequence}
         __lowerCamelCase    		=					{0: 'batch', 2: encoder_sequence}
         __lowerCamelCase    		=					{0: 'batch', 2: encoder_sequence}







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase__	:  int						=  {
    '''configuration_switch_transformers''': [
        '''SWITCH_TRANSFORMERS_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''SwitchTransformersConfig''',
        '''SwitchTransformersOnnxConfig''',
    ]
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowerCAmelCase__	:  List[Any]						=  [
				    '''SWITCH_TRANSFORMERS_PRETRAINED_MODEL_ARCHIVE_LIST''',
				    '''SwitchTransformersEncoderModel''',
				    '''SwitchTransformersForConditionalGeneration''',
				    '''SwitchTransformersModel''',
				    '''SwitchTransformersPreTrainedModel''',
				    '''SwitchTransformersTop1Router''',
				    '''SwitchTransformersSparseMLP''',
				]


if TYPE_CHECKING:
				from .configuration_switch_transformers import (
				    SWITCH_TRANSFORMERS_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    SwitchTransformersConfig,
				    SwitchTransformersOnnxConfig,
				)

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_switch_transformers import (
								    SWITCH_TRANSFORMERS_PRETRAINED_MODEL_ARCHIVE_LIST,
								    SwitchTransformersEncoderModel,
								    SwitchTransformersForConditionalGeneration,
								    SwitchTransformersModel,
								    SwitchTransformersPreTrainedModel,
								    SwitchTransformersSparseMLP,
								    SwitchTransformersTopaRouter,
								)


else:
				import sys

				lowerCAmelCase__	:  Union[str, Any]						=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


