code: 
  '''simple docstring'''
  
  from __future__ import annotations
  
  import unittest
  
  from transformers import OpenAIGPTConfig, is_tf_available
  from transformers.testing_utils import require_tf, slow
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_tf_available():
  	import tensorflow as tf
  
  	from transformers.models.openai.modeling_tf_openai import (
  	    TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
  	    TFOpenAIGPTDoubleHeadsModel,
  	    TFOpenAIGPTForSequenceClassification,
  	    TFOpenAIGPTLMHeadModel,
  	    TFOpenAIGPTModel,
  	)
  
  class 			UpperCAmelCase				:
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		def __init__(    self  ,					_snake_case  ,					)				->    int:
  				_UpperCamelCase       : Any    =      parent
  				_UpperCamelCase       : Dict    =      13
  				_UpperCamelCase       : Union[str, Any]    =      7
  				_UpperCamelCase       : str    =      True
  				_UpperCamelCase       : int    =      True
  				_UpperCamelCase       : Tuple    =      True
  				_UpperCamelCase       : Optional[Any]    =      True
  				_UpperCamelCase       : Any    =      True
  				_UpperCamelCase       : Any    =      99
  				_UpperCamelCase       : Tuple    =      32
  				_UpperCamelCase       : List[Any]    =      2
  				_UpperCamelCase       : int    =      4
  				_UpperCamelCase       : Dict    =      37
  				_UpperCamelCase       : Optional[Any]    =      '''gelu'''
  				_UpperCamelCase       : str    =      0.1
  				_UpperCamelCase       : List[str]    =      0.1
  				_UpperCamelCase       : Optional[Any]    =      512
  				_UpperCamelCase       : Tuple    =      16
  				_UpperCamelCase       : List[str]    =      2
  				_UpperCamelCase       : Dict    =      0.02
  				_UpperCamelCase       : List[str]    =      3
  				_UpperCamelCase       : Optional[Any]    =      4
  				_UpperCamelCase       : int    =      None
  				_UpperCamelCase       : List[Any]    =      self.vocab_size - 1
  		def _lowercase  (    self     )				->    Any:
  				_UpperCamelCase       : Tuple    =      ids_tensor([self.batch_size, self.seq_length]  ,					self.vocab_size     )
  
  				_UpperCamelCase       : Tuple    =      None
  				if self.use_input_mask:
  						_UpperCamelCase       : Any    =      random_attention_mask([self.batch_size, self.seq_length]     )
  
  				_UpperCamelCase       : Any    =      None
  				if self.use_token_type_ids:
  						_UpperCamelCase       : List[str]    =      ids_tensor([self.batch_size, self.seq_length]  ,					self.type_vocab_size     )
  
  				_UpperCamelCase       : Any    =      None
  				if self.use_mc_token_ids:
  						_UpperCamelCase       : List[Any]    =      ids_tensor([self.batch_size, self.num_choices]  ,					self.seq_length     )
  
  				_UpperCamelCase       : List[Any]    =      None
  				_UpperCamelCase       : Union[str, Any]    =      None
  				_UpperCamelCase       : Tuple    =      None
  				if self.use_labels:
  						_UpperCamelCase       : Optional[int]    =      ids_tensor([self.batch_size]  ,					self.type_sequence_label_size     )
  						_UpperCamelCase       : List[str]    =      ids_tensor([self.batch_size, self.seq_length]  ,					self.num_labels     )
  						_UpperCamelCase       : str    =      ids_tensor([self.batch_size]  ,					self.num_choices     )
  
  				_UpperCamelCase       : int    =      OpenAIGPTConfig(
  				    vocab_size=self.vocab_size  ,					n_embd=self.hidden_size  ,					n_layer=self.num_hidden_layers  ,					n_head=self.num_attention_heads  ,					n_positions=self.max_position_embeddings  ,					pad_token_id=self.pad_token_id  ,					)
  
  				_UpperCamelCase       : Union[str, Any]    =      ids_tensor([self.num_hidden_layers, self.num_attention_heads]  ,					2     )
  
  				return (
  				    config,
  				    input_ids,
  				    input_mask,
  				    head_mask,
  				    token_type_ids,
  				    mc_token_ids,
  				    sequence_labels,
  				    token_labels,
  				    choice_labels,
  				)
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    List[str]:
  				_UpperCamelCase       : List[Any]    =      TFOpenAIGPTModel(config=_snake_case     )
  				_UpperCamelCase       : Union[str, Any]    =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
  				_UpperCamelCase       : List[str]    =      model(_snake_case     )
  
  				_UpperCamelCase       : List[str]    =      [input_ids, input_mask]
  				_UpperCamelCase       : Dict    =      model(_snake_case     )
  
  				_UpperCamelCase       : Optional[Any]    =      model(_snake_case     )
  
  				self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, self.seq_length, self.hidden_size)     )
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    Any:
  				_UpperCamelCase       : Optional[int]    =      TFOpenAIGPTLMHeadModel(config=_snake_case     )
  				_UpperCamelCase       : Tuple    =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
  				_UpperCamelCase       : Union[str, Any]    =      model(_snake_case     )
  				self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.seq_length, self.vocab_size)     )
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    Optional[int]:
  				_UpperCamelCase       : List[Any]    =      TFOpenAIGPTDoubleHeadsModel(config=_snake_case     )
  
  				_UpperCamelCase       : List[Any]    =      tf.tile(tf.expand_dims(_snake_case  ,					1     )  ,					(1, self.num_choices, 1)     )
  				_UpperCamelCase       : str    =      tf.tile(tf.expand_dims(_snake_case  ,					1     )  ,					(1, self.num_choices, 1)     )
  				_UpperCamelCase       : int    =      tf.tile(tf.expand_dims(_snake_case  ,					1     )  ,					(1, self.num_choices, 1)     )
  
  				_UpperCamelCase       : List[str]    =      {
  				    '''input_ids''': multiple_choice_inputs_ids,
  				    '''mc_token_ids''': mc_token_ids,
  				    '''attention_mask''': multiple_choice_input_mask,
  				    '''token_type_ids''': multiple_choice_token_type_ids,
  				}
  				_UpperCamelCase       : Tuple    =      model(_snake_case     )
  				self.parent.assertEqual(
  				    result.logits.shape  ,					(self.batch_size, self.num_choices, self.seq_length, self.vocab_size)     )
  				self.parent.assertEqual(result.mc_logits.shape  ,					(self.batch_size, self.num_choices)     )
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    str:
  				_UpperCamelCase       : List[str]    =      self.num_labels
  				_UpperCamelCase       : Dict    =      ids_tensor([self.batch_size]  ,					self.type_sequence_label_size     )
  				_UpperCamelCase       : str    =      {
  				    '''input_ids''': input_ids,
  				    '''attention_mask''': input_mask,
  				    '''token_type_ids''': token_type_ids,
  				    '''labels''': sequence_labels,
  				}
  				_UpperCamelCase       : Dict    =      TFOpenAIGPTForSequenceClassification(_snake_case     )
  				_UpperCamelCase       : str    =      model(_snake_case     )
  				self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.num_labels)     )
  
  
  
  
  		def _lowercase  (    self     )				->    Optional[int]:
  				_UpperCamelCase       : Tuple    =      self.prepare_config_and_inputs()
  
  				(
  				    (
  				    _UpperCamelCase
  				),							(
  				    _UpperCamelCase
  				),							(
  				    _UpperCamelCase
  				),							(
  				    _UpperCamelCase
  				),							(
  				    _UpperCamelCase
  				),							(
  				    _UpperCamelCase
  				),							(
  				    _UpperCamelCase
  				),							(
  				    _UpperCamelCase
  				),							(
  				    _UpperCamelCase
  				),							
  				)       : List[str]    =      config_and_inputs
  
  				_UpperCamelCase       : int    =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
  				return config, inputs_dict
  
  
  
  
  
  
  
  @require_tf
  class 			UpperCAmelCase				(					a_  ,		a_  ,		unittest.TestCase ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		A__  :   Union[str, Any]          =    (
  		    (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
  		    if is_tf_available()
  		    else ()
  		)
  		A__  :   Tuple          =    (
  		    (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
  		)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
  		A__  :   Tuple          =    (
  		    {
  		        'feature-extraction': TFOpenAIGPTModel,
  		        'text-classification': TFOpenAIGPTForSequenceClassification,
  		        'text-generation': TFOpenAIGPTLMHeadModel,
  		        'zero-shot': TFOpenAIGPTForSequenceClassification,
  		    }
  		    if is_tf_available()
  		    else {}
  		)
  		A__  :   Optional[Any]          =    False
  		A__  :   Optional[Any]          =    False
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case     )				->    Optional[int]:
  				if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
  						# Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
  						# `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
  						# tiny config could not be created.
  						return True
  
  				return False
  		def _lowercase  (    self     )				->    Optional[Any]:
  				_UpperCamelCase       : Dict    =      TFOpenAIGPTModelTester(self     )
  				_UpperCamelCase       : Optional[int]    =      ConfigTester(self  ,					config_class=_snake_case  ,					n_embd=37     )
  		def _lowercase  (    self     )				->    int:
  				self.config_tester.run_common_tests()
  		def _lowercase  (    self     )				->    List[str]:
  				_UpperCamelCase       : int    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_openai_gpt_model(*_snake_case     )
  		def _lowercase  (    self     )				->    List[Any]:
  				_UpperCamelCase       : Optional[int]    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_openai_gpt_lm_head(*_snake_case     )
  		def _lowercase  (    self     )				->    int:
  				_UpperCamelCase       : Dict    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_openai_gpt_double_head(*_snake_case     )
  		def _lowercase  (    self     )				->    Optional[int]:
  				_UpperCamelCase       : Optional[int]    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*_snake_case     )
  
  
  
  
  		@slow
  		def _lowercase  (    self     )				->    int:
  				for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  						_UpperCamelCase       : int    =      TFOpenAIGPTModel.from_pretrained(_snake_case     )
  						self.assertIsNotNone(_snake_case     )
  
  
  
  
  
  
  
  @require_tf
  class 			UpperCAmelCase				(					unittest.TestCase ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		@slow
  		def _lowercase  (    self     )				->    List[Any]:
  				_UpperCamelCase       : Union[str, Any]    =      TFOpenAIGPTLMHeadModel.from_pretrained('''openai-gpt'''     )
  				_UpperCamelCase       : Optional[Any]    =      tf.convert_to_tensor([[481, 4735, 544]]  ,					dtype=tf.intaa     )  # the president is
  				_UpperCamelCase       : Union[str, Any]    =      [
  				    481,
  				    4735,
  				    544,
  				    246,
  				    963,
  				    870,
  				    762,
  				    239,
  				    244,
  				    40477,
  				    244,
  				    249,
  				    719,
  				    881,
  				    487,
  				    544,
  				    240,
  				    244,
  				    603,
  				    481,
  				]  # the president is a very good man. " \n " i\'m sure he is, " said the
  
  				_UpperCamelCase       : Union[str, Any]    =      model.generate(_snake_case  ,					do_sample=_snake_case     )
  				self.assertListEqual(output_ids[0].numpy().tolist()  ,					_snake_case     )
  
  
  
  
  
  
style_context: 
  '''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
  
  
  _UpperCAmelCase   :      Optional[int] 						=  logging.get_logger(__name__)
  
  _UpperCAmelCase   :      Any 						=  {
      """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				(					a_ ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		A__  :   List[str]          =    'bigbird_pegasus'
  		A__  :   Union[str, Any]          =    ['past_key_values']
  		A__  :   Optional[int]          =    {
  		    'num_attention_heads': 'encoder_attention_heads',
  		    'hidden_size': 'd_model',
  		    'attention_probs_dropout_prob': 'attention_dropout',
  		}
  		def __init__(    self  ,					_snake_case=96103  ,					_snake_case=4096  ,					_snake_case=16  ,					_snake_case=4096  ,					_snake_case=16  ,					_snake_case=16  ,					_snake_case=4096  ,					_snake_case=16  ,					_snake_case=0.0  ,					_snake_case=0.0  ,					_snake_case=True  ,					_snake_case=True  ,					_snake_case="gelu_new"  ,					_snake_case=1024  ,					_snake_case=0.1  ,					_snake_case=0.0  ,					_snake_case=0.0  ,					_snake_case=0.02  ,					_snake_case=2  ,					_snake_case=0.0  ,					_snake_case=True  ,					_snake_case=0  ,					_snake_case=2  ,					_snake_case=1  ,					_snake_case="block_sparse"  ,					_snake_case=64  ,					_snake_case=3  ,					_snake_case=False  ,					**_snake_case  ,					)				->    Optional[Any]:
  				_UpperCamelCase       : str    =      vocab_size
  				_UpperCamelCase       : Tuple    =      max_position_embeddings
  				_UpperCamelCase       : int    =      d_model
  				_UpperCamelCase       : List[str]    =      encoder_ffn_dim
  				_UpperCamelCase       : str    =      encoder_layers
  				_UpperCamelCase       : Dict    =      encoder_attention_heads
  				_UpperCamelCase       : str    =      decoder_ffn_dim
  				_UpperCamelCase       : List[str]    =      decoder_layers
  				_UpperCamelCase       : Any    =      decoder_attention_heads
  				_UpperCamelCase       : str    =      dropout
  				_UpperCamelCase       : int    =      attention_dropout
  				_UpperCamelCase       : Optional[int]    =      activation_dropout
  				_UpperCamelCase       : Optional[Any]    =      activation_function
  				_UpperCamelCase       : Tuple    =      init_std
  				_UpperCamelCase       : Any    =      encoder_layerdrop
  				_UpperCamelCase       : List[str]    =      decoder_layerdrop
  				_UpperCamelCase       : Any    =      classifier_dropout
  				_UpperCamelCase       : int    =      use_cache
  				_UpperCamelCase       : Union[str, Any]    =      encoder_layers
  				_UpperCamelCase       : str    =      scale_embedding  # scale factor will be sqrt(d_model) if True
  
  				# extra config
  				_UpperCamelCase       : str    =      attention_type
  				_UpperCamelCase       : Tuple    =      block_size
  				_UpperCamelCase       : Optional[Any]    =      num_random_blocks
  				_UpperCamelCase       : Dict    =      use_bias
  
  				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  ,					**_snake_case  ,					)
  
  
  
  
  
  
  
  class 			UpperCAmelCase				(					a_ ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		@property
  		def _lowercase  (    self     )				->    Mapping[str, Mapping[int, str]]:
  				if self.task in ["default", "seq2seq-lm"]:
  						_UpperCamelCase       : str    =      OrderedDict(
  						    [
  						        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
  						        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
  						    ]     )
  
  						if self.use_past:
  								_UpperCamelCase       : List[Any]    =      {0: '''batch'''}
  								_UpperCamelCase       : Tuple    =      {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
  						else:
  								_UpperCamelCase       : Union[str, Any]    =      {0: '''batch''', 1: '''decoder_sequence'''}
  								_UpperCamelCase       : Union[str, Any]    =      {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.
  						_UpperCamelCase       : Optional[int]    =      OrderedDict(
  						    [
  						        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
  						        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
  						    ]     )
  						if self.use_past:
  								_UpperCamelCase,							_UpperCamelCase       : List[str]    =      self.num_layers
  								for i in range(_snake_case     ):
  										_UpperCamelCase       : Optional[int]    =      {0: '''batch''', 2: '''past_sequence + sequence'''}
  										_UpperCamelCase       : Dict    =      {0: '''batch''', 2: '''past_sequence + sequence'''}
  				else:
  						_UpperCamelCase       : Optional[int]    =      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 _lowercase  (    self     )				->    Mapping[str, Mapping[int, str]]:
  				if self.task in ["default", "seq2seq-lm"]:
  						_UpperCamelCase       : int    =      super().outputs
  				else:
  						_UpperCamelCase       : Optional[int]    =      super(_snake_case  ,					self     ).outputs
  						if self.use_past:
  								_UpperCamelCase,							_UpperCamelCase       : Tuple    =      self.num_layers
  								for i in range(_snake_case     ):
  										_UpperCamelCase       : int    =      {0: '''batch''', 2: '''past_sequence + sequence'''}
  										_UpperCamelCase       : Optional[int]    =      {0: '''batch''', 2: '''past_sequence + sequence'''}
  				return common_outputs
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case = -1  ,					_snake_case = -1  ,					_snake_case = False  ,					_snake_case = None  ,					)				->    Mapping[str, Any]:
  				_UpperCamelCase       : List[str]    =      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
  				    _snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case     )
  
  				# Generate decoder inputs
  				_UpperCamelCase       : Optional[int]    =      seq_length if not self.use_past else 1
  				_UpperCamelCase       : Optional[int]    =      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
  				    _snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case     )
  				_UpperCamelCase       : Optional[int]    =      {F'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
  				_UpperCamelCase       : 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
  						_UpperCamelCase,							_UpperCamelCase       : Dict    =      common_inputs['''input_ids'''].shape
  						_UpperCamelCase       : Dict    =      common_inputs['''decoder_input_ids'''].shape[1]
  						_UpperCamelCase,							_UpperCamelCase       : List[Any]    =      self.num_attention_heads
  						_UpperCamelCase       : List[Any]    =      (
  						    batch,
  						    num_encoder_attention_heads,
  						    encoder_seq_length,
  						    self._config.hidden_size // num_encoder_attention_heads,
  						)
  						_UpperCamelCase       : int    =      decoder_seq_length + 3
  						_UpperCamelCase       : Union[str, Any]    =      (
  						    batch,
  						    num_decoder_attention_heads,
  						    decoder_past_length,
  						    self._config.hidden_size // num_decoder_attention_heads,
  						)
  
  						_UpperCamelCase       : Any    =      torch.cat(
  						    [common_inputs['''decoder_attention_mask'''], torch.ones(_snake_case  ,					_snake_case     )]  ,					dim=1     )
  
  						_UpperCamelCase       : Any    =      []
  						# If the number of encoder and decoder layers are present in the model configuration, both are considered
  						_UpperCamelCase,							_UpperCamelCase       : int    =      self.num_layers
  						_UpperCamelCase       : Union[str, Any]    =      min(_snake_case  ,					_snake_case     )
  						_UpperCamelCase       : Union[str, Any]    =      max(_snake_case  ,					_snake_case     ) - min_num_layers
  						_UpperCamelCase       : Optional[int]    =      '''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.
  						_UpperCamelCase       : 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 _lowercase  (    self  ,					_snake_case  ,					_snake_case = -1  ,					_snake_case = -1  ,					_snake_case = False  ,					_snake_case = None  ,					)				->    Mapping[str, Any]:
  				_UpperCamelCase       : Dict    =      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
  						_UpperCamelCase,							_UpperCamelCase       : Union[str, Any]    =      common_inputs['''input_ids'''].shape
  						# Not using the same length for past_key_values
  						_UpperCamelCase       : str    =      seqlen + 2
  						_UpperCamelCase,							_UpperCamelCase       : str    =      self.num_layers
  						_UpperCamelCase,							_UpperCamelCase       : str    =      self.num_attention_heads
  						_UpperCamelCase       : List[str]    =      (
  						    batch,
  						    num_encoder_attention_heads,
  						    past_key_values_length,
  						    self._config.hidden_size // num_encoder_attention_heads,
  						)
  
  						_UpperCamelCase       : Optional[int]    =      common_inputs['''attention_mask'''].dtype
  						_UpperCamelCase       : Union[str, Any]    =      torch.cat(
  						    [common_inputs['''attention_mask'''], torch.ones(_snake_case  ,					_snake_case  ,					dtype=_snake_case     )]  ,					dim=1     )
  						_UpperCamelCase       : int    =      [
  						    (torch.zeros(_snake_case     ), torch.zeros(_snake_case     )) for _ in range(_snake_case     )
  						]
  				return common_inputs
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case = -1  ,					_snake_case = -1  ,					_snake_case = False  ,					_snake_case = 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
  				_UpperCamelCase       : Union[str, 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
  				_UpperCamelCase       : List[Any]    =      tokenizer.num_special_tokens_to_add(_snake_case     )
  				_UpperCamelCase       : List[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
  				_UpperCamelCase       : Optional[Any]    =      [''' '''.join([tokenizer.unk_token]     ) * seq_length] * batch_size
  				_UpperCamelCase       : Any    =      dict(tokenizer(_snake_case  ,					return_tensors=_snake_case     )     )
  				return common_inputs
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case = -1  ,					_snake_case = -1  ,					_snake_case = False  ,					_snake_case = None  ,					)				->    Mapping[str, Any]:
  				if self.task in ["default", "seq2seq-lm"]:
  						_UpperCamelCase       : 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":
  						_UpperCamelCase       : List[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:
  						_UpperCamelCase       : 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 _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case     )				->    Tuple:
  				if self.task in ["default", "seq2seq-lm"]:
  						_UpperCamelCase       : List[Any]    =      super()._flatten_past_key_values_(_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case     )
  				else:
  						_UpperCamelCase       : int    =      super(_snake_case  ,					self     )._flatten_past_key_values_(
  						    _snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case     )
  
  
  
  
  
  