


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


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

snake_case    :   List[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 						_snake_case  (				lowerCamelCase_							):
 SCREAMING_SNAKE_CASE__				=	'''blenderbot-small'''
 SCREAMING_SNAKE_CASE__				=	['''past_key_values''']
 SCREAMING_SNAKE_CASE__				=	{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}




 def __init__(		self ,  _lowerCamelCase=5_0265 ,  _lowerCamelCase=512 ,  _lowerCamelCase=8 ,  _lowerCamelCase=2048 ,  _lowerCamelCase=16 ,  _lowerCamelCase=8 ,  _lowerCamelCase=2048 ,  _lowerCamelCase=16 ,  _lowerCamelCase=0.0 ,  _lowerCamelCase=0.0 ,  _lowerCamelCase=True ,  _lowerCamelCase=True ,  _lowerCamelCase="gelu" ,  _lowerCamelCase=512 ,  _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 ,  ):
       a						:Tuple										=	vocab_size
       a						:int										=	max_position_embeddings
       a						:List[Any]										=	d_model
       a						:Tuple										=	encoder_ffn_dim
       a						:str										=	encoder_layers
       a						:Optional[Any]										=	encoder_attention_heads
       a						:Dict										=	decoder_ffn_dim
       a						:int										=	decoder_layers
       a						:List[str]										=	decoder_attention_heads
       a						:int										=	dropout
       a						:Dict										=	attention_dropout
       a						:Tuple										=	activation_dropout
       a						:Optional[int]										=	activation_function
       a						:Optional[int]										=	init_std
       a						:int										=	encoder_layerdrop
       a						:Any										=	decoder_layerdrop
       a						:Dict										=	use_cache
       a						:Optional[Any]										=	encoder_layers
       a						:Optional[int]										=	scale_embedding  # scale factor will be sqrt(d_model) if True

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







class 						_snake_case  (				lowerCamelCase_							):




 @property
 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       if self.task in ["default", "seq2seq-lm"]:
             a						:List[str]										=	OrderedDict(
                 [
                     ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                     ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ]   )

             if self.use_past:
                   a						:Optional[Any]										=	{0: '''batch'''}
                   a						:Any										=	{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
             else:
                   a						:List[Any]										=	{0: '''batch''', 1: '''decoder_sequence'''}
                   a						:int										=	{0: '''batch''', 1: '''decoder_sequence'''}

             if self.use_past:
                   self.fill_with_past_key_values_(__snake_case ,  direction='''inputs'''   )
       elif self.task == "causal-lm":
             # TODO: figure this case out.
             a						:Optional[int]										=	OrderedDict(
                 [
                     ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                     ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ]   )
             if self.use_past:
                   a							,    a						:List[str]										=	self.num_layers
                   for i in range(__snake_case   ):
                         a						:Union[str, Any]										=	{0: '''batch''', 2: '''past_sequence + sequence'''}
                         a						:int										=	{0: '''batch''', 2: '''past_sequence + sequence'''}
       else:
             a						:str										=	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   ):
       if self.task in ["default", "seq2seq-lm"]:
             a						:int										=	super().outputs
       else:
             a						:List[str]										=	super(__snake_case ,  self   ).outputs
             if self.use_past:
                   a							,    a						:List[str]										=	self.num_layers
                   for i in range(__snake_case   ):
                         a						:str										=	{0: '''batch''', 2: '''past_sequence + sequence'''}
                         a						:List[Any]										=	{0: '''batch''', 2: '''past_sequence + sequence'''}
       return common_outputs




 def 	SCREAMING_SNAKE_CASE__    (		self ,  _lowerCamelCase ,  _lowerCamelCase = -1 ,  _lowerCamelCase = -1 ,  _lowerCamelCase = False ,  _lowerCamelCase = None ,  ):
       a						:List[Any]										=	self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           __snake_case ,  __snake_case ,  __snake_case ,  __snake_case ,  __snake_case   )

       # Generate decoder inputs
       a						:Tuple										=	seq_length if not self.use_past else 1
       a						:Tuple										=	self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           __snake_case ,  __snake_case ,  __snake_case ,  __snake_case ,  __snake_case   )
       a						:str										=	{F'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
       a						:Optional[Any]										=	dict(**__snake_case ,  **__snake_case   )

       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						:Optional[Any]										=	common_inputs['''input_ids'''].shape
             a						:Tuple										=	common_inputs['''decoder_input_ids'''].shape[1]
             a							,    a						:Union[str, Any]										=	self.num_attention_heads
             a						:Union[str, Any]										=	(
                 batch,
                 num_encoder_attention_heads,
                 encoder_seq_length,
                 self._config.hidden_size // num_encoder_attention_heads,
             )
             a						:List[Any]										=	decoder_seq_length + 3
             a						:str										=	(
                 batch,
                 num_decoder_attention_heads,
                 decoder_past_length,
                 self._config.hidden_size // num_decoder_attention_heads,
             )

             a						:Optional[int]										=	torch.cat(
                 [common_inputs['''decoder_attention_mask'''], torch.ones(__snake_case ,  __snake_case   )] ,  dim=1   )

             a						:List[str]										=	[]
             # If the number of encoder and decoder layers are present in the model configuration, both are considered
             a							,    a						:Union[str, Any]										=	self.num_layers
             a						:Dict										=	min(__snake_case ,  __snake_case   )
             a						:List[Any]										=	max(__snake_case ,  __snake_case   ) - min_num_layers
             a						:List[str]										=	'''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

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




 def 	SCREAMING_SNAKE_CASE__    (		self ,  _lowerCamelCase ,  _lowerCamelCase = -1 ,  _lowerCamelCase = -1 ,  _lowerCamelCase = False ,  _lowerCamelCase = None ,  ):
       a						:int										=	self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           __snake_case ,  __snake_case ,  __snake_case ,  __snake_case ,  __snake_case   )

       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						:Optional[Any]										=	common_inputs['''input_ids'''].shape
             # Not using the same length for past_key_values
             a						:Dict										=	seqlen + 2
             a							,    a						:str										=	self.num_layers
             a							,    a						:Optional[int]										=	self.num_attention_heads
             a						:Optional[int]										=	(
                 batch,
                 num_encoder_attention_heads,
                 past_key_values_length,
                 self._config.hidden_size // num_encoder_attention_heads,
             )

             a						:str										=	common_inputs['''attention_mask'''].dtype
             a						:Tuple										=	torch.cat(
                 [common_inputs['''attention_mask'''], torch.ones(__snake_case ,  __snake_case ,  dtype=__snake_case   )] ,  dim=1   )
             a						:int										=	[
                 (torch.zeros(__snake_case   ), torch.zeros(__snake_case   )) for _ in range(__snake_case   )
             ]
       return common_inputs




 def 	SCREAMING_SNAKE_CASE__    (		self ,  _lowerCamelCase ,  _lowerCamelCase = -1 ,  _lowerCamelCase = -1 ,  _lowerCamelCase = False ,  _lowerCamelCase = None ,  ):
       # Copied from OnnxConfig.generate_dummy_inputs
       # Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
       # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
       a						:Optional[Any]										=	compute_effective_axis_dimension(
           __snake_case ,  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						:Tuple										=	tokenizer.num_special_tokens_to_add(__snake_case   )
       a						:str										=	compute_effective_axis_dimension(
           __snake_case ,  fixed_dimension=OnnxConfig.default_fixed_sequence ,  num_token_to_add=__snake_case   )

       # Generate dummy inputs according to compute batch and sequence
       a						:Union[str, Any]										=	[''' '''.join([tokenizer.unk_token]   ) * seq_length] * batch_size
       a						:str										=	dict(tokenizer(__snake_case ,  return_tensors=__snake_case   )   )
       return common_inputs




 def 	SCREAMING_SNAKE_CASE__    (		self ,  _lowerCamelCase ,  _lowerCamelCase = -1 ,  _lowerCamelCase = -1 ,  _lowerCamelCase = False ,  _lowerCamelCase = None ,  ):
       if self.task in ["default", "seq2seq-lm"]:
             a						:List[Any]										=	self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                 __snake_case ,  batch_size=__snake_case ,  seq_length=__snake_case ,  is_pair=__snake_case ,  framework=__snake_case   )

       elif self.task == "causal-lm":
             a						:Optional[Any]										=	self._generate_dummy_inputs_for_causal_lm(
                 __snake_case ,  batch_size=__snake_case ,  seq_length=__snake_case ,  is_pair=__snake_case ,  framework=__snake_case   )
       else:
             a						:List[Any]										=	self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 __snake_case ,  batch_size=__snake_case ,  seq_length=__snake_case ,  is_pair=__snake_case ,  framework=__snake_case   )

       return common_inputs




 def 	SCREAMING_SNAKE_CASE__    (		self ,  _lowerCamelCase ,  _lowerCamelCase ,  _lowerCamelCase ,  _lowerCamelCase   ):
       if self.task in ["default", "seq2seq-lm"]:
             a						:Tuple										=	super()._flatten_past_key_values_(__snake_case ,  __snake_case ,  __snake_case ,  __snake_case   )
       else:
             a						:List[Any]										=	super(__snake_case ,  self   )._flatten_past_key_values_(
                 __snake_case ,  __snake_case ,  __snake_case ,  __snake_case   )









from collections import OrderedDict
from typing import List, Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


snake_case    :   Union[str, Any]	    =					logging.get_logger(__name__)

snake_case    :   List[str]	    =					{
    '''google/efficientnet-b7''': '''https://huggingface.co/google/efficientnet-b7/resolve/main/config.json''',
}







class 		_snake_case  (				_snake_case							):
 SCREAMING_SNAKE_CASE__				=	'efficientnet'




 def __init__(		self ,  _lowerCamelCase = 3 ,  _lowerCamelCase = 600 ,  _lowerCamelCase = 2.0 ,  _lowerCamelCase = 3.1 ,  _lowerCamelCase = 8 ,  _lowerCamelCase = [3, 3, 5, 3, 5, 5, 3] ,  _lowerCamelCase = [32, 16, 24, 40, 80, 112, 192] ,  _lowerCamelCase = [16, 24, 40, 80, 112, 192, 320] ,  _lowerCamelCase = [] ,  _lowerCamelCase = [1, 2, 2, 2, 1, 2, 1] ,  _lowerCamelCase = [1, 2, 2, 3, 3, 4, 1] ,  _lowerCamelCase = [1, 6, 6, 6, 6, 6, 6] ,  _lowerCamelCase = 0.25 ,  _lowerCamelCase = "swish" ,  _lowerCamelCase = 2560 ,  _lowerCamelCase = "mean" ,  _lowerCamelCase = 0.02 ,  _lowerCamelCase = 0.001 ,  _lowerCamelCase = 0.99 ,  _lowerCamelCase = 0.5 ,  _lowerCamelCase = 0.2 ,  **_lowerCamelCase ,  ):
       super().__init__(**_lowerCamelCase   )

       a						:Optional[int]										=	num_channels
       a						:List[str]										=	image_size
       a						:int										=	width_coefficient
       a						:Optional[Any]										=	depth_coefficient
       a						:Any										=	depth_divisor
       a						:Any										=	kernel_sizes
       a						:Tuple										=	in_channels
       a						:Union[str, Any]										=	out_channels
       a						:Any										=	depthwise_padding
       a						:Any										=	strides
       a						:Optional[Any]										=	num_block_repeats
       a						:Tuple										=	expand_ratios
       a						:Dict										=	squeeze_expansion_ratio
       a						:int										=	hidden_act
       a						:Dict										=	hidden_dim
       a						:Tuple										=	pooling_type
       a						:Any										=	initializer_range
       a						:Tuple										=	batch_norm_eps
       a						:Optional[int]										=	batch_norm_momentum
       a						:List[Any]										=	dropout_rate
       a						:Optional[int]										=	drop_connect_rate
       a						:Tuple										=	sum(_lowerCamelCase   ) * 4







class 		_snake_case  (				_snake_case							):
 SCREAMING_SNAKE_CASE__				=	version.parse('1.11'							)




 @property
 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       return OrderedDict(
           [
               ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
           ]   )




 @property
 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       return 1e-5





