code: 
  
  
  
  """simple docstring"""
  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					:Dict  =      logging.get_logger(__name__)
  
  _lowerCAmelCase					:int  =      {
      'google/bigbird-pegasus-large-arxiv': (
          'https://huggingface.co/google/bigbird-pegasus-large-arxiv/resolve/main/config.json'
      ),
      'google/bigbird-pegasus-large-pubmed': (
          'https://huggingface.co/google/bigbird-pegasus-large-pubmed/resolve/main/config.json'
      ),
      'google/bigbird-pegasus-large-bigpatent': (
          'https://huggingface.co/google/bigbird-pegasus-large-bigpatent/resolve/main/config.json'
      ),
      # See all BigBirdPegasus models at https://huggingface.co/models?filter=bigbird_pegasus
  }
  class 							_UpperCAmelCase							(				__UpperCAmelCase   ):
  
  
  
  
  
       '''simple docstring'''
  
  
  
       a__             ='''bigbird_pegasus'''
       a__             =['''past_key_values''']
       a__             ={
           '''num_attention_heads''': '''encoder_attention_heads''',
           '''hidden_size''': '''d_model''',
           '''attention_probs_dropout_prob''': '''attention_dropout''',
       }
  
  
  
  
  
       def __init__(      self ,			A=9_6_1_0_3 ,			A=4_0_9_6 ,			A=1_6 ,			A=4_0_9_6 ,			A=1_6 ,			A=1_6 ,			A=4_0_9_6 ,			A=1_6 ,			A=0.0 ,			A=0.0 ,			A=True ,			A=True ,			A="gelu_new" ,			A=1_0_2_4 ,			A=0.1 ,			A=0.0 ,			A=0.0 ,			A=0.02 ,			A=2 ,			A=0.0 ,			A=True ,			A=0 ,			A=2 ,			A=1 ,			A="block_sparse" ,			A=6_4 ,			A=3 ,			A=False ,			**A ,			)							->      Tuple:
           _UpperCAmelCase							:						List[str]       							=					vocab_size
           _UpperCAmelCase							:						Optional[Any]       							=					max_position_embeddings
           _UpperCAmelCase							:						Any       							=					d_model
           _UpperCAmelCase							:						Dict       							=					encoder_ffn_dim
           _UpperCAmelCase							:						Tuple       							=					encoder_layers
           _UpperCAmelCase							:						Dict       							=					encoder_attention_heads
           _UpperCAmelCase							:						str       							=					decoder_ffn_dim
           _UpperCAmelCase							:						str       							=					decoder_layers
           _UpperCAmelCase							:						Tuple       							=					decoder_attention_heads
           _UpperCAmelCase							:						str       							=					dropout
           _UpperCAmelCase							:						List[str]       							=					attention_dropout
           _UpperCAmelCase							:						Dict       							=					activation_dropout
           _UpperCAmelCase							:						str       							=					activation_function
           _UpperCAmelCase							:						Union[str, Any]       							=					init_std
           _UpperCAmelCase							:						Optional[int]       							=					encoder_layerdrop
           _UpperCAmelCase							:						Tuple       							=					decoder_layerdrop
           _UpperCAmelCase							:						Optional[int]       							=					classifier_dropout
           _UpperCAmelCase							:						str       							=					use_cache
           _UpperCAmelCase							:						List[Any]       							=					encoder_layers
           _UpperCAmelCase							:						List[str]       							=					scale_embedding  # scale factor will be sqrt(d_model) if True
  
           # extra config
           _UpperCAmelCase							:						Optional[Any]       							=					attention_type
           _UpperCAmelCase							:						Any       							=					block_size
           _UpperCAmelCase							:						Any       							=					num_random_blocks
           _UpperCAmelCase							:						Optional[int]       							=					use_bias
  
           super().__init__(
               pad_token_id=lowercase_ ,			bos_token_id=lowercase_ ,			eos_token_id=lowercase_ ,			is_encoder_decoder=lowercase_ ,			decoder_start_token_id=lowercase_ ,			**lowercase_ ,			)
  
  
  
  class 							_UpperCAmelCase							(				__UpperCAmelCase   ):
  
  
  
  
  
       '''simple docstring'''
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      Mapping[str, Mapping[int, str]]:
  
           if self.task in ["default", "seq2seq-lm"]:
               _UpperCAmelCase							:						Dict       							=					OrderedDict(
                   [
                       ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                       ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                   ]	)
  
               if self.use_past:
                   _UpperCAmelCase							:						Any       							=					{0: '''batch'''}
                   _UpperCAmelCase							:						Optional[int]       							=					{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
               else:
                   _UpperCAmelCase							:						Union[str, Any]       							=					{0: '''batch''', 1: '''decoder_sequence'''}
                   _UpperCAmelCase							:						Any       							=					{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.
               _UpperCAmelCase							:						Union[str, Any]       							=					OrderedDict(
                   [
                       ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                       ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                   ]	)
               if self.use_past:
                   _UpperCAmelCase							:						List[str]       							=					self.num_layers
                   for i in range(lowercase_	):
                       _UpperCAmelCase							:						Dict       							=					{0: '''batch''', 2: '''past_sequence + sequence'''}
                       _UpperCAmelCase							:						int       							=					{0: '''batch''', 2: '''past_sequence + sequence'''}
           else:
               _UpperCAmelCase							:						Any       							=					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 				__lowerCAmelCase			(      self	)							->      Mapping[str, Mapping[int, str]]:
  
           if self.task in ["default", "seq2seq-lm"]:
               _UpperCAmelCase							:						str       							=					super().outputs
           else:
               _UpperCAmelCase							:						Optional[Any]       							=					super(lowercase_ ,			self	).outputs
               if self.use_past:
                   _UpperCAmelCase							:						Union[str, Any]       							=					self.num_layers
                   for i in range(lowercase_	):
                       _UpperCAmelCase							:						int       							=					{0: '''batch''', 2: '''past_sequence + sequence'''}
                       _UpperCAmelCase							:						List[Any]       							=					{0: '''batch''', 2: '''past_sequence + sequence'''}
           return common_outputs
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A ,			A = -1 ,			A = -1 ,			A = False ,			A = None ,			)							->      Mapping[str, Any]:
           _UpperCAmelCase							:						Union[str, Any]       							=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               lowercase_ ,			lowercase_ ,			lowercase_ ,			lowercase_ ,			lowercase_	)
  
           # Generate decoder inputs
           _UpperCAmelCase							:						int       							=					seq_length if not self.use_past else 1
           _UpperCAmelCase							:						Union[str, Any]       							=					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               lowercase_ ,			lowercase_ ,			lowercase_ ,			lowercase_ ,			lowercase_	)
           _UpperCAmelCase							:						int       							=					{f'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
           _UpperCAmelCase							:						int       							=					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
               _UpperCAmelCase							:						int       							=					common_inputs['''input_ids'''].shape
               _UpperCAmelCase							:						Optional[Any]       							=					common_inputs['''decoder_input_ids'''].shape[1]
               _UpperCAmelCase							:						Optional[Any]       							=					self.num_attention_heads
               _UpperCAmelCase							:						Optional[Any]       							=					(
                   batch,
                   num_encoder_attention_heads,
                   encoder_seq_length,
                   self._config.hidden_size // num_encoder_attention_heads,
               )
               _UpperCAmelCase							:						int       							=					decoder_seq_length + 3
               _UpperCAmelCase							:						str       							=					(
                   batch,
                   num_decoder_attention_heads,
                   decoder_past_length,
                   self._config.hidden_size // num_decoder_attention_heads,
               )
  
               _UpperCAmelCase							:						List[str]       							=					torch.cat(
                   [common_inputs['''decoder_attention_mask'''], torch.ones(lowercase_ ,			lowercase_	)] ,			dim=1	)
  
               _UpperCAmelCase							:						Optional[int]       							=					[]
               # If the number of encoder and decoder layers are present in the model configuration, both are considered
               _UpperCAmelCase							:						int       							=					self.num_layers
               _UpperCAmelCase							:						Tuple       							=					min(lowercase_ ,			lowercase_	)
               _UpperCAmelCase							:						Union[str, Any]       							=					max(lowercase_ ,			lowercase_	) - min_num_layers
               _UpperCAmelCase							:						Dict       							=					'''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.
               _UpperCAmelCase							:						Optional[int]       							=					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 				__lowerCAmelCase			(      self ,			A ,			A = -1 ,			A = -1 ,			A = False ,			A = None ,			)							->      Mapping[str, Any]:
           _UpperCAmelCase							:						str       							=					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
               _UpperCAmelCase							:						int       							=					common_inputs['''input_ids'''].shape
               # Not using the same length for past_key_values
               _UpperCAmelCase							:						str       							=					seqlen + 2
               _UpperCAmelCase							:						Dict       							=					self.num_layers
               _UpperCAmelCase							:						str       							=					self.num_attention_heads
               _UpperCAmelCase							:						Optional[int]       							=					(
                   batch,
                   num_encoder_attention_heads,
                   past_key_values_length,
                   self._config.hidden_size // num_encoder_attention_heads,
               )
  
               _UpperCAmelCase							:						List[str]       							=					common_inputs['''attention_mask'''].dtype
               _UpperCAmelCase							:						Tuple       							=					torch.cat(
                   [common_inputs['''attention_mask'''], torch.ones(lowercase_ ,			lowercase_ ,			dtype=lowercase_	)] ,			dim=1	)
               _UpperCAmelCase							:						Dict       							=					[
                   (torch.zeros(lowercase_	), torch.zeros(lowercase_	)) for _ in range(lowercase_	)
               ]
           return common_inputs
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A ,			A = -1 ,			A = -1 ,			A = False ,			A = None ,			)							->      Mapping[str, Any]:
           _UpperCAmelCase							:						Optional[Any]       							=					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
           _UpperCAmelCase							:						str       							=					tokenizer.num_special_tokens_to_add(lowercase_	)
           _UpperCAmelCase							:						Any       							=					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
           _UpperCAmelCase							:						int       							=					[''' '''.join([tokenizer.unk_token]	) * seq_length] * batch_size
           _UpperCAmelCase							:						List[Any]       							=					dict(tokenizer(lowercase_ ,			return_tensors=lowercase_	)	)
           return common_inputs
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A ,			A = -1 ,			A = -1 ,			A = False ,			A = None ,			)							->      Mapping[str, Any]:
  
           if self.task in ["default", "seq2seq-lm"]:
               _UpperCAmelCase							:						Tuple       							=					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":
               _UpperCAmelCase							:						int       							=					self._generate_dummy_inputs_for_causal_lm(
                   lowercase_ ,			batch_size=lowercase_ ,			seq_length=lowercase_ ,			is_pair=lowercase_ ,			framework=lowercase_	)
           else:
               _UpperCAmelCase							:						Dict       							=					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 				__lowerCAmelCase			(      self ,			A ,			A ,			A ,			A	)							->      Union[str, Any]:
  
           if self.task in ["default", "seq2seq-lm"]:
               _UpperCAmelCase							:						int       							=					super()._flatten_past_key_values_(lowercase_ ,			lowercase_ ,			lowercase_ ,			lowercase_	)
           else:
               _UpperCAmelCase							:						Optional[int]       							=					super(lowercase_ ,			self	)._flatten_past_key_values_(
                   lowercase_ ,			lowercase_ ,			lowercase_ ,			lowercase_	)
  
  
  
  
  
style_context: 
  
  
  
  """simple docstring"""
  from collections import OrderedDict
  from typing import Any, List, Mapping, Optional
  
  from ... import PreTrainedTokenizer, TensorType, is_torch_available
  from ...configuration_utils import PretrainedConfig
  from ...onnx import OnnxConfigWithPast, PatchingSpec
  from ...utils import logging
  
  
  _lowerCAmelCase					:Union[str, Any]  =      logging.get_logger(__name__)
  
  _lowerCAmelCase					:List[str]  =      {
      'gpt2': 'https://huggingface.co/gpt2/resolve/main/config.json',
      'gpt2-medium': 'https://huggingface.co/gpt2-medium/resolve/main/config.json',
      'gpt2-large': 'https://huggingface.co/gpt2-large/resolve/main/config.json',
      'gpt2-xl': 'https://huggingface.co/gpt2-xl/resolve/main/config.json',
      'distilgpt2': 'https://huggingface.co/distilgpt2/resolve/main/config.json',
  }
  class 							_UpperCAmelCase							(				a   ):
  
  
  
  
  
       '''simple docstring'''
  
  
  
       a__             ='''gpt2'''
       a__             =['''past_key_values''']
       a__             ={
           '''hidden_size''': '''n_embd''',
           '''max_position_embeddings''': '''n_positions''',
           '''num_attention_heads''': '''n_head''',
           '''num_hidden_layers''': '''n_layer''',
       }
  
  
  
  
  
       def __init__(      self ,			A=5_0_2_5_7 ,			A=1_0_2_4 ,			A=7_6_8 ,			A=1_2 ,			A=1_2 ,			A=None ,			A="gelu_new" ,			A=0.1 ,			A=0.1 ,			A=0.1 ,			A=1E-5 ,			A=0.02 ,			A="cls_index" ,			A=True ,			A=None ,			A=True ,			A=0.1 ,			A=True ,			A=True ,			A=5_0_2_5_6 ,			A=5_0_2_5_6 ,			A=False ,			A=False ,			**A ,			)							->      Union[str, Any]:
           _UpperCAmelCase							:						Optional[int]       							=					vocab_size
           _UpperCAmelCase							:						Union[str, Any]       							=					n_positions
           _UpperCAmelCase							:						Optional[Any]       							=					n_embd
           _UpperCAmelCase							:						Tuple       							=					n_layer
           _UpperCAmelCase							:						Any       							=					n_head
           _UpperCAmelCase							:						Union[str, Any]       							=					n_inner
           _UpperCAmelCase							:						Optional[int]       							=					activation_function
           _UpperCAmelCase							:						Optional[int]       							=					resid_pdrop
           _UpperCAmelCase							:						Dict       							=					embd_pdrop
           _UpperCAmelCase							:						List[Any]       							=					attn_pdrop
           _UpperCAmelCase							:						Tuple       							=					layer_norm_epsilon
           _UpperCAmelCase							:						Optional[int]       							=					initializer_range
           _UpperCAmelCase							:						List[str]       							=					summary_type
           _UpperCAmelCase							:						Tuple       							=					summary_use_proj
           _UpperCAmelCase							:						List[Any]       							=					summary_activation
           _UpperCAmelCase							:						Optional[int]       							=					summary_first_dropout
           _UpperCAmelCase							:						int       							=					summary_proj_to_labels
           _UpperCAmelCase							:						Union[str, Any]       							=					scale_attn_weights
           _UpperCAmelCase							:						Any       							=					use_cache
           _UpperCAmelCase							:						Tuple       							=					scale_attn_by_inverse_layer_idx
           _UpperCAmelCase							:						Optional[Any]       							=					reorder_and_upcast_attn
  
           _UpperCAmelCase							:						Union[str, Any]       							=					bos_token_id
           _UpperCAmelCase							:						Optional[int]       							=					eos_token_id
  
           super().__init__(bos_token_id=A ,			eos_token_id=A ,			**A	)
  
  
  
  class 							_UpperCAmelCase							(				a   ):
  
  
  
  
  
       '''simple docstring'''
  
  
  
       def __init__(      self ,			A ,			A = "default" ,			A = None ,			A = False ,			)							->      str:
           super().__init__(A ,			task=A ,			patching_specs=A ,			use_past=A	)
           if not getattr(self._config ,			'''pad_token_id''' ,			A	):
               # TODO: how to do that better?
               _UpperCAmelCase							:						Optional[int]       							=					0
  
  
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      Mapping[str, Mapping[int, str]]:
           _UpperCAmelCase							:						List[str]       							=					OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}	)
           if self.use_past:
               self.fill_with_past_key_values_(A ,			direction='''inputs'''	)
               _UpperCAmelCase							:						Union[str, Any]       							=					{0: '''batch''', 1: '''past_sequence + sequence'''}
           else:
               _UpperCAmelCase							:						Tuple       							=					{0: '''batch''', 1: '''sequence'''}
  
           return common_inputs
  
  
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      int:
           return self._config.n_layer
  
  
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      int:
           return self._config.n_head
  
  
  
  
  
       def 				__lowerCAmelCase			(      self ,			A ,			A = -1 ,			A = -1 ,			A = False ,			A = None ,			)							->      Mapping[str, Any]:
           _UpperCAmelCase							:						int       							=					super(A ,			self	).generate_dummy_inputs(
               A ,			batch_size=A ,			seq_length=A ,			is_pair=A ,			framework=A	)
  
           # We need to order the input in the way they appears in the forward()
           _UpperCAmelCase							:						List[Any]       							=					OrderedDict({'''input_ids''': common_inputs['''input_ids''']}	)
  
           # Need to add the past_keys
           if self.use_past:
               if not is_torch_available():
                   raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''	)
               else:
                   import torch
  
                   _UpperCAmelCase							,       _UpperCAmelCase							:						Optional[Any]       							=					common_inputs['''input_ids'''].shape
                   # Not using the same length for past_key_values
                   _UpperCAmelCase							:						Optional[Any]       							=					seqlen + 2
                   _UpperCAmelCase							:						Union[str, Any]       							=					(
                       batch,
                       self.num_attention_heads,
                       past_key_values_length,
                       self._config.hidden_size // self.num_attention_heads,
                   )
                   _UpperCAmelCase							:						List[Any]       							=					[
                       (torch.zeros(A	), torch.zeros(A	)) for _ in range(self.num_layers	)
                   ]
  
           _UpperCAmelCase							:						int       							=					common_inputs['''attention_mask''']
           if self.use_past:
               _UpperCAmelCase							:						int       							=					ordered_inputs['''attention_mask'''].dtype
               _UpperCAmelCase							:						Dict       							=					torch.cat(
                   [ordered_inputs['''attention_mask'''], torch.ones(A ,			A ,			dtype=A	)] ,			dim=1	)
  
           return ordered_inputs
  
  
  
  
  
       @property
       def 				__lowerCAmelCase			(      self	)							->      int:
           return 1_3
  
  
  