






"""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


_SCREAMING_SNAKE_CASE :    List[str]    =						logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE :    str    =						{
    '''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						( __snake_case		):
    SCREAMING_SNAKE_CASE						:					Tuple						=			"""bigbird_pegasus"""
    SCREAMING_SNAKE_CASE						:					Any						=			["""past_key_values"""]
    SCREAMING_SNAKE_CASE						:					Union[str, Any]						=			{
        """num_attention_heads""": """encoder_attention_heads""",
        """hidden_size""": """d_model""",
        """attention_probs_dropout_prob""": """attention_dropout""",
    }






    def __init__(	self					:							Dict	,						__SCREAMING_SNAKE_CASE					:							List[str]=96103	,						__SCREAMING_SNAKE_CASE					:							List[Any]=4096	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=16	,						__SCREAMING_SNAKE_CASE					:							Optional[Any]=4096	,						__SCREAMING_SNAKE_CASE					:							Union[str, Any]=16	,						__SCREAMING_SNAKE_CASE					:							List[str]=16	,						__SCREAMING_SNAKE_CASE					:							str=4096	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=16	,						__SCREAMING_SNAKE_CASE					:							List[Any]=0.0	,						__SCREAMING_SNAKE_CASE					:							int=0.0	,						__SCREAMING_SNAKE_CASE					:							List[Any]=True	,						__SCREAMING_SNAKE_CASE					:							Union[str, Any]=True	,						__SCREAMING_SNAKE_CASE					:							Union[str, Any]="gelu_new"	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=1024	,						__SCREAMING_SNAKE_CASE					:							Dict=0.1	,						__SCREAMING_SNAKE_CASE					:							Any=0.0	,						__SCREAMING_SNAKE_CASE					:							Optional[Any]=0.0	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=0.02	,						__SCREAMING_SNAKE_CASE					:							Dict=2	,						__SCREAMING_SNAKE_CASE					:							Union[str, Any]=0.0	,						__SCREAMING_SNAKE_CASE					:							str=True	,						__SCREAMING_SNAKE_CASE					:							str=0	,						__SCREAMING_SNAKE_CASE					:							Tuple=2	,						__SCREAMING_SNAKE_CASE					:							Optional[int]=1	,						__SCREAMING_SNAKE_CASE					:							int="block_sparse"	,						__SCREAMING_SNAKE_CASE					:							Dict=64	,						__SCREAMING_SNAKE_CASE					:							List[str]=3	,						__SCREAMING_SNAKE_CASE					:							Any=False	,						**__SCREAMING_SNAKE_CASE					:							List[str]	,						)					->		Any:
      lowerCamelCase_   					=						vocab_size
      lowerCamelCase_   					=						max_position_embeddings
      lowerCamelCase_   					=						d_model
      lowerCamelCase_   					=						encoder_ffn_dim
      lowerCamelCase_   					=						encoder_layers
      lowerCamelCase_   					=						encoder_attention_heads
      lowerCamelCase_   					=						decoder_ffn_dim
      lowerCamelCase_   					=						decoder_layers
      lowerCamelCase_   					=						decoder_attention_heads
      lowerCamelCase_   					=						dropout
      lowerCamelCase_   					=						attention_dropout
      lowerCamelCase_   					=						activation_dropout
      lowerCamelCase_   					=						activation_function
      lowerCamelCase_   					=						init_std
      lowerCamelCase_   					=						encoder_layerdrop
      lowerCamelCase_   					=						decoder_layerdrop
      lowerCamelCase_   					=						classifier_dropout
      lowerCamelCase_   					=						use_cache
      lowerCamelCase_   					=						encoder_layers
      lowerCamelCase_   					=						scale_embedding  # scale factor will be sqrt(d_model) if True

      # extra config
      lowerCamelCase_   					=						attention_type
      lowerCamelCase_   					=						block_size
      lowerCamelCase_   					=						num_random_blocks
      lowerCamelCase_   					=						use_bias

      super().__init__(
          pad_token_id=__SCREAMING_SNAKE_CASE	,						bos_token_id=__SCREAMING_SNAKE_CASE	,						eos_token_id=__SCREAMING_SNAKE_CASE	,						is_encoder_decoder=__SCREAMING_SNAKE_CASE	,						decoder_start_token_id=__SCREAMING_SNAKE_CASE	,						**__SCREAMING_SNAKE_CASE	,						)






class 					a						( __snake_case		):






    @property
    def        UpperCamelCase	(	self					:							Optional[Any] )					->		Mapping[str, Mapping[int, str]]:
      if self.task in ["default", "seq2seq-lm"]:
        lowerCamelCase_   					=						OrderedDict(
            [
                ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
            ] )

        if self.use_past:
          lowerCamelCase_   					=						{0: 'batch'}
          lowerCamelCase_   					=						{0: 'batch', 1: 'past_decoder_sequence + sequence'}
        else:
          lowerCamelCase_   					=						{0: 'batch', 1: 'decoder_sequence'}
          lowerCamelCase_   					=						{0: 'batch', 1: 'decoder_sequence'}

        if self.use_past:
          self.fill_with_past_key_values_(__SCREAMING_SNAKE_CASE	,						direction='inputs' )
      elif self.task == "causal-lm":
        # TODO: figure this case out.
        lowerCamelCase_   					=						OrderedDict(
            [
                ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
            ] )
        if self.use_past:
          lowerCamelCase_					,     lowerCamelCase_   					=						self.num_layers
          for i in range(__SCREAMING_SNAKE_CASE ):
            lowerCamelCase_   					=						{0: 'batch', 2: 'past_sequence + sequence'}
            lowerCamelCase_   					=						{0: 'batch', 2: 'past_sequence + sequence'}
      else:
        lowerCamelCase_   					=						OrderedDict(
            [
                ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
                ('decoder_input_ids', {0: 'batch', 1: 'decoder_sequence'}),
                ('decoder_attention_mask', {0: 'batch', 1: 'decoder_sequence'}),
            ] )

      return common_inputs






    @property
    def        UpperCamelCase	(	self					:							int )					->		Mapping[str, Mapping[int, str]]:
      if self.task in ["default", "seq2seq-lm"]:
        lowerCamelCase_   					=						super().outputs
      else:
        lowerCamelCase_   					=						super(__SCREAMING_SNAKE_CASE	,						self ).outputs
        if self.use_past:
          lowerCamelCase_					,     lowerCamelCase_   					=						self.num_layers
          for i in range(__SCREAMING_SNAKE_CASE ):
            lowerCamelCase_   					=						{0: 'batch', 2: 'past_sequence + sequence'}
            lowerCamelCase_   					=						{0: 'batch', 2: 'past_sequence + sequence'}
      return common_outputs






    def        UpperCamelCase	(	self					:							Dict	,						__SCREAMING_SNAKE_CASE					:							PreTrainedTokenizer	,						__SCREAMING_SNAKE_CASE					:							int = -1	,						__SCREAMING_SNAKE_CASE					:							int = -1	,						__SCREAMING_SNAKE_CASE					:							bool = False	,						__SCREAMING_SNAKE_CASE					:							Optional[TensorType] = None	,						)					->		Mapping[str, Any]:
      lowerCamelCase_   					=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          __SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE )

      # Generate decoder inputs
      lowerCamelCase_   					=						seq_length if not self.use_past else 1
      lowerCamelCase_   					=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          __SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE )
      lowerCamelCase_   					=						{F'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
      lowerCamelCase_   					=						dict(**__SCREAMING_SNAKE_CASE	,						**__SCREAMING_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
        lowerCamelCase_					,     lowerCamelCase_   					=						common_inputs['input_ids'].shape
        lowerCamelCase_   					=						common_inputs['decoder_input_ids'].shape[1]
        lowerCamelCase_					,     lowerCamelCase_   					=						self.num_attention_heads
        lowerCamelCase_   					=						(
            batch,
            num_encoder_attention_heads,
            encoder_seq_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )
        lowerCamelCase_   					=						decoder_seq_length + 3
        lowerCamelCase_   					=						(
            batch,
            num_decoder_attention_heads,
            decoder_past_length,
            self._config.hidden_size // num_decoder_attention_heads,
        )

        lowerCamelCase_   					=						torch.cat(
            [common_inputs['decoder_attention_mask'], torch.ones(__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE )]	,						dim=1 )

        lowerCamelCase_   					=						[]
        # If the number of encoder and decoder layers are present in the model configuration, both are considered
        lowerCamelCase_					,     lowerCamelCase_   					=						self.num_layers
        lowerCamelCase_   					=						min(__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE )
        lowerCamelCase_   					=						max(__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE ) - min_num_layers
        lowerCamelCase_   					=						'encoder' if num_encoder_layers > num_decoder_layers else 'decoder'

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






    def        UpperCamelCase	(	self					:							Optional[Any]	,						__SCREAMING_SNAKE_CASE					:							PreTrainedTokenizer	,						__SCREAMING_SNAKE_CASE					:							int = -1	,						__SCREAMING_SNAKE_CASE					:							int = -1	,						__SCREAMING_SNAKE_CASE					:							bool = False	,						__SCREAMING_SNAKE_CASE					:							Optional[TensorType] = None	,						)					->		Mapping[str, Any]:
      lowerCamelCase_   					=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
          __SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_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
        lowerCamelCase_					,     lowerCamelCase_   					=						common_inputs['input_ids'].shape
        # Not using the same length for past_key_values
        lowerCamelCase_   					=						seqlen + 2
        lowerCamelCase_					,     lowerCamelCase_   					=						self.num_layers
        lowerCamelCase_					,     lowerCamelCase_   					=						self.num_attention_heads
        lowerCamelCase_   					=						(
            batch,
            num_encoder_attention_heads,
            past_key_values_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )

        lowerCamelCase_   					=						common_inputs['attention_mask'].dtype
        lowerCamelCase_   					=						torch.cat(
            [common_inputs['attention_mask'], torch.ones(__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						dtype=__SCREAMING_SNAKE_CASE )]	,						dim=1 )
        lowerCamelCase_   					=						[
            (torch.zeros(__SCREAMING_SNAKE_CASE ), torch.zeros(__SCREAMING_SNAKE_CASE )) for _ in range(__SCREAMING_SNAKE_CASE )
        ]
      return common_inputs






    def        UpperCamelCase	(	self					:							Optional[int]	,						__SCREAMING_SNAKE_CASE					:							PreTrainedTokenizer	,						__SCREAMING_SNAKE_CASE					:							int = -1	,						__SCREAMING_SNAKE_CASE					:							int = -1	,						__SCREAMING_SNAKE_CASE					:							bool = False	,						__SCREAMING_SNAKE_CASE					:							Optional[TensorType] = None	,						)					->		Mapping[str, Any]:
      # Copied from OnnxConfig.generate_dummy_inputs
      # Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
      # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
      lowerCamelCase_   					=						compute_effective_axis_dimension(
          __SCREAMING_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
      lowerCamelCase_   					=						tokenizer.num_special_tokens_to_add(__SCREAMING_SNAKE_CASE )
      lowerCamelCase_   					=						compute_effective_axis_dimension(
          __SCREAMING_SNAKE_CASE	,						fixed_dimension=OnnxConfig.default_fixed_sequence	,						num_token_to_add=__SCREAMING_SNAKE_CASE )

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






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

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

      return common_inputs






    def        UpperCamelCase	(	self					:							Union[str, Any]	,						__SCREAMING_SNAKE_CASE					:							List[str]	,						__SCREAMING_SNAKE_CASE					:							Optional[int]	,						__SCREAMING_SNAKE_CASE					:							List[Any]	,						__SCREAMING_SNAKE_CASE					:							Tuple )					->		int:
      if self.task in ["default", "seq2seq-lm"]:
        lowerCamelCase_   					=						super()._flatten_past_key_values_(__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE )
      else:
        lowerCamelCase_   					=						super(__SCREAMING_SNAKE_CASE	,						self )._flatten_past_key_values_(
            __SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE )












"""simple docstring"""





def 					lowerCamelCase__	(							_lowerCamelCase	:		int = 1000			)				->    int:
  lowerCamelCase_   					=						0
  lowerCamelCase_   					=						(n - 1) // 3
  total += ((terms) * (6 + (terms - 1) * 3)) // 2  # total of an A.P.
  lowerCamelCase_   					=						(n - 1) // 5
  total += ((terms) * (10 + (terms - 1) * 5)) // 2
  lowerCamelCase_   					=						(n - 1) // 15
  total -= ((terms) * (30 + (terms - 1) * 15)) // 2
  return total


if __name__ == "__main__":
  print(F'''{solution() = }''')




