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

lowerCAmelCase_     =	{
    '''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  _snake_case		(    UpperCAmelCase__ ):







				"""simple docstring"""






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





				def __init__(      self							:							List[Any]      ,    _A							:							Dict=5_0_2_6_5      ,    _A							:							Dict=5_1_2      ,    _A							:							Any=8      ,    _A							:							str=2_0_4_8      ,    _A							:							Union[str, Any]=1_6      ,    _A							:							List[str]=8      ,    _A							:							str=2_0_4_8      ,    _A							:							Optional[int]=1_6      ,    _A							:							List[Any]=0.0      ,    _A							:							int=0.0      ,    _A							:							Optional[int]=True      ,    _A							:							Optional[Any]=True      ,    _A							:							int="gelu"      ,    _A							:							Union[str, Any]=5_1_2      ,    _A							:							Any=0.1      ,    _A							:							List[Any]=0.0      ,    _A							:							Union[str, Any]=0.0      ,    _A							:							List[Any]=0.02      ,    _A							:							Tuple=1      ,    _A							:							str=False      ,    _A							:							str=0      ,    _A							:							int=1      ,    _A							:							Any=2      ,    _A							:							int=2      ,    **_A							:							Tuple      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    vocab_size
											_SCREAMING_SNAKE_CASE			  =    max_position_embeddings
											_SCREAMING_SNAKE_CASE			  =    d_model
											_SCREAMING_SNAKE_CASE			  =    encoder_ffn_dim
											_SCREAMING_SNAKE_CASE			  =    encoder_layers
											_SCREAMING_SNAKE_CASE			  =    encoder_attention_heads
											_SCREAMING_SNAKE_CASE			  =    decoder_ffn_dim
											_SCREAMING_SNAKE_CASE			  =    decoder_layers
											_SCREAMING_SNAKE_CASE			  =    decoder_attention_heads
											_SCREAMING_SNAKE_CASE			  =    dropout
											_SCREAMING_SNAKE_CASE			  =    attention_dropout
											_SCREAMING_SNAKE_CASE			  =    activation_dropout
											_SCREAMING_SNAKE_CASE			  =    activation_function
											_SCREAMING_SNAKE_CASE			  =    init_std
											_SCREAMING_SNAKE_CASE			  =    encoder_layerdrop
											_SCREAMING_SNAKE_CASE			  =    decoder_layerdrop
											_SCREAMING_SNAKE_CASE			  =    use_cache
											_SCREAMING_SNAKE_CASE			  =    encoder_layers
											_SCREAMING_SNAKE_CASE			  =    scale_embedding  # scale factor will be sqrt(d_model) if True

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




class  _snake_case		(    UpperCAmelCase__ ):







				"""simple docstring"""






				@property
				def 		_lowerCAmelCase		(      self							:							List[Any]):



											"""simple docstring"""







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

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



											"""simple docstring"""







											if self.task in ["default", "seq2seq-lm"]:
																		_SCREAMING_SNAKE_CASE			  =    super().outputs
											else:
																		_SCREAMING_SNAKE_CASE			  =    super(_A      ,    self).outputs
																		if self.use_past:
																									_SCREAMING_SNAKE_CASE			  =    self.num_layers
																									for i in range(_A):
																																_SCREAMING_SNAKE_CASE			  =    {0: """batch""", 2: """past_sequence + sequence"""}
																																_SCREAMING_SNAKE_CASE			  =    {0: """batch""", 2: """past_sequence + sequence"""}
											return common_outputs





				def 		_lowerCAmelCase		(      self							:							List[str]      ,    _A							:							PreTrainedTokenizer      ,    _A							:							int = -1      ,    _A							:							int = -1      ,    _A							:							bool = False      ,    _A							:							Optional[TensorType] = None      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
											    _A      ,    _A      ,    _A      ,    _A      ,    _A)

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

																		_SCREAMING_SNAKE_CASE			  =    torch.cat(
																		    [common_inputs["""decoder_attention_mask"""], torch.ones(_A      ,    _A)]      ,    dim=1)

																		_SCREAMING_SNAKE_CASE			  =    []
																		# If the number of encoder and decoder layers are present in the model configuration, both are considered
																		_SCREAMING_SNAKE_CASE			  =    self.num_layers
																		_SCREAMING_SNAKE_CASE			  =    min(_A      ,    _A)
																		_SCREAMING_SNAKE_CASE			  =    max(_A      ,    _A) - min_num_layers
																		_SCREAMING_SNAKE_CASE			  =    """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.
																		_SCREAMING_SNAKE_CASE			  =    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      ,    ):



											"""simple docstring"""







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

																		_SCREAMING_SNAKE_CASE			  =    common_inputs["""attention_mask"""].dtype
																		_SCREAMING_SNAKE_CASE			  =    torch.cat(
																		    [common_inputs["""attention_mask"""], torch.ones(_A      ,    _A      ,    dtype=_A)]      ,    dim=1)
																		_SCREAMING_SNAKE_CASE			  =    [
																		    (torch.zeros(_A), torch.zeros(_A)) for _ in range(_A)
																		]
											return common_inputs





				def 		_lowerCAmelCase		(      self							:							Any      ,    _A							:							PreTrainedTokenizer      ,    _A							:							int = -1      ,    _A							:							int = -1      ,    _A							:							bool = False      ,    _A							:							Optional[TensorType] = None      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    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
											_SCREAMING_SNAKE_CASE			  =    tokenizer.num_special_tokens_to_add(_A)
											_SCREAMING_SNAKE_CASE			  =    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
											_SCREAMING_SNAKE_CASE			  =    [""" """.join([tokenizer.unk_token]) * seq_length] * batch_size
											_SCREAMING_SNAKE_CASE			  =    dict(tokenizer(_A      ,    return_tensors=_A))
											return common_inputs





				def 		_lowerCAmelCase		(      self							:							Tuple      ,    _A							:							PreTrainedTokenizer      ,    _A							:							int = -1      ,    _A							:							int = -1      ,    _A							:							bool = False      ,    _A							:							Optional[TensorType] = None      ,    ):



											"""simple docstring"""







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



											"""simple docstring"""







											if self.task in ["default", "seq2seq-lm"]:
																		_SCREAMING_SNAKE_CASE			  =    super()._flatten_past_key_values_(_A      ,    _A      ,    _A      ,    _A)
											else:
																		_SCREAMING_SNAKE_CASE			  =    super(_A      ,    self)._flatten_past_key_values_(
																		    _A      ,    _A      ,    _A      ,    _A)



"""simple docstring"""





from __future__ import annotations



def      lowerCamelCase_(__SCREAMING_SNAKE_CASE     ,	__SCREAMING_SNAKE_CASE     ,	__SCREAMING_SNAKE_CASE     ,	)->    tuple:
							if (electron_conc, hole_conc, intrinsic_conc).count(0  ) != 1:
														raise ValueError("""You cannot supply more or less than 2 values"""  )
							elif electron_conc < 0:
														raise ValueError("""Electron concentration cannot be negative in a semiconductor"""  )
							elif hole_conc < 0:
														raise ValueError("""Hole concentration cannot be negative in a semiconductor"""  )
							elif intrinsic_conc < 0:
														raise ValueError(
														    """Intrinsic concentration cannot be negative in a semiconductor"""  )
							elif electron_conc == 0:
														return (
														    "electron_conc",
														    intrinsic_conc**2 / hole_conc,
														)
							elif hole_conc == 0:
														return (
														    "hole_conc",
														    intrinsic_conc**2 / electron_conc,
														)
							elif intrinsic_conc == 0:
														return (
														    "intrinsic_conc",
														    (electron_conc * hole_conc) ** 0.5,
														)
							else:
														return (-1, -1)


if __name__ == "__main__":
			import doctest

			doctest.testmod()


