
"""simple docstring"""


from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...file_utils import TensorType, is_torch_available
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import logging


__A       						=       logging.get_logger(__name__)

__A       						=       {
    'facebook/blenderbot-3B': 'https://huggingface.co/facebook/blenderbot-3B/resolve/main/config.json',
    # See all Blenderbot models at https://huggingface.co/models?filter=blenderbot
}







class 		lowerCamelCase__					(					__magic_name__				):





			'''simple docstring'''
			lowerCamelCase  					=		'''blenderbot'''
			lowerCamelCase  					=		['''past_key_values''']
			lowerCamelCase  					=		{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}



			def __init__(							self     ,     __UpperCAmelCase=80_08     ,     __UpperCAmelCase=1_28     ,     __UpperCAmelCase=2     ,     __UpperCAmelCase=1_02_40     ,     __UpperCAmelCase=32     ,     __UpperCAmelCase=24     ,     __UpperCAmelCase=1_02_40     ,     __UpperCAmelCase=32     ,     __UpperCAmelCase=0.0     ,     __UpperCAmelCase=0.0     ,     __UpperCAmelCase=True     ,     __UpperCAmelCase=True     ,     __UpperCAmelCase="gelu"     ,     __UpperCAmelCase=25_60     ,     __UpperCAmelCase=0.1     ,     __UpperCAmelCase=0.0     ,     __UpperCAmelCase=0.0     ,     __UpperCAmelCase=0.0_2     ,     __UpperCAmelCase=1     ,     __UpperCAmelCase=False     ,     __UpperCAmelCase=0     ,     __UpperCAmelCase=1     ,     __UpperCAmelCase=2     ,     __UpperCAmelCase=3     ,     __UpperCAmelCase=2     ,     **__UpperCAmelCase     ,     ) ->     Optional[int]:
				_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								=use_cache
				_lowerCAmelCase								=encoder_layers
				_lowerCAmelCase								=scale_embedding  # scale factor will be sqrt(d_model) if True

				super().__init__(
				    pad_token_id=__UpperCAmelCase     ,     bos_token_id=__UpperCAmelCase     ,     eos_token_id=__UpperCAmelCase     ,     is_encoder_decoder=__UpperCAmelCase     ,     decoder_start_token_id=__UpperCAmelCase     ,     encoder_no_repeat_ngram_size=__UpperCAmelCase     ,     forced_eos_token_id=__UpperCAmelCase     ,     **__UpperCAmelCase     ,     )







class 		lowerCamelCase__					(					__magic_name__				):





			'''simple docstring'''



			@property
			def 					_lowerCAmelCase		(							self  ) ->     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_(__UpperCAmelCase     ,     direction="""inputs"""  )
				elif self.task == "causal-lm":
					_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(__UpperCAmelCase  ):
							_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
			# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
			def 					_lowerCAmelCase		(							self  ) ->     Mapping[str, Mapping[int, str]]:
				if self.task in ["default", "seq2seq-lm"]:
					_lowerCAmelCase								=super().outputs
				else:
					_lowerCAmelCase								=super(__UpperCAmelCase     ,     self  ).outputs
					if self.use_past:
						_lowerCAmelCase						,							_lowerCAmelCase								=self.num_layers
						for i in range(__UpperCAmelCase  ):
							_lowerCAmelCase								={0: """batch""", 2: """past_sequence + sequence"""}
							_lowerCAmelCase								={0: """batch""", 2: """past_sequence + sequence"""}
				return common_outputs



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase = -1     ,     __UpperCAmelCase = -1     ,     __UpperCAmelCase = False     ,     __UpperCAmelCase = None     ,     ) ->     Mapping[str, Any]:
				_lowerCAmelCase								=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
				    __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  )
				# Generate decoder inputs
				_lowerCAmelCase								=seq_length if not self.use_past else 1
				_lowerCAmelCase								=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
				    __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  )
				_lowerCAmelCase								={f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
				_lowerCAmelCase								=dict(**__UpperCAmelCase     ,     **__UpperCAmelCase  )

				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
					_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(__UpperCAmelCase     ,     __UpperCAmelCase  )]     ,     dim=1  )
					_lowerCAmelCase								=[]
					_lowerCAmelCase						,							_lowerCAmelCase								=self.num_layers

					for _ in range(__UpperCAmelCase  ):
						common_inputs["past_key_values"].append(
						    (
						        torch.zeros(__UpperCAmelCase  ),
						        torch.zeros(__UpperCAmelCase  ),
						        torch.zeros(__UpperCAmelCase  ),
						        torch.zeros(__UpperCAmelCase  ),
						    )  )
				return common_inputs



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase = -1     ,     __UpperCAmelCase = -1     ,     __UpperCAmelCase = False     ,     __UpperCAmelCase = None     ,     ) ->     Mapping[str, Any]:
				_lowerCAmelCase								=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
				    __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  )

				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								=seqlen
					_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(__UpperCAmelCase     ,     __UpperCAmelCase     ,     dtype=__UpperCAmelCase  )]     ,     dim=1  )
					_lowerCAmelCase								=[
					    (torch.zeros(__UpperCAmelCase  ), torch.zeros(__UpperCAmelCase  )) for _ in range(__UpperCAmelCase  )
					]
				return common_inputs



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase = -1     ,     __UpperCAmelCase = -1     ,     __UpperCAmelCase = False     ,     __UpperCAmelCase = 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(
				    __UpperCAmelCase     ,     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(__UpperCAmelCase  )
				_lowerCAmelCase								=compute_effective_axis_dimension(
				    __UpperCAmelCase     ,     fixed_dimension=OnnxConfig.default_fixed_sequence     ,     num_token_to_add=__UpperCAmelCase  )

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



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase = -1     ,     __UpperCAmelCase = -1     ,     __UpperCAmelCase = False     ,     __UpperCAmelCase = None     ,     ) ->     Mapping[str, Any]:
				if self.task in ["default", "seq2seq-lm"]:
					_lowerCAmelCase								=self._generate_dummy_inputs_for_default_and_seqaseq_lm(
					    __UpperCAmelCase     ,     batch_size=__UpperCAmelCase     ,     seq_length=__UpperCAmelCase     ,     is_pair=__UpperCAmelCase     ,     framework=__UpperCAmelCase  )

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

				return common_inputs



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  ) ->     int:
				if self.task in ["default", "seq2seq-lm"]:
					_lowerCAmelCase								=super()._flatten_past_key_values_(__UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  )
				else:
					_lowerCAmelCase								=super(__UpperCAmelCase     ,     self  )._flatten_past_key_values_(
					    __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  )



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase  ) ->     str:
				if direction not in ["inputs", "outputs"]:
					raise ValueError(f'''direction must either be "inputs" or "outputs", but {direction} was given'''  )

				_lowerCAmelCase								="""past_key_values""" if direction == """inputs""" else """present"""
				_lowerCAmelCase						,							_lowerCAmelCase								=self.num_layers

				_lowerCAmelCase								="""past_encoder_sequence"""
				_lowerCAmelCase								="""past_decoder_sequence""" if direction == """inputs""" else """past_decoder_sequence + sequence"""

				for i in range(__UpperCAmelCase  ):
					_lowerCAmelCase								={0: """batch""", 2: decoder_sequence}
					_lowerCAmelCase								={0: """batch""", 2: decoder_sequence}
					_lowerCAmelCase								={0: """batch""", 2: encoder_sequence}
					_lowerCAmelCase								={0: """batch""", 2: encoder_sequence}









'''simple docstring'''







from functools import lru_cache






@lru_cache
def 		_lowercase		(	lowercase_  ):



		'''simple docstring'''







		if not isinstance(lowercase_						,							lowercase_  ):
				raise TypeError("k must be an integer."  )
		if k < 0:
				raise ValueError("k integer must be greater or equal to zero."  )
		if k == 0:
				return 0
		elif k == 1:
				return 1
		else:
				return fibonacci(k - 1  ) + fibonacci(k - 2  )






def 		_lowercase		(	lowercase_						,							lowercase_  ):



		'''simple docstring'''







		_snake_case	       =       len(lowercase_  )
		# Find m such that F_m >= n where F_i is the i_th fibonacci number.
		_snake_case	       =       0
		while True:
				if fibonacci(lowercase_  ) >= len_list:
						_snake_case	       =       i
						break
				i += 1
		_snake_case	       =       0
		while fibb_k > 0:
				_snake_case	       =       min(
				    offset + fibonacci(fibb_k - 1  )						,							len_list - 1  )  # Prevent out of range
				_snake_case	       =       arr[index_k]
				if item_k_1 == val:
						return index_k
				elif val < item_k_1:
						fibb_k -= 1
				elif val > item_k_1:
						offset += fibonacci(fibb_k - 1  )
						fibb_k -= 2
		else:
				return -1


if __name__ == "__main__":
						import doctest

						doctest.testmod()





