




def     lowerCAmelCase		(		_lowerCAmelCase				: list[list[int]]    ,				_lowerCAmelCase				: list[list[int]]						):




 """simple docstring"""







 UpperCAmelCase__							=    []
 UpperCAmelCase__							=    len(_lowerCAmelCase						)
 for i in range(_lowerCAmelCase						):
  UpperCAmelCase__							=    []
  for j in range(_lowerCAmelCase						):
   UpperCAmelCase__							=    0
   for k in range(_lowerCAmelCase						):
    UpperCAmelCase__							=    val + matrix_a[i][k] * matrix_b[k][j]
   list_a.append(_lowerCAmelCase						)
  matrix_c.append(_lowerCAmelCase						)
 return matrix_c



def     lowerCAmelCase		(		_lowerCAmelCase				: int						):




 """simple docstring"""







 return [[int(row == column						) for column in range(_lowerCAmelCase						)] for row in range(_lowerCAmelCase						)]



def     lowerCAmelCase		(		_lowerCAmelCase				: int						):




 """simple docstring"""







 if n <= 1:
  return n
 UpperCAmelCase__							=    identity(2						)
 UpperCAmelCase__							=    [[1, 1], [1, 0]]
 UpperCAmelCase__							=    n - 1
 while n > 0:
  if n % 2 == 1:
   UpperCAmelCase__							=    multiply(_lowerCAmelCase    ,				_lowerCAmelCase						)
  UpperCAmelCase__							=    multiply(_lowerCAmelCase    ,				_lowerCAmelCase						)
  UpperCAmelCase__							=    int(n / 2						)
 return res_matrix[0][0]



def     lowerCAmelCase		(		_lowerCAmelCase				: int						):




 """simple docstring"""







 if n <= 1:
  return n
 UpperCAmelCase__							=    0
 UpperCAmelCase__							=    1
 for _ in range(2    ,				n + 1						):
  UpperCAmelCase__							=    fiba, fiba + fiba
 return fiba



def     lowerCAmelCase		(		):




 """simple docstring"""







 for ordinal in "0th 1st 2nd 3rd 10th 100th 1000th".split():
  UpperCAmelCase__							=    int("".join(c for c in ordinal if c in "0123456789"						)						)  # 1000th --> 1000
  print(
      F'''{ordinal} fibonacci number using matrix exponentiation is '''
      F'''{nth_fibonacci_matrix(_lowerCAmelCase						)} and using bruteforce is '''
      F'''{nth_fibonacci_bruteforce(_lowerCAmelCase						)}\n'''						)
 # from timeit import timeit
 # print(timeit("nth_fibonacci_matrix(1000000)",
 #              "from main import nth_fibonacci_matrix", number=5))
 # print(timeit("nth_fibonacci_bruteforce(1000000)",
 #              "from main import nth_fibonacci_bruteforce", number=5))
 # 2.3342058970001744
 # 57.256506615000035


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  main()










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    	=  logging.get_logger(__name__)

__UpperCAmelCase    	=  {
    '''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 						lowerCamelCase__			(		_a ):
						_lowerCAmelCase             =			'''bigbird_pegasus'''
						_lowerCAmelCase             =			['''past_key_values''']
						_lowerCAmelCase             =			{
						    '''num_attention_heads''': '''encoder_attention_heads''',
						    '''hidden_size''': '''d_model''',
						    '''attention_probs_dropout_prob''': '''attention_dropout''',
						}


						def __init__(			self    :	int   ,							_a    :	List[Any]=9_6_1_0_3   ,							_a    :	Tuple=4_0_9_6   ,							_a    :	int=1_6   ,							_a    :	Dict=4_0_9_6   ,							_a    :	List[str]=1_6   ,							_a    :	Tuple=1_6   ,							_a    :	Union[str, Any]=4_0_9_6   ,							_a    :	int=1_6   ,							_a    :	Any=0.0   ,							_a    :	Union[str, Any]=0.0   ,							_a    :	Tuple=True   ,							_a    :	List[str]=True   ,							_a    :	Union[str, Any]="gelu_new"   ,							_a    :	Tuple=1_0_2_4   ,							_a    :	List[str]=0.1   ,							_a    :	Tuple=0.0   ,							_a    :	Any=0.0   ,							_a    :	int=0.0_2   ,							_a    :	str=2   ,							_a    :	Dict=0.0   ,							_a    :	Dict=True   ,							_a    :	List[str]=0   ,							_a    :	Dict=2   ,							_a    :	Any=1   ,							_a    :	Union[str, Any]="block_sparse"   ,							_a    :	Tuple=6_4   ,							_a    :	Tuple=3   ,							_a    :	List[str]=False   ,							**_a    :	Optional[Any]   ,							):
													a__:							Any									=vocab_size
													a__:							str									=max_position_embeddings
													a__:							str									=d_model
													a__:							int									=encoder_ffn_dim
													a__:							Optional[Any]									=encoder_layers
													a__:							Any									=encoder_attention_heads
													a__:							int									=decoder_ffn_dim
													a__:							Dict									=decoder_layers
													a__:							Dict									=decoder_attention_heads
													a__:							Union[str, Any]									=dropout
													a__:							List[Any]									=attention_dropout
													a__:							int									=activation_dropout
													a__:							Union[str, Any]									=activation_function
													a__:							Optional[int]									=init_std
													a__:							List[Any]									=encoder_layerdrop
													a__:							Dict									=decoder_layerdrop
													a__:							int									=classifier_dropout
													a__:							List[Any]									=use_cache
													a__:							int									=encoder_layers
													a__:							List[Any]									=scale_embedding  # scale factor will be sqrt(d_model) if True

													# extra config
													a__:							Any									=attention_type
													a__:							Any									=block_size
													a__:							int									=num_random_blocks
													a__:							List[str]									=use_bias

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


class 						lowerCamelCase__			(		_a ):


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

																				if self.use_past:
																											a__:							List[Any]									={0: "batch"}
																											a__:							int									={0: "batch", 1: "past_decoder_sequence + sequence"}
																				else:
																											a__:							List[str]									={0: "batch", 1: "decoder_sequence"}
																											a__:							Optional[int]									={0: "batch", 1: "decoder_sequence"}

																				if self.use_past:
																											self.fill_with_past_key_values_(_a   ,							direction="inputs"      )
													elif self.task == "causal-lm":
																				# TODO: figure this case out.
																				a__:							List[str]									=OrderedDict(
																				    [
																				        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
																				        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
																				    ]      )
																				if self.use_past:
																											a__				,      a__:							str									=self.num_layers
																											for i in range(_a      ):
																																		a__:							Any									={0: "batch", 2: "past_sequence + sequence"}
																																		a__:							Any									={0: "batch", 2: "past_sequence + sequence"}
													else:
																				a__:							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 	_lowerCamelCase      (			self    :	Union[str, Any]      ):
													if self.task in ["default", "seq2seq-lm"]:
																				a__:							str									=super().outputs
													else:
																				a__:							Dict									=super(_a   ,							self      ).outputs
																				if self.use_past:
																											a__				,      a__:							Tuple									=self.num_layers
																											for i in range(_a      ):
																																		a__:							str									={0: "batch", 2: "past_sequence + sequence"}
																																		a__:							List[str]									={0: "batch", 2: "past_sequence + sequence"}
													return common_outputs


						def 	_lowerCamelCase      (			self    :	Union[str, Any]   ,							_a    :	PreTrainedTokenizer   ,							_a    :	int = -1   ,							_a    :	int = -1   ,							_a    :	bool = False   ,							_a    :	Optional[TensorType] = None   ,							):
													a__:							Union[str, Any]									=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
													    _a   ,							_a   ,							_a   ,							_a   ,							_a      )

													# Generate decoder inputs
													a__:							str									=seq_length if not self.use_past else 1
													a__:							Dict									=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
													    _a   ,							_a   ,							_a   ,							_a   ,							_a      )
													a__:							List[str]									={F"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
													a__:							str									=dict(**_a   ,							**_a      )

													if self.use_past:
																				if not is_torch_available():
																											raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."      )
																				else:
																											import torch
																				a__				,      a__:							str									=common_inputs["input_ids"].shape
																				a__:							List[str]									=common_inputs["decoder_input_ids"].shape[1]
																				a__				,      a__:							Any									=self.num_attention_heads
																				a__:							int									=(
																				    batch,
																				    num_encoder_attention_heads,
																				    encoder_seq_length,
																				    self._config.hidden_size // num_encoder_attention_heads,
																				)
																				a__:							str									=decoder_seq_length + 3
																				a__:							List[str]									=(
																				    batch,
																				    num_decoder_attention_heads,
																				    decoder_past_length,
																				    self._config.hidden_size // num_decoder_attention_heads,
																				)

																				a__:							List[str]									=torch.cat(
																				    [common_inputs["decoder_attention_mask"], torch.ones(_a   ,							_a      )]   ,							dim=1      )

																				a__:							List[str]									=[]
																				# If the number of encoder and decoder layers are present in the model configuration, both are considered
																				a__				,      a__:							int									=self.num_layers
																				a__:							List[Any]									=min(_a   ,							_a      )
																				a__:							str									=max(_a   ,							_a      ) - min_num_layers
																				a__:							Optional[Any]									="encoder" if num_encoder_layers > num_decoder_layers else "decoder"

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


						def 	_lowerCamelCase      (			self    :	Any   ,							_a    :	PreTrainedTokenizer   ,							_a    :	int = -1   ,							_a    :	int = -1   ,							_a    :	bool = False   ,							_a    :	Optional[TensorType] = None   ,							):
													a__:							Tuple									=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
													    _a   ,							_a   ,							_a   ,							_a   ,							_a      )

													if self.use_past:
																				if not is_torch_available():
																											raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."      )
																				else:
																											import torch
																				a__				,      a__:							Tuple									=common_inputs["input_ids"].shape
																				# Not using the same length for past_key_values
																				a__:							str									=seqlen + 2
																				a__				,      a__:							List[str]									=self.num_layers
																				a__				,      a__:							Any									=self.num_attention_heads
																				a__:							Optional[int]									=(
																				    batch,
																				    num_encoder_attention_heads,
																				    past_key_values_length,
																				    self._config.hidden_size // num_encoder_attention_heads,
																				)

																				a__:							int									=common_inputs["attention_mask"].dtype
																				a__:							str									=torch.cat(
																				    [common_inputs["attention_mask"], torch.ones(_a   ,							_a   ,							dtype=_a      )]   ,							dim=1      )
																				a__:							int									=[
																				    (torch.zeros(_a      ), torch.zeros(_a      )) for _ in range(_a      )
																				]
													return common_inputs


						def 	_lowerCamelCase      (			self    :	Tuple   ,							_a    :	PreTrainedTokenizer   ,							_a    :	int = -1   ,							_a    :	int = -1   ,							_a    :	bool = False   ,							_a    :	Optional[TensorType] = None   ,							):
													# 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
													a__:							List[str]									=compute_effective_axis_dimension(
													    _a   ,							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
													a__:							Optional[int]									=tokenizer.num_special_tokens_to_add(_a      )
													a__:							Any									=compute_effective_axis_dimension(
													    _a   ,							fixed_dimension=OnnxConfig.default_fixed_sequence   ,							num_token_to_add=_a      )

													# Generate dummy inputs according to compute batch and sequence
													a__:							Any									=[" ".join([tokenizer.unk_token]      ) * seq_length] * batch_size
													a__:							Optional[Any]									=dict(tokenizer(_a   ,							return_tensors=_a      )      )
													return common_inputs


						def 	_lowerCamelCase      (			self    :	Dict   ,							_a    :	PreTrainedTokenizer   ,							_a    :	int = -1   ,							_a    :	int = -1   ,							_a    :	bool = False   ,							_a    :	Optional[TensorType] = None   ,							):
													if self.task in ["default", "seq2seq-lm"]:
																				a__:							Any									=self._generate_dummy_inputs_for_default_and_seqaseq_lm(
																				    _a   ,							batch_size=_a   ,							seq_length=_a   ,							is_pair=_a   ,							framework=_a      )

													elif self.task == "causal-lm":
																				a__:							Dict									=self._generate_dummy_inputs_for_causal_lm(
																				    _a   ,							batch_size=_a   ,							seq_length=_a   ,							is_pair=_a   ,							framework=_a      )
													else:
																				a__:							int									=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
																				    _a   ,							batch_size=_a   ,							seq_length=_a   ,							is_pair=_a   ,							framework=_a      )

													return common_inputs







						def 	_lowerCamelCase      (			self    :	List[str]   ,							_a    :	int   ,							_a    :	str   ,							_a    :	Any   ,							_a    :	str      ):
													if self.task in ["default", "seq2seq-lm"]:
																				a__:							Tuple									=super()._flatten_past_key_values_(_a   ,							_a   ,							_a   ,							_a      )
													else:
																				a__:							Tuple									=super(_a   ,							self      )._flatten_past_key_values_(
																				    _a   ,							_a   ,							_a   ,							_a      )





