code: 
  '''simple docstring'''
  
  import argparse
  import json
  from pathlib import Path
  
  import requests
  import torch
  from huggingface_hub import hf_hub_download
  from PIL import Image
  
  from transformers import ConvNextConfig, ConvNextForImageClassification, ConvNextImageProcessor
  from transformers.utils import logging
  
  
  logging.set_verbosity_info()
  _UpperCAmelCase   :      List[str] 						=  logging.get_logger(__name__)
  
  
  
  
  
  
  
  def 						snake_case__	(      UpperCamelCase	) ->      List[Any]:
    _UpperCamelCase       : Any    =      ConvNextConfig()
  
    if "tiny" in checkpoint_url:
      _UpperCamelCase       : Any    =      [3, 3, 9, 3]
      _UpperCamelCase       : List[Any]    =      [96, 1_92, 3_84, 7_68]
    if "small" in checkpoint_url:
      _UpperCamelCase       : List[Any]    =      [3, 3, 27, 3]
      _UpperCamelCase       : int    =      [96, 1_92, 3_84, 7_68]
    if "base" in checkpoint_url:
      _UpperCamelCase       : int    =      [3, 3, 27, 3]
      _UpperCamelCase       : Tuple    =      [1_28, 2_56, 5_12, 10_24]
    if "large" in checkpoint_url:
      _UpperCamelCase       : Tuple    =      [3, 3, 27, 3]
      _UpperCamelCase       : str    =      [1_92, 3_84, 7_68, 15_36]
    if "xlarge" in checkpoint_url:
      _UpperCamelCase       : str    =      [3, 3, 27, 3]
      _UpperCamelCase       : Tuple    =      [2_56, 5_12, 10_24, 20_48]
  
    if "1k" in checkpoint_url:
      _UpperCamelCase       : Union[str, Any]    =      10_00
      _UpperCamelCase       : List[Any]    =      '''imagenet-1k-id2label.json'''
      _UpperCamelCase       : Union[str, Any]    =      (1, 10_00)
    else:
      _UpperCamelCase       : Optional[Any]    =      2_18_41
      _UpperCamelCase       : str    =      '''imagenet-22k-id2label.json'''
      _UpperCamelCase       : Optional[int]    =      (1, 2_18_41)
  
    _UpperCamelCase       : Any    =      '''huggingface/label-files'''
    _UpperCamelCase       : Any    =      num_labels
    _UpperCamelCase       : Tuple    =      json.load(open(hf_hub_download(UpperCamelCase			,UpperCamelCase			,repo_type='''dataset'''	)			,'''r'''	)	)
    _UpperCamelCase       : int    =      {int(UpperCamelCase	): v for k, v in idalabel.items()}
    if "1k" not in checkpoint_url:
      # this dataset contains 21843 labels but the model only has 21841
      # we delete the classes as mentioned in https://github.com/google-research/big_transfer/issues/18
      del idalabel[92_05]
      del idalabel[1_50_27]
    _UpperCamelCase       : str    =      idalabel
    _UpperCamelCase       : List[str]    =      {v: k for k, v in idalabel.items()}
    _UpperCamelCase       : Tuple    =      hidden_sizes
    _UpperCamelCase       : List[str]    =      depths
  
    return config, expected_shape
  
  
  
  
  
  
  
  def 						snake_case__	(      UpperCamelCase	) ->      Optional[Any]:
    if "downsample_layers.0.0" in name:
      _UpperCamelCase       : Any    =      name.replace('''downsample_layers.0.0'''			,'''embeddings.patch_embeddings'''	)
    if "downsample_layers.0.1" in name:
      _UpperCamelCase       : Any    =      name.replace('''downsample_layers.0.1'''			,'''embeddings.norm'''	)  # we rename to layernorm later on
    if "downsample_layers.1.0" in name:
      _UpperCamelCase       : int    =      name.replace('''downsample_layers.1.0'''			,'''stages.1.downsampling_layer.0'''	)
    if "downsample_layers.1.1" in name:
      _UpperCamelCase       : Optional[int]    =      name.replace('''downsample_layers.1.1'''			,'''stages.1.downsampling_layer.1'''	)
    if "downsample_layers.2.0" in name:
      _UpperCamelCase       : Optional[int]    =      name.replace('''downsample_layers.2.0'''			,'''stages.2.downsampling_layer.0'''	)
    if "downsample_layers.2.1" in name:
      _UpperCamelCase       : int    =      name.replace('''downsample_layers.2.1'''			,'''stages.2.downsampling_layer.1'''	)
    if "downsample_layers.3.0" in name:
      _UpperCamelCase       : Tuple    =      name.replace('''downsample_layers.3.0'''			,'''stages.3.downsampling_layer.0'''	)
    if "downsample_layers.3.1" in name:
      _UpperCamelCase       : Any    =      name.replace('''downsample_layers.3.1'''			,'''stages.3.downsampling_layer.1'''	)
    if "stages" in name and "downsampling_layer" not in name:
      # stages.0.0. for instance should be renamed to stages.0.layers.0.
      _UpperCamelCase       : Dict    =      name[: len('''stages.0'''	)] + '''.layers''' + name[len('''stages.0'''	) :]
    if "stages" in name:
      _UpperCamelCase       : List[str]    =      name.replace('''stages'''			,'''encoder.stages'''	)
    if "norm" in name:
      _UpperCamelCase       : Union[str, Any]    =      name.replace('''norm'''			,'''layernorm'''	)
    if "gamma" in name:
      _UpperCamelCase       : Any    =      name.replace('''gamma'''			,'''layer_scale_parameter'''	)
    if "head" in name:
      _UpperCamelCase       : Optional[int]    =      name.replace('''head'''			,'''classifier'''	)
  
    return name
  
  
  
  
  
  
  
  def 						snake_case__	(      ) ->      Any:
    _UpperCamelCase       : Union[str, Any]    =      '''http://images.cocodataset.org/val2017/000000039769.jpg'''
    _UpperCamelCase       : Union[str, Any]    =      Image.open(requests.get(UpperCamelCase			,stream=UpperCamelCase	).raw	)
    return im
  
  
  
  
  
  
  
  @torch.no_grad()
  def 						snake_case__	(      UpperCamelCase			,UpperCamelCase	) ->      List[Any]:
    _UpperCamelCase       : int    =      get_convnext_config(UpperCamelCase	)
    # load original state_dict from URL
    _UpperCamelCase       : Any    =      torch.hub.load_state_dict_from_url(UpperCamelCase	)['''model''']
    # rename keys
    for key in state_dict.copy().keys():
      _UpperCamelCase       : List[str]    =      state_dict.pop(UpperCamelCase	)
      _UpperCamelCase       : Tuple    =      val
    # add prefix to all keys expect classifier head
    for key in state_dict.copy().keys():
      _UpperCamelCase       : List[Any]    =      state_dict.pop(UpperCamelCase	)
      if not key.startswith('''classifier'''	):
        _UpperCamelCase       : Dict    =      '''convnext.''' + key
      _UpperCamelCase       : Optional[int]    =      val
  
    # load HuggingFace model
    _UpperCamelCase       : Dict    =      ConvNextForImageClassification(UpperCamelCase	)
    model.load_state_dict(UpperCamelCase	)
    model.eval()
  
    # Check outputs on an image, prepared by ConvNextImageProcessor
    _UpperCamelCase       : Optional[int]    =      2_24 if '''224''' in checkpoint_url else 3_84
    _UpperCamelCase       : int    =      ConvNextImageProcessor(size=UpperCamelCase	)
    _UpperCamelCase       : Union[str, Any]    =      image_processor(images=prepare_img()			,return_tensors='''pt'''	).pixel_values
  
    _UpperCamelCase       : str    =      model(UpperCamelCase	).logits
  
    # note: the logits below were obtained without center cropping
    if checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_tiny_1k_224_ema.pth":
      _UpperCamelCase       : Dict    =      torch.tensor([-0.1210, -0.6605, 0.1918]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_small_1k_224_ema.pth":
      _UpperCamelCase       : Union[str, Any]    =      torch.tensor([-0.4473, -0.1847, -0.6365]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_1k_224_ema.pth":
      _UpperCamelCase       : List[Any]    =      torch.tensor([0.4525, 0.7539, 0.0308]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_1k_384.pth":
      _UpperCamelCase       : Optional[int]    =      torch.tensor([0.3561, 0.6350, -0.0384]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_1k_224_ema.pth":
      _UpperCamelCase       : int    =      torch.tensor([0.4174, -0.0989, 0.1489]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_1k_384.pth":
      _UpperCamelCase       : List[Any]    =      torch.tensor([0.2513, -0.1349, -0.1613]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_22k_224.pth":
      _UpperCamelCase       : List[Any]    =      torch.tensor([1.2980, 0.3631, -0.1198]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_22k_224.pth":
      _UpperCamelCase       : str    =      torch.tensor([1.2963, 0.1227, 0.1723]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_224.pth":
      _UpperCamelCase       : Union[str, Any]    =      torch.tensor([1.7956, 0.8390, 0.2820]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_22k_1k_224.pth":
      _UpperCamelCase       : Tuple    =      torch.tensor([-0.2822, -0.0502, -0.0878]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_22k_1k_384.pth":
      _UpperCamelCase       : Tuple    =      torch.tensor([-0.5672, -0.0730, -0.4348]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_22k_1k_224.pth":
      _UpperCamelCase       : Union[str, Any]    =      torch.tensor([0.2681, 0.2365, 0.6246]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_22k_1k_384.pth":
      _UpperCamelCase       : Optional[int]    =      torch.tensor([-0.2642, 0.3931, 0.5116]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_1k_224_ema.pth":
      _UpperCamelCase       : Any    =      torch.tensor([-0.6677, -0.1873, -0.8379]	)
    elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_1k_384_ema.pth":
      _UpperCamelCase       : str    =      torch.tensor([-0.7749, -0.2967, -0.6444]	)
    else:
      raise ValueError(f'''Unknown URL: {checkpoint_url}'''	)
  
    assert torch.allclose(logits[0, :3]			,UpperCamelCase			,atol=1e-3	)
    assert logits.shape == expected_shape
  
    Path(UpperCamelCase	).mkdir(exist_ok=UpperCamelCase	)
    print(f'''Saving model to {pytorch_dump_folder_path}'''	)
    model.save_pretrained(UpperCamelCase	)
    print(f'''Saving image processor to {pytorch_dump_folder_path}'''	)
    image_processor.save_pretrained(UpperCamelCase	)
  
    print('''Pushing model to the hub...'''	)
    _UpperCamelCase       : Any    =      '''convnext'''
    if "tiny" in checkpoint_url:
      model_name += "-tiny"
    elif "small" in checkpoint_url:
      model_name += "-small"
    elif "base" in checkpoint_url:
      model_name += "-base"
    elif "xlarge" in checkpoint_url:
      model_name += "-xlarge"
    elif "large" in checkpoint_url:
      model_name += "-large"
    if "224" in checkpoint_url:
      model_name += "-224"
    elif "384" in checkpoint_url:
      model_name += "-384"
    if "22k" in checkpoint_url and "1k" not in checkpoint_url:
      model_name += "-22k"
    if "22k" in checkpoint_url and "1k" in checkpoint_url:
      model_name += "-22k-1k"
  
    model.push_to_hub(
        repo_path_or_name=Path(UpperCamelCase			,UpperCamelCase	)			,organization='''nielsr'''			,commit_message='''Add model'''			,)
  
  
  if __name__ == "__main__":
   _UpperCAmelCase   :      Optional[int] 						=  argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       """--checkpoint_url""",
       default="""https://dl.fbaipublicfiles.com/convnext/convnext_tiny_1k_224_ema.pth""",
       type=str,
       help="""URL of the original ConvNeXT checkpoint you'd like to convert.""",
   )
   parser.add_argument(
       """--pytorch_dump_folder_path""",
       default=None,
       type=str,
       required=True,
       help="""Path to the output PyTorch model directory.""",
   )
  
   _UpperCAmelCase   :      List[str] 						=  parser.parse_args()
   convert_convnext_checkpoint(args.checkpoint_url, args.pytorch_dump_folder_path)
  
  
  
  
  
  
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     )
  
  
  
  
  
  