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


__a    :	Optional[Any]         =    logging.get_logger(__name__)

__a    :	Any         =    {
    '''facebook/blenderbot_small-90M''': '''https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/config.json''',
    # See all BlenderbotSmall models at https://huggingface.co/models?filter=blenderbot_small
}




class   _UpperCamelCase (		_UpperCAmelCase					):


			"""simple docstring"""






			__a    :					List[Any]     					=		'''blenderbot-small'''
			__a    :					Any     					=		['''past_key_values''']
			__a    :					Optional[Any]     					=		{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}





			def __init__(  self ,  lowerCAmelCase__=5_02_65 ,  lowerCAmelCase__=5_12 ,  lowerCAmelCase__=8 ,  lowerCAmelCase__=20_48 ,  lowerCAmelCase__=16 ,  lowerCAmelCase__=8 ,  lowerCAmelCase__=20_48 ,  lowerCAmelCase__=16 ,  lowerCAmelCase__=0.0 ,  lowerCAmelCase__=0.0 ,  lowerCAmelCase__=True ,  lowerCAmelCase__=True ,  lowerCAmelCase__="gelu" ,  lowerCAmelCase__=5_12 ,  lowerCAmelCase__=0.1 ,  lowerCAmelCase__=0.0 ,  lowerCAmelCase__=0.0 ,  lowerCAmelCase__=0.02 ,  lowerCAmelCase__=1 ,  lowerCAmelCase__=False ,  lowerCAmelCase__=0 ,  lowerCAmelCase__=1 ,  lowerCAmelCase__=2 ,  lowerCAmelCase__=2 ,  **lowerCAmelCase__ ,  )	->   Any:

							'''simple docstring'''


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

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




class   _UpperCamelCase (		_UpperCAmelCase					):


			"""simple docstring"""






			@property
			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   Optional[Any]:

							'''simple docstring'''


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

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

											if self.use_past:
															self.fill_with_past_key_values_(lowercase__ ,  direction='''inputs'''		)
							elif self.task == "causal-lm":
											# TODO: figure this case out.
											__lowercase					     =				OrderedDict(
											    [
											        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
											        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
											    ]		)
											if self.use_past:
															__lowercase     ,	__lowercase					     =				self.num_layers
															for i in range(lowercase__		):
																			__lowercase					     =				{0: '''batch''', 2: '''past_sequence + sequence'''}
																			__lowercase					     =				{0: '''batch''', 2: '''past_sequence + sequence'''}
							else:
											__lowercase					     =				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
			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   Any:

							'''simple docstring'''


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





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ = -1 ,  lowerCAmelCase__ = -1 ,  lowerCAmelCase__ = False ,  lowerCAmelCase__ = None ,  )	->   Tuple:

							'''simple docstring'''


							__lowercase					     =				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowercase__ ,  lowercase__ ,  lowercase__ ,  lowercase__ ,  lowercase__		)

							# Generate decoder inputs
							__lowercase					     =				seq_length if not self.use_past else 1
							__lowercase					     =				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowercase__ ,  lowercase__ ,  lowercase__ ,  lowercase__ ,  lowercase__		)
							__lowercase					     =				{F"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
							__lowercase					     =				dict(**lowercase__ ,  **lowercase__		)

							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
											__lowercase					     =				common_inputs['''decoder_input_ids'''].shape[1]
											__lowercase     ,	__lowercase					     =				self.num_attention_heads
											__lowercase					     =				(
											    batch,
											    num_encoder_attention_heads,
											    encoder_seq_length,
											    self._config.hidden_size // num_encoder_attention_heads,
											)
											__lowercase					     =				decoder_seq_length + 3
											__lowercase					     =				(
											    batch,
											    num_decoder_attention_heads,
											    decoder_past_length,
											    self._config.hidden_size // num_decoder_attention_heads,
											)

											__lowercase					     =				torch.cat(
											    [common_inputs['''decoder_attention_mask'''], torch.ones(lowercase__ ,  lowercase__		)] ,  dim=1		)

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

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





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ = -1 ,  lowerCAmelCase__ = -1 ,  lowerCAmelCase__ = False ,  lowerCAmelCase__ = None ,  )	->   str:

							'''simple docstring'''


							__lowercase					     =				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowercase__ ,  lowercase__ ,  lowercase__ ,  lowercase__ ,  lowercase__		)

							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     ,	__lowercase					     =				self.num_layers
											__lowercase     ,	__lowercase					     =				self.num_attention_heads
											__lowercase					     =				(
											    batch,
											    num_encoder_attention_heads,
											    past_key_values_length,
											    self._config.hidden_size // num_encoder_attention_heads,
											)

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





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ = -1 ,  lowerCAmelCase__ = -1 ,  lowerCAmelCase__ = False ,  lowerCAmelCase__ = None ,  )	->   List[str]:

							'''simple docstring'''


							__lowercase					     =				compute_effective_axis_dimension(
							    lowercase__ ,  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
							__lowercase					     =				tokenizer.num_special_tokens_to_add(lowercase__		)
							__lowercase					     =				compute_effective_axis_dimension(
							    lowercase__ ,  fixed_dimension=OnnxConfig.default_fixed_sequence ,  num_token_to_add=lowercase__		)

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





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ = -1 ,  lowerCAmelCase__ = -1 ,  lowerCAmelCase__ = False ,  lowerCAmelCase__ = None ,  )	->   Any:

							'''simple docstring'''


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

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

							return common_inputs





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   List[str]:

							'''simple docstring'''


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


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_speech_available, is_torch_available


_lowerCamelCase      :					int					    =      {
    '''configuration_audio_spectrogram_transformer''': [
        '''AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''ASTConfig''',
    ]
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _lowerCamelCase      :					Tuple					    =      [
       '''AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''ASTForAudioClassification''',
       '''ASTModel''',
       '''ASTPreTrainedModel''',
   ]

try:
   if not is_speech_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _lowerCamelCase      :					Optional[Any]					    =      ['''ASTFeatureExtractor''']

if TYPE_CHECKING:
   from .configuration_audio_spectrogram_transformer import (
       AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
       ASTConfig,
   )

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_audio_spectrogram_transformer import (
          AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
          ASTForAudioClassification,
          ASTModel,
          ASTPreTrainedModel,
      )

   try:
      if not is_speech_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_audio_spectrogram_transformer import ASTFeatureExtractor


else:
   import sys

   _lowerCamelCase      :					Optional[int]					    =      _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


