



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


__lowerCAmelCase       :					Optional[int]      					=					logging.get_logger(__name__)

__lowerCAmelCase       :					Optional[int]      					=					{
    '''facebook/blenderbot_small-90M''': '''https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/config.json''',
    # See all BlenderbotSmall models at https://huggingface.co/models?filter=blenderbot_small
}



class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       '''blenderbot-small'''
		_lowerCamelCase			  =       ['''past_key_values''']
		_lowerCamelCase			  =       {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}





		def __init__(					self							,    _lowercase=5_0_2_6_5							,    _lowercase=5_1_2							,    _lowercase=8							,    _lowercase=2_0_4_8							,    _lowercase=1_6							,    _lowercase=8							,    _lowercase=2_0_4_8							,    _lowercase=1_6							,    _lowercase=0.0							,    _lowercase=0.0							,    _lowercase=True							,    _lowercase=True							,    _lowercase="gelu"							,    _lowercase=5_1_2							,    _lowercase=0.1							,    _lowercase=0.0							,    _lowercase=0.0							,    _lowercase=0.02							,    _lowercase=1							,    _lowercase=False							,    _lowercase=0							,    _lowercase=1							,    _lowercase=2							,    _lowercase=2							,    **_lowercase							,    ) ->						Union[str, Any]:







								'''simple docstring'''

								snake_case_   : Optional[int]						=			vocab_size
								snake_case_   : Dict						=			max_position_embeddings
								snake_case_   : Union[str, Any]						=			d_model
								snake_case_   : List[str]						=			encoder_ffn_dim
								snake_case_   : Any						=			encoder_layers
								snake_case_   : Optional[Any]						=			encoder_attention_heads
								snake_case_   : int						=			decoder_ffn_dim
								snake_case_   : List[str]						=			decoder_layers
								snake_case_   : str						=			decoder_attention_heads
								snake_case_   : str						=			dropout
								snake_case_   : List[str]						=			attention_dropout
								snake_case_   : Any						=			activation_dropout
								snake_case_   : Optional[int]						=			activation_function
								snake_case_   : int						=			init_std
								snake_case_   : List[str]						=			encoder_layerdrop
								snake_case_   : Dict						=			decoder_layerdrop
								snake_case_   : List[Any]						=			use_cache
								snake_case_   : Optional[Any]						=			encoder_layers
								snake_case_   : Any						=			scale_embedding  # scale factor will be sqrt(d_model) if True

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




class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		@property
		def    UpperCAmelCase__							(					self   ) ->						Mapping[str, Mapping[int, str]]:







								'''simple docstring'''

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

														if self.use_past:
																				snake_case_   : int						=			{0: """batch"""}
																				snake_case_   : str						=			{0: """batch""", 1: """past_decoder_sequence + sequence"""}
														else:
																				snake_case_   : Union[str, Any]						=			{0: """batch""", 1: """decoder_sequence"""}
																				snake_case_   : Optional[Any]						=			{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.
														snake_case_   : Dict						=			OrderedDict(
														    [
														        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
														        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
														    ]   )
														if self.use_past:
																				snake_case_			,		snake_case_   : int						=			self.num_layers
																				for i in range(_lowercase   ):
																										snake_case_   : Any						=			{0: """batch""", 2: """past_sequence + sequence"""}
																										snake_case_   : Optional[int]						=			{0: """batch""", 2: """past_sequence + sequence"""}
								else:
														snake_case_   : Any						=			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   ) ->						Mapping[str, Mapping[int, str]]:







								'''simple docstring'''

								if self.task in ["default", "seq2seq-lm"]:
														snake_case_   : Any						=			super().outputs
								else:
														snake_case_   : Optional[int]						=			super(_lowercase							,    self   ).outputs
														if self.use_past:
																				snake_case_			,		snake_case_   : str						=			self.num_layers
																				for i in range(_lowercase   ):
																										snake_case_   : str						=			{0: """batch""", 2: """past_sequence + sequence"""}
																										snake_case_   : Dict						=			{0: """batch""", 2: """past_sequence + sequence"""}
								return common_outputs





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase = -1							,    _lowercase = -1							,    _lowercase = False							,    _lowercase = None							,    ) ->						Mapping[str, Any]:







								'''simple docstring'''

								snake_case_   : Tuple						=			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
								    _lowercase							,    _lowercase							,    _lowercase							,    _lowercase							,    _lowercase   )

								# Generate decoder inputs
								snake_case_   : List[str]						=			seq_length if not self.use_past else 1
								snake_case_   : str						=			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
								    _lowercase							,    _lowercase							,    _lowercase							,    _lowercase							,    _lowercase   )
								snake_case_   : Optional[Any]						=			{f'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
								snake_case_   : Any						=			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
														snake_case_			,		snake_case_   : Optional[int]						=			common_inputs["""input_ids"""].shape
														snake_case_   : Optional[int]						=			common_inputs["""decoder_input_ids"""].shape[1]
														snake_case_			,		snake_case_   : Optional[Any]						=			self.num_attention_heads
														snake_case_   : Optional[Any]						=			(
														    batch,
														    num_encoder_attention_heads,
														    encoder_seq_length,
														    self._config.hidden_size // num_encoder_attention_heads,
														)
														snake_case_   : Tuple						=			decoder_seq_length + 3
														snake_case_   : int						=			(
														    batch,
														    num_decoder_attention_heads,
														    decoder_past_length,
														    self._config.hidden_size // num_decoder_attention_heads,
														)

														snake_case_   : Optional[Any]						=			torch.cat(
														    [common_inputs["""decoder_attention_mask"""], torch.ones(_lowercase							,    _lowercase   )]							,    dim=1   )

														snake_case_   : Optional[Any]						=			[]
														# If the number of encoder and decoder layers are present in the model configuration, both are considered
														snake_case_			,		snake_case_   : List[str]						=			self.num_layers
														snake_case_   : List[str]						=			min(_lowercase							,    _lowercase   )
														snake_case_   : Optional[Any]						=			max(_lowercase							,    _lowercase   ) - min_num_layers
														snake_case_   : Optional[Any]						=			"""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.
														snake_case_   : Optional[Any]						=			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    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase = -1							,    _lowercase = -1							,    _lowercase = False							,    _lowercase = None							,    ) ->						Mapping[str, Any]:







								'''simple docstring'''

								snake_case_   : Union[str, Any]						=			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
														snake_case_			,		snake_case_   : Any						=			common_inputs["""input_ids"""].shape
														# Not using the same length for past_key_values
														snake_case_   : List[Any]						=			seqlen + 2
														snake_case_			,		snake_case_   : Any						=			self.num_layers
														snake_case_			,		snake_case_   : Any						=			self.num_attention_heads
														snake_case_   : List[str]						=			(
														    batch,
														    num_encoder_attention_heads,
														    past_key_values_length,
														    self._config.hidden_size // num_encoder_attention_heads,
														)

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





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase = -1							,    _lowercase = -1							,    _lowercase = False							,    _lowercase = None							,    ) ->						Mapping[str, Any]:







								'''simple docstring'''

								snake_case_   : Any						=			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
								snake_case_   : Any						=			tokenizer.num_special_tokens_to_add(_lowercase   )
								snake_case_   : Dict						=			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
								snake_case_   : Dict						=			[""" """.join([tokenizer.unk_token]   ) * seq_length] * batch_size
								snake_case_   : List[Any]						=			dict(tokenizer(_lowercase							,    return_tensors=_lowercase   )   )
								return common_inputs





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase = -1							,    _lowercase = -1							,    _lowercase = False							,    _lowercase = None							,    ) ->						Mapping[str, Any]:







								'''simple docstring'''

								if self.task in ["default", "seq2seq-lm"]:
														snake_case_   : str						=			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":
														snake_case_   : int						=			self._generate_dummy_inputs_for_causal_lm(
														    _lowercase							,    batch_size=_lowercase							,    seq_length=_lowercase							,    is_pair=_lowercase							,    framework=_lowercase   )
								else:
														snake_case_   : List[Any]						=			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    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase							,    _lowercase							,    _lowercase   ) ->						Any:







								'''simple docstring'''

								if self.task in ["default", "seq2seq-lm"]:
														snake_case_   : Union[str, Any]						=			super()._flatten_past_key_values_(_lowercase							,    _lowercase							,    _lowercase							,    _lowercase   )
								else:
														snake_case_   : int						=			super(_lowercase							,    self   )._flatten_past_key_values_(
														    _lowercase							,    _lowercase							,    _lowercase							,    _lowercase   )






"""simple docstring"""





def 	__lowerCAmelCase						(		__UpperCamelCase      :			int					, __UpperCamelCase      :			int    ):


						'''simple docstring'''






						snake_case_   : Any						=			1  # To kept the Calculated Value
						# Since C(n, k) = C(n, n-k)
						if k > (n - k):
												snake_case_   : Optional[int]						=			n - k
						# Calculate C(n,k)
						for i in range(__UpperCamelCase    ):
												result *= n - i
												result //= i + 1
						return result
def 	__lowerCAmelCase						(		__UpperCamelCase      :			int    ):


						'''simple docstring'''






						return binomial_coefficient(2 * node_count					, __UpperCamelCase    ) // (node_count + 1)
def 	__lowerCAmelCase						(		__UpperCamelCase      :			int    ):


						'''simple docstring'''






						if n < 0:
												raise ValueError("""factorial() not defined for negative values"""    )
						snake_case_   : Optional[int]						=			1
						for i in range(1					, n + 1    ):
												result *= i
						return result
def 	__lowerCAmelCase						(		__UpperCamelCase      :			int    ):


						'''simple docstring'''






						return catalan_number(__UpperCamelCase    ) * factorial(__UpperCamelCase    )


if __name__ == "__main__":
					__lowerCAmelCase       :					Optional[Any]      					=					int(input('''Enter the number of nodes: ''').strip() or 0)
					if node_count <= 0:
										raise ValueError('''We need some nodes to work with.''')
					print(
					    F'''Given {node_count} nodes, there are {binary_tree_count(node_count)} '''
					    F'''binary trees and {catalan_number(node_count)} binary search trees.'''
					)

