





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								=							logging.get_logger(__name__)

snake_case								=							{
    """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 					A_					(   UpperCAmelCase						):







       """simple docstring"""





       SCREAMING_SNAKE_CASE_   :			Union[str, Any]  			=	'''blenderbot-small'''
       SCREAMING_SNAKE_CASE_   :			int  			=	['''past_key_values''']
       SCREAMING_SNAKE_CASE_   :			Tuple  			=	{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}







       def __init__(     self						:						List[str]    ,__A						:						List[Any]=5_0265    ,__A						:						str=512    ,__A						:						Optional[int]=8    ,__A						:						Any=2048    ,__A						:						Tuple=16    ,__A						:						str=8    ,__A						:						int=2048    ,__A						:						List[str]=16    ,__A						:						Optional[int]=0.0    ,__A						:						Any=0.0    ,__A						:						int=True    ,__A						:						List[Any]=True    ,__A						:						Tuple="gelu"    ,__A						:						Any=512    ,__A						:						Dict=0.1    ,__A						:						Tuple=0.0    ,__A						:						int=0.0    ,__A						:						int=0.02    ,__A						:						Dict=1    ,__A						:						str=False    ,__A						:						Dict=0    ,__A						:						Union[str, Any]=1    ,__A						:						Optional[int]=2    ,__A						:						List[str]=2    ,**__A						:						Tuple    ,)    ->       Tuple:
         _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=__A    ,bos_token_id=__A    ,eos_token_id=__A    ,is_encoder_decoder=__A    ,decoder_start_token_id=__A    ,forced_eos_token_id=__A    ,**__A    ,)





class 					A_					(   UpperCAmelCase						):







       """simple docstring"""





       @property
       def  __UpperCAmelCase			(     self						:						List[Any]	)    ->       Mapping[str, Mapping[int, str]]:
         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_(__A    ,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(__A	):
               _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  __UpperCAmelCase			(     self						:						Dict	)    ->       Mapping[str, Mapping[int, str]]:
         if self.task in ["default", "seq2seq-lm"]:
           _lowercase						    =			super().outputs
         else:
           _lowercase						    =			super(__A    ,self	).outputs
           if self.use_past:
             _lowercase    ,		_lowercase						    =			self.num_layers
             for i in range(__A	):
               _lowercase						    =			{0: 'batch', 2: 'past_sequence + sequence'}
               _lowercase						    =			{0: 'batch', 2: 'past_sequence + sequence'}
         return common_outputs







       def  __UpperCAmelCase			(     self						:						Optional[int]    ,__A						:						PreTrainedTokenizer    ,__A						:						int = -1    ,__A						:						int = -1    ,__A						:						bool = False    ,__A						:						Optional[TensorType] = None    ,)    ->       Mapping[str, Any]:
         _lowercase						    =			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             __A    ,__A    ,__A    ,__A    ,__A	)

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

         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(__A    ,__A	)]    ,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(__A    ,__A	)
           _lowercase						    =			max(__A    ,__A	) - min_num_layers
           _lowercase						    =			'encoder' if num_encoder_layers > num_decoder_layers else 'decoder'

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







       def  __UpperCAmelCase			(     self						:						List[Any]    ,__A						:						PreTrainedTokenizer    ,__A						:						int = -1    ,__A						:						int = -1    ,__A						:						bool = False    ,__A						:						Optional[TensorType] = None    ,)    ->       Mapping[str, Any]:
         _lowercase						    =			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             __A    ,__A    ,__A    ,__A    ,__A	)

         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(__A    ,__A    ,dtype=__A	)]    ,dim=1	)
           _lowercase						    =			[
               (torch.zeros(__A	), torch.zeros(__A	)) for _ in range(__A	)
           ]
         return common_inputs







       def  __UpperCAmelCase			(     self						:						Any    ,__A						:						PreTrainedTokenizer    ,__A						:						int = -1    ,__A						:						int = -1    ,__A						:						bool = False    ,__A						:						Optional[TensorType] = None    ,)    ->       Mapping[str, Any]:
         # 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
         _lowercase						    =			compute_effective_axis_dimension(
             __A    ,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(__A	)
         _lowercase						    =			compute_effective_axis_dimension(
             __A    ,fixed_dimension=OnnxConfig.default_fixed_sequence    ,num_token_to_add=__A	)

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







       def  __UpperCAmelCase			(     self						:						Dict    ,__A						:						PreTrainedTokenizer    ,__A						:						int = -1    ,__A						:						int = -1    ,__A						:						bool = False    ,__A						:						Optional[TensorType] = None    ,)    ->       Mapping[str, Any]:
         if self.task in ["default", "seq2seq-lm"]:
           _lowercase						    =			self._generate_dummy_inputs_for_default_and_seqaseq_lm(
               __A    ,batch_size=__A    ,seq_length=__A    ,is_pair=__A    ,framework=__A	)

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

         return common_inputs







       def  __UpperCAmelCase			(     self						:						List[str]    ,__A						:						Dict    ,__A						:						Any    ,__A						:						List[Any]    ,__A						:						Tuple	)    ->       Union[str, Any]:
         if self.task in ["default", "seq2seq-lm"]:
           _lowercase						    =			super()._flatten_past_key_values_(__A    ,__A    ,__A    ,__A	)
         else:
           _lowercase						    =			super(__A    ,self	)._flatten_past_key_values_(
               __A    ,__A    ,__A    ,__A	)


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


a__												=						logging.get_logger(__name__)

a__												=						{
    '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/config.json''',
    '''funnel-transformer/small-base''': '''https://huggingface.co/funnel-transformer/small-base/resolve/main/config.json''',
    '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/config.json''',
    '''funnel-transformer/medium-base''': '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/config.json''',
    '''funnel-transformer/intermediate''': (
        '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/config.json'''
    ),
    '''funnel-transformer/intermediate-base''': (
        '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/config.json'''
    ),
    '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/config.json''',
    '''funnel-transformer/large-base''': '''https://huggingface.co/funnel-transformer/large-base/resolve/main/config.json''',
    '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/config.json''',
    '''funnel-transformer/xlarge-base''': '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/config.json''',
}

class 							UpperCAmelCase_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		Optional[int]             =       "funnel"
							UpperCAmelCase__			:		Tuple             =       {
							    "hidden_size": "d_model",
							    "num_attention_heads": "n_head",
							}


							def __init__(     self			,				_a=3_0_5_2_2			,				_a=[4, 4, 4]			,				_a=None			,				_a=2			,				_a=7_6_8			,				_a=1_2			,				_a=6_4			,				_a=3_0_7_2			,				_a="gelu_new"			,				_a=0.1			,				_a=0.1			,				_a=0.0			,				_a=0.1			,				_a=None			,				_a=1e-9			,				_a="mean"			,				_a="relative_shift"			,				_a=True			,				_a=True			,				_a=True			,				**_a			,				)       ->       List[Any]:
												_a      :       Optional[int]   =						vocab_size
												_a      :       Dict   =						block_sizes
												_a      :       Optional[int]   =						[1] * len(_a			) if block_repeats is None else block_repeats
												assert len(_a			) == len(
												    self.block_repeats			), "`block_sizes` and `block_repeats` should have the same length."
												_a      :       int   =						num_decoder_layers
												_a      :       List[str]   =						d_model
												_a      :       Optional[Any]   =						n_head
												_a      :       Tuple   =						d_head
												_a      :       Dict   =						d_inner
												_a      :       List[str]   =						hidden_act
												_a      :       int   =						hidden_dropout
												_a      :       Union[str, Any]   =						attention_dropout
												_a      :       Tuple   =						activation_dropout
												_a      :       Optional[Any]   =						initializer_range
												_a      :       Dict   =						initializer_std
												_a      :       Union[str, Any]   =						layer_norm_eps
												assert pooling_type in [
												    "mean",
												    "max",
												], F"""Got {pooling_type} for `pooling_type` but only 'mean' and 'max' are supported."""
												_a      :       Any   =						pooling_type
												assert attention_type in [
												    "relative_shift",
												    "factorized",
												], F"""Got {attention_type} for `attention_type` but only 'relative_shift' and 'factorized' are supported."""
												_a      :       Optional[Any]   =						attention_type
												_a      :       int   =						separate_cls
												_a      :       Tuple   =						truncate_seq
												_a      :       List[Any]   =						pool_q_only

												super().__init__(**_a			)


							@property
							def 							__lowercase							(     self			)       ->       Tuple:
												return sum(self.block_sizes			)


							@num_hidden_layers.setter
							def 							__lowercase							(     self			,				_a			)       ->       List[str]:
												raise NotImplementedError(
												    '''This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`.'''			)


							@property
							def 							__lowercase							(     self			)       ->       Optional[int]:
												return len(self.block_sizes			)




							@num_blocks.setter
							def 							__lowercase							(     self			,				_a			)       ->       Dict:
												raise NotImplementedError('''This model does not support the setting of `num_blocks`. Please set `block_sizes`.'''			)



