code: 
  
  
  
  
  
  
  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
  
  
  __A  							=  logging.get_logger(__name__)
  
  __A  							=  {
      "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 							_A (    __UpperCAmelCase							):
      """simple docstring"""
  
      lowerCamelCase  :       Optional[int]   =   'bigbird_pegasus'
      lowerCamelCase  :       Dict   =   ['past_key_values']
      lowerCamelCase  :       int   =   {
          'num_attention_heads': 'encoder_attention_heads',
          'hidden_size': 'd_model',
          'attention_probs_dropout_prob': 'attention_dropout',
      }
  
  
  
      def __init__(							self			:    Optional[Any]   ,    __SCREAMING_SNAKE_CASE			:    Any=96103   ,    __SCREAMING_SNAKE_CASE			:    Dict=4096   ,    __SCREAMING_SNAKE_CASE			:    Any=16   ,    __SCREAMING_SNAKE_CASE			:    List[Any]=4096   ,    __SCREAMING_SNAKE_CASE			:    int=16   ,    __SCREAMING_SNAKE_CASE			:    Tuple=16   ,    __SCREAMING_SNAKE_CASE			:    Tuple=4096   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]=16   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]=0.0   ,    __SCREAMING_SNAKE_CASE			:    int=0.0   ,    __SCREAMING_SNAKE_CASE			:    List[str]=True   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]=True   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]="gelu_new"   ,    __SCREAMING_SNAKE_CASE			:    Dict=1024   ,    __SCREAMING_SNAKE_CASE			:    Any=0.1   ,    __SCREAMING_SNAKE_CASE			:    List[str]=0.0   ,    __SCREAMING_SNAKE_CASE			:    List[str]=0.0   ,    __SCREAMING_SNAKE_CASE			:    Tuple=0.02   ,    __SCREAMING_SNAKE_CASE			:    Dict=2   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]=0.0   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]=True   ,    __SCREAMING_SNAKE_CASE			:    Tuple=0   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]=2   ,    __SCREAMING_SNAKE_CASE			:    List[str]=1   ,    __SCREAMING_SNAKE_CASE			:    List[str]="block_sparse"   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]=64   ,    __SCREAMING_SNAKE_CASE			:    List[str]=3   ,    __SCREAMING_SNAKE_CASE			:    List[Any]=False   ,    **__SCREAMING_SNAKE_CASE			:    int   ,    )			->       Tuple:
             __UpperCAmelCase    							=vocab_size
             __UpperCAmelCase    							=max_position_embeddings
             __UpperCAmelCase    							=d_model
             __UpperCAmelCase    							=encoder_ffn_dim
             __UpperCAmelCase    							=encoder_layers
             __UpperCAmelCase    							=encoder_attention_heads
             __UpperCAmelCase    							=decoder_ffn_dim
             __UpperCAmelCase    							=decoder_layers
             __UpperCAmelCase    							=decoder_attention_heads
             __UpperCAmelCase    							=dropout
             __UpperCAmelCase    							=attention_dropout
             __UpperCAmelCase    							=activation_dropout
             __UpperCAmelCase    							=activation_function
             __UpperCAmelCase    							=init_std
             __UpperCAmelCase    							=encoder_layerdrop
             __UpperCAmelCase    							=decoder_layerdrop
             __UpperCAmelCase    							=classifier_dropout
             __UpperCAmelCase    							=use_cache
             __UpperCAmelCase    							=encoder_layers
             __UpperCAmelCase    							=scale_embedding  # scale factor will be sqrt(d_model) if True
  
             # extra config
             __UpperCAmelCase    							=attention_type
             __UpperCAmelCase    							=block_size
             __UpperCAmelCase    							=num_random_blocks
             __UpperCAmelCase    							=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 							_A (    __UpperCAmelCase							):
      """simple docstring"""
  
      @property
      def _a       (							self			:    str			)			->       Mapping[str, Mapping[int, str]]:
  
             if self.task in ["default", "seq2seq-lm"]:
                    __UpperCAmelCase    							=OrderedDict(
                        [
                            ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                            ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                        ]			)
  
                    if self.use_past:
                           __UpperCAmelCase    							={0: '''batch'''}
                           __UpperCAmelCase    							={0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
                    else:
                           __UpperCAmelCase    							={0: '''batch''', 1: '''decoder_sequence'''}
                           __UpperCAmelCase    							={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    							=OrderedDict(
                        [
                            ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                            ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                        ]			)
                    if self.use_past:
                           __UpperCAmelCase    							=self.num_layers
                           for i in range(lowercase_			):
                                  __UpperCAmelCase    							={0: '''batch''', 2: '''past_sequence + sequence'''}
                                  __UpperCAmelCase    							={0: '''batch''', 2: '''past_sequence + sequence'''}
             else:
                    __UpperCAmelCase    							=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 _a       (							self			:    Dict			)			->       Mapping[str, Mapping[int, str]]:
  
             if self.task in ["default", "seq2seq-lm"]:
                    __UpperCAmelCase    							=super().outputs
             else:
                    __UpperCAmelCase    							=super(lowercase_   ,    self			).outputs
                    if self.use_past:
                           __UpperCAmelCase    							=self.num_layers
                           for i in range(lowercase_			):
                                  __UpperCAmelCase    							={0: '''batch''', 2: '''past_sequence + sequence'''}
                                  __UpperCAmelCase    							={0: '''batch''', 2: '''past_sequence + sequence'''}
             return common_outputs
  
  
  
      def _a       (							self			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any] = -1   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any] = -1   ,    __SCREAMING_SNAKE_CASE			:    Tuple = False   ,    __SCREAMING_SNAKE_CASE			:    Optional[int] = None   ,    )			->       Mapping[str, Any]:
             __UpperCAmelCase    							=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 lowercase_   ,    lowercase_   ,    lowercase_   ,    lowercase_   ,    lowercase_			)
  
             # Generate decoder inputs
             __UpperCAmelCase    							=seq_length if not self.use_past else 1
             __UpperCAmelCase    							=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                 lowercase_   ,    lowercase_   ,    lowercase_   ,    lowercase_   ,    lowercase_			)
             __UpperCAmelCase    							={f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
             __UpperCAmelCase    							=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    							=common_inputs['''input_ids'''].shape
                    __UpperCAmelCase    							=common_inputs['''decoder_input_ids'''].shape[1]
                    __UpperCAmelCase    							=self.num_attention_heads
                    __UpperCAmelCase    							=(
                        batch,
                        num_encoder_attention_heads,
                        encoder_seq_length,
                        self._config.hidden_size // num_encoder_attention_heads,
                    )
                    __UpperCAmelCase    							=decoder_seq_length + 3
                    __UpperCAmelCase    							=(
                        batch,
                        num_decoder_attention_heads,
                        decoder_past_length,
                        self._config.hidden_size // num_decoder_attention_heads,
                    )
  
                    __UpperCAmelCase    							=torch.cat(
                        [common_inputs["""decoder_attention_mask"""], torch.ones(lowercase_   ,    lowercase_			)]   ,    dim=1			)
  
                    __UpperCAmelCase    							=[]
                    # If the number of encoder and decoder layers are present in the model configuration, both are considered
                    __UpperCAmelCase    							=self.num_layers
                    __UpperCAmelCase    							=min(lowercase_   ,    lowercase_			)
                    __UpperCAmelCase    							=max(lowercase_   ,    lowercase_			) - min_num_layers
                    __UpperCAmelCase    							='''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    							=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 _a       (							self			:    str   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    List[Any] = -1   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any] = -1   ,    __SCREAMING_SNAKE_CASE			:    List[Any] = False   ,    __SCREAMING_SNAKE_CASE			:    List[Any] = None   ,    )			->       Mapping[str, Any]:
             __UpperCAmelCase    							=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    							=common_inputs['''input_ids'''].shape
                    # Not using the same length for past_key_values
                    __UpperCAmelCase    							=seqlen + 2
                    __UpperCAmelCase    							=self.num_layers
                    __UpperCAmelCase    							=self.num_attention_heads
                    __UpperCAmelCase    							=(
                        batch,
                        num_encoder_attention_heads,
                        past_key_values_length,
                        self._config.hidden_size // num_encoder_attention_heads,
                    )
  
                    __UpperCAmelCase    							=common_inputs['''attention_mask'''].dtype
                    __UpperCAmelCase    							=torch.cat(
                        [common_inputs["""attention_mask"""], torch.ones(lowercase_   ,    lowercase_   ,    dtype=lowercase_			)]   ,    dim=1			)
                    __UpperCAmelCase    							=[
                        (torch.zeros(lowercase_			), torch.zeros(lowercase_			)) for _ in range(lowercase_			)
                    ]
             return common_inputs
  
  
  
      def _a       (							self			:    Any   ,    __SCREAMING_SNAKE_CASE			:    Dict   ,    __SCREAMING_SNAKE_CASE			:    Optional[int] = -1   ,    __SCREAMING_SNAKE_CASE			:    str = -1   ,    __SCREAMING_SNAKE_CASE			:    List[str] = False   ,    __SCREAMING_SNAKE_CASE			:    List[str] = None   ,    )			->       Mapping[str, Any]:
             __UpperCAmelCase    							=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    							=tokenizer.num_special_tokens_to_add(lowercase_			)
             __UpperCAmelCase    							=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    							=[''' '''.join([tokenizer.unk_token]			) * seq_length] * batch_size
             __UpperCAmelCase    							=dict(tokenizer(lowercase_   ,    return_tensors=lowercase_			)			)
             return common_inputs
  
  
  
      def _a       (							self			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    Dict = -1   ,    __SCREAMING_SNAKE_CASE			:    Optional[int] = -1   ,    __SCREAMING_SNAKE_CASE			:    Any = False   ,    __SCREAMING_SNAKE_CASE			:    List[str] = None   ,    )			->       Mapping[str, Any]:
  
             if self.task in ["default", "seq2seq-lm"]:
                    __UpperCAmelCase    							=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    							=self._generate_dummy_inputs_for_causal_lm(
                        lowercase_   ,    batch_size=lowercase_   ,    seq_length=lowercase_   ,    is_pair=lowercase_   ,    framework=lowercase_			)
             else:
                    __UpperCAmelCase    							=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 _a       (							self			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]   ,    __SCREAMING_SNAKE_CASE			:    int   ,    __SCREAMING_SNAKE_CASE			:    str   ,    __SCREAMING_SNAKE_CASE			:    Dict			)			->       Union[str, Any]:
  
             if self.task in ["default", "seq2seq-lm"]:
                    __UpperCAmelCase    							=super()._flatten_past_key_values_(lowercase_   ,    lowercase_   ,    lowercase_   ,    lowercase_			)
             else:
                    __UpperCAmelCase    							=super(lowercase_   ,    self			)._flatten_past_key_values_(
                        lowercase_   ,    lowercase_   ,    lowercase_   ,    lowercase_			)
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  from __future__ import annotations
  
  __A  							=  [2, 1, 4, 5, 6, 0, 8, 9, 1, 2, 0, 6, 4, 2, 0, 6, 5, 3, 2, 7]
  
  
  
  class 							_A :
      """simple docstring"""
  
      def __init__(							self			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    int			)			->       None:
             __UpperCAmelCase    							=-1
             __UpperCAmelCase    							=-1
             __UpperCAmelCase    							=[-1] * length
             __UpperCAmelCase    							=None
             __UpperCAmelCase    							=None
  
  
  
      def __repr__(							self			:    Optional[int]			)			->       str:
             return f'''Node(min_value={self.minn} max_value={self.maxx})'''
  
  
  
  
  
  
  
  def 			lowercase__  (				A_:	list[int]		)  ->							Node | None:
  
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
         __UpperCAmelCase    							=Node(len(A_		)		)
         __UpperCAmelCase							,   __UpperCAmelCase    							=min(A_		), max(A_		)
         # Leaf node case where the node contains only one unique value
         if root.minn == root.maxx:
                return root
         __UpperCAmelCase    							=(root.minn + root.maxx) // 2
  
         __UpperCAmelCase    							=[]
         __UpperCAmelCase    							=[]
  
         for index, num in enumerate(A_		):
                if num <= pivot:
                       left_arr.append(A_		)
                else:
                       right_arr.append(A_		)
                __UpperCAmelCase    							=len(A_		)
         __UpperCAmelCase    							=build_tree(A_		)
         __UpperCAmelCase    							=build_tree(A_		)
         return root
  
  
  
  
  
  
  
  def 			lowercase__  (				A_:	Node | None     ,			A_:	int     ,			A_:	int		)  ->							int:
  
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
         if index < 0 or node is None:
                return 0
         # Leaf node cases
         if node.minn == node.maxx:
                return index + 1 if node.minn == num else 0
         __UpperCAmelCase    							=(node.minn + node.maxx) // 2
         if num <= pivot:
                # go the left subtree and map index to the left subtree
                return rank_till_index(node.left     ,			A_     ,			node.map_left[index] - 1		)
         else:
                # go to the right subtree and map index to the right subtree
                return rank_till_index(node.right     ,			A_     ,			index - node.map_left[index]		)
  
  
  
  
  
  
  
  def 			lowercase__  (				A_:	Node | None     ,			A_:	int     ,			A_:	int     ,			A_:	int		)  ->							int:
  
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
         if start > end:
                return 0
         __UpperCAmelCase    							=rank_till_index(A_     ,			A_     ,			A_		)
         __UpperCAmelCase    							=rank_till_index(A_     ,			A_     ,			start - 1		)
         return rank_till_end - rank_before_start
  
  
  
  
  
  
  
  def 			lowercase__  (				A_:	Node | None     ,			A_:	int     ,			A_:	int     ,			A_:	int		)  ->							int:
  
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
         if index > (end - start) or start > end or node is None:
                return -1
         # Leaf node case
         if node.minn == node.maxx:
                return node.minn
         # Number of elements in the left subtree in interval [start, end]
         __UpperCAmelCase    							=node.map_left[end] - (
             node.map_left[start - 1] if start else 0
         )
         if num_elements_in_left_tree > index:
                return quantile(
                    node.left     ,			A_     ,			(node.map_left[start - 1] if start else 0)     ,			node.map_left[end] - 1     ,			)
         else:
                return quantile(
                    node.right     ,			index - num_elements_in_left_tree     ,			start - (node.map_left[start - 1] if start else 0)     ,			end - node.map_left[end]     ,			)
  
  
  
  
  
  
  
  def 			lowercase__  (				A_:	Node | None     ,			A_:	int     ,			A_:	int     ,			A_:	int     ,			A_:	int		)  ->							int:
  
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
         if (
             start > end
             or node is None
             or start_num > end_num
             or node.minn > end_num
             or node.maxx < start_num
         ):
                return 0
         if start_num <= node.minn and node.maxx <= end_num:
                return end - start + 1
         __UpperCAmelCase    							=range_counting(
             node.left     ,			(node.map_left[start - 1] if start else 0)     ,			node.map_left[end] - 1     ,			A_     ,			A_     ,			)
         __UpperCAmelCase    							=range_counting(
             node.right     ,			start - (node.map_left[start - 1] if start else 0)     ,			end - node.map_left[end]     ,			A_     ,			A_     ,			)
         return left + right
  
  
  if __name__ == "__main__":
     import doctest
  
     doctest.testmod()
  
  
  
  
  