"""simple docstring"""





import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    MODEL_FOR_PRETRAINING_MAPPING,
			    AlbertForMaskedLM,
			    AlbertForMultipleChoice,
			    AlbertForPreTraining,
			    AlbertForQuestionAnswering,
			    AlbertForSequenceClassification,
			    AlbertForTokenClassification,
			    AlbertModel,
			)
			from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST




class  _snake_case		:







				"""simple docstring"""






				def __init__(      self							:							Any      ,    _A							:							Tuple      ,    _A							:							Optional[int]=1_3      ,    _A							:							Tuple=7      ,    _A							:							int=True      ,    _A							:							Optional[int]=True      ,    _A							:							int=True      ,    _A							:							Optional[int]=True      ,    _A							:							Dict=9_9      ,    _A							:							Any=1_6      ,    _A							:							Any=3_6      ,    _A							:							List[Any]=6      ,    _A							:							Optional[int]=6      ,    _A							:							int=6      ,    _A							:							Dict=3_7      ,    _A							:							List[Any]="gelu"      ,    _A							:							Optional[int]=0.1      ,    _A							:							str=0.1      ,    _A							:							Any=5_1_2      ,    _A							:							Optional[Any]=1_6      ,    _A							:							List[str]=2      ,    _A							:							Tuple=0.02      ,    _A							:							List[Any]=3      ,    _A							:							Any=4      ,    _A							:							List[str]=None      ,    ):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    parent
											_SCREAMING_SNAKE_CASE			  =    batch_size
											_SCREAMING_SNAKE_CASE			  =    seq_length
											_SCREAMING_SNAKE_CASE			  =    is_training
											_SCREAMING_SNAKE_CASE			  =    use_input_mask
											_SCREAMING_SNAKE_CASE			  =    use_token_type_ids
											_SCREAMING_SNAKE_CASE			  =    use_labels
											_SCREAMING_SNAKE_CASE			  =    vocab_size
											_SCREAMING_SNAKE_CASE			  =    embedding_size
											_SCREAMING_SNAKE_CASE			  =    hidden_size
											_SCREAMING_SNAKE_CASE			  =    num_hidden_layers
											_SCREAMING_SNAKE_CASE			  =    num_hidden_groups
											_SCREAMING_SNAKE_CASE			  =    num_attention_heads
											_SCREAMING_SNAKE_CASE			  =    intermediate_size
											_SCREAMING_SNAKE_CASE			  =    hidden_act
											_SCREAMING_SNAKE_CASE			  =    hidden_dropout_prob
											_SCREAMING_SNAKE_CASE			  =    attention_probs_dropout_prob
											_SCREAMING_SNAKE_CASE			  =    max_position_embeddings
											_SCREAMING_SNAKE_CASE			  =    type_vocab_size
											_SCREAMING_SNAKE_CASE			  =    type_sequence_label_size
											_SCREAMING_SNAKE_CASE			  =    initializer_range
											_SCREAMING_SNAKE_CASE			  =    num_labels
											_SCREAMING_SNAKE_CASE			  =    num_choices
											_SCREAMING_SNAKE_CASE			  =    scope





				def 		_lowerCAmelCase		(      self							:							Optional[int]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    ids_tensor([self.batch_size, self.seq_length]      ,    self.vocab_size)

											_SCREAMING_SNAKE_CASE			  =    None
											if self.use_input_mask:
																		_SCREAMING_SNAKE_CASE			  =    random_attention_mask([self.batch_size, self.seq_length])

											_SCREAMING_SNAKE_CASE			  =    None
											if self.use_token_type_ids:
																		_SCREAMING_SNAKE_CASE			  =    ids_tensor([self.batch_size, self.seq_length]      ,    self.type_vocab_size)

											_SCREAMING_SNAKE_CASE			  =    None
											_SCREAMING_SNAKE_CASE			  =    None
											_SCREAMING_SNAKE_CASE			  =    None
											if self.use_labels:
																		_SCREAMING_SNAKE_CASE			  =    ids_tensor([self.batch_size]      ,    self.type_sequence_label_size)
																		_SCREAMING_SNAKE_CASE			  =    ids_tensor([self.batch_size, self.seq_length]      ,    self.num_labels)
																		_SCREAMING_SNAKE_CASE			  =    ids_tensor([self.batch_size]      ,    self.num_choices)

											_SCREAMING_SNAKE_CASE			  =    self.get_config()

											return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels





				def 		_lowerCAmelCase		(      self							:							Dict):



											"""simple docstring"""







											return AlbertConfig(
											    vocab_size=self.vocab_size      ,    hidden_size=self.hidden_size      ,    num_hidden_layers=self.num_hidden_layers      ,    num_attention_heads=self.num_attention_heads      ,    intermediate_size=self.intermediate_size      ,    hidden_act=self.hidden_act      ,    hidden_dropout_prob=self.hidden_dropout_prob      ,    attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,    max_position_embeddings=self.max_position_embeddings      ,    type_vocab_size=self.type_vocab_size      ,    initializer_range=self.initializer_range      ,    num_hidden_groups=self.num_hidden_groups      ,    )





				def 		_lowerCAmelCase		(      self							:							Any      ,    _A							:							str      ,    _A							:							str      ,    _A							:							Optional[Any]      ,    _A							:							int      ,    _A							:							Union[str, Any]      ,    _A							:							Dict      ,    _A							:							Optional[int]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    AlbertModel(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE			  =    model(_A      ,    attention_mask=_A      ,    token_type_ids=_A)
											_SCREAMING_SNAKE_CASE			  =    model(_A      ,    token_type_ids=_A)
											_SCREAMING_SNAKE_CASE			  =    model(_A)
											self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.hidden_size))
											self.parent.assertEqual(result.pooler_output.shape      ,    (self.batch_size, self.hidden_size))





				def 		_lowerCAmelCase		(      self							:							Dict      ,    _A							:							Any      ,    _A							:							Optional[Any]      ,    _A							:							str      ,    _A							:							str      ,    _A							:							Optional[Any]      ,    _A							:							int      ,    _A							:							str):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    AlbertForPreTraining(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE			  =    model(
											    _A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A      ,    sentence_order_label=_A      ,    )
											self.parent.assertEqual(result.prediction_logits.shape      ,    (self.batch_size, self.seq_length, self.vocab_size))
											self.parent.assertEqual(result.sop_logits.shape      ,    (self.batch_size, config.num_labels))





				def 		_lowerCAmelCase		(      self							:							Dict      ,    _A							:							int      ,    _A							:							str      ,    _A							:							Dict      ,    _A							:							Dict      ,    _A							:							Union[str, Any]      ,    _A							:							str      ,    _A							:							Dict):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    AlbertForMaskedLM(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE			  =    model(_A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A)
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.vocab_size))





				def 		_lowerCAmelCase		(      self							:							Tuple      ,    _A							:							Optional[Any]      ,    _A							:							Any      ,    _A							:							Union[str, Any]      ,    _A							:							Optional[Any]      ,    _A							:							Dict      ,    _A							:							List[Any]      ,    _A							:							Dict):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    AlbertForQuestionAnswering(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE			  =    model(
											    _A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    start_positions=_A      ,    end_positions=_A      ,    )
											self.parent.assertEqual(result.start_logits.shape      ,    (self.batch_size, self.seq_length))
											self.parent.assertEqual(result.end_logits.shape      ,    (self.batch_size, self.seq_length))





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]      ,    _A							:							Tuple      ,    _A							:							List[str]      ,    _A							:							List[str]      ,    _A							:							Optional[int]      ,    _A							:							List[Any]      ,    _A							:							Tuple      ,    _A							:							int):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.num_labels
											_SCREAMING_SNAKE_CASE			  =    AlbertForSequenceClassification(_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE			  =    model(_A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A)
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_labels))





				def 		_lowerCAmelCase		(      self							:							Tuple      ,    _A							:							List[Any]      ,    _A							:							int      ,    _A							:							List[Any]      ,    _A							:							List[str]      ,    _A							:							Optional[int]      ,    _A							:							str      ,    _A							:							Tuple):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.num_labels
											_SCREAMING_SNAKE_CASE			  =    AlbertForTokenClassification(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE			  =    model(_A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A)
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.num_labels))





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]      ,    _A							:							int      ,    _A							:							Optional[Any]      ,    _A							:							List[str]      ,    _A							:							List[Any]      ,    _A							:							List[str]      ,    _A							:							List[str]      ,    _A							:							str):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.num_choices
											_SCREAMING_SNAKE_CASE			  =    AlbertForMultipleChoice(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE			  =    input_ids.unsqueeze(1).expand(-1      ,    self.num_choices      ,    -1).contiguous()
											_SCREAMING_SNAKE_CASE			  =    token_type_ids.unsqueeze(1).expand(-1      ,    self.num_choices      ,    -1).contiguous()
											_SCREAMING_SNAKE_CASE			  =    input_mask.unsqueeze(1).expand(-1      ,    self.num_choices      ,    -1).contiguous()
											_SCREAMING_SNAKE_CASE			  =    model(
											    _A      ,    attention_mask=_A      ,    token_type_ids=_A      ,    labels=_A      ,    )
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_choices))





				def 		_lowerCAmelCase		(      self							:							Dict):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.prepare_config_and_inputs()
											(
											    (
											    _SCREAMING_SNAKE_CASE	
											)  ,				(
											    _SCREAMING_SNAKE_CASE	
											)  ,				(
											    _SCREAMING_SNAKE_CASE	
											)  ,				(
											    _SCREAMING_SNAKE_CASE	
											)  ,				(
											    _SCREAMING_SNAKE_CASE	
											)  ,				(
											    _SCREAMING_SNAKE_CASE	
											)  ,				(
											    _SCREAMING_SNAKE_CASE	
											)  ,					
											)			  =    config_and_inputs
											_SCREAMING_SNAKE_CASE			  =    {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
											return config, inputs_dict




@require_torch
class  _snake_case		(    _a   ,       _a   ,       unittest.TestCase ):







				"""simple docstring"""






				a			=						(
				    (
				        AlbertModel,
				        AlbertForPreTraining,
				        AlbertForMaskedLM,
				        AlbertForMultipleChoice,
				        AlbertForSequenceClassification,
				        AlbertForTokenClassification,
				        AlbertForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				a			=						(
				    {
				        "feature-extraction": AlbertModel,
				        "fill-mask": AlbertForMaskedLM,
				        "question-answering": AlbertForQuestionAnswering,
				        "text-classification": AlbertForSequenceClassification,
				        "token-classification": AlbertForTokenClassification,
				        "zero-shot": AlbertForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				a			=						True





				def 		_lowerCAmelCase		(      self							:							Optional[int]      ,    _A							:							int      ,    _A							:							str      ,    _A							:							str=False):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    super()._prepare_for_class(_A      ,    _A      ,    return_labels=_A)

											if return_labels:
																		if model_class in get_values(_A):
																									_SCREAMING_SNAKE_CASE			  =    torch.zeros(
																									    (self.model_tester.batch_size, self.model_tester.seq_length)      ,    dtype=torch.long      ,    device=_A)
																									_SCREAMING_SNAKE_CASE			  =    torch.zeros(
																									    self.model_tester.batch_size      ,    dtype=torch.long      ,    device=_A)
											return inputs_dict





				def 		_lowerCAmelCase		(      self							:							Any):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    AlbertModelTester(self)
											_SCREAMING_SNAKE_CASE			  =    ConfigTester(self      ,    config_class=_A      ,    hidden_size=3_7)





				def 		_lowerCAmelCase		(      self							:							List[Any]):



											"""simple docstring"""







											self.config_tester.run_common_tests()





				def 		_lowerCAmelCase		(      self							:							List[Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*_A)





				def 		_lowerCAmelCase		(      self							:							Tuple):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_pretraining(*_A)





				def 		_lowerCAmelCase		(      self							:							List[str]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*_A)





				def 		_lowerCAmelCase		(      self							:							str):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_multiple_choice(*_A)





				def 		_lowerCAmelCase		(      self							:							List[Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*_A)





				def 		_lowerCAmelCase		(      self							:							Optional[Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*_A)





				def 		_lowerCAmelCase		(      self							:							Tuple):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    self.model_tester.prepare_config_and_inputs()
											for type in ["absolute", "relative_key", "relative_key_query"]:
																		_SCREAMING_SNAKE_CASE			  =    type
																		self.model_tester.create_and_check_model(*_A)





				@slow
				def 		_lowerCAmelCase		(      self							:							Union[str, Any]):



											"""simple docstring"""







											for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		_SCREAMING_SNAKE_CASE			  =    AlbertModel.from_pretrained(_A)
																		self.assertIsNotNone(_A)




@require_torch
class  _snake_case		(    unittest.TestCase ):







				"""simple docstring"""






				@slow
				def 		_lowerCAmelCase		(      self							:							Tuple):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    AlbertModel.from_pretrained("""albert-base-v2""")
											_SCREAMING_SNAKE_CASE			  =    torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]])
											_SCREAMING_SNAKE_CASE			  =    torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
											with torch.no_grad():
																		_SCREAMING_SNAKE_CASE			  =    model(_A      ,    attention_mask=_A)[0]
											_SCREAMING_SNAKE_CASE			  =    torch.Size((1, 1_1, 7_6_8))
											self.assertEqual(output.shape      ,    _A)
											_SCREAMING_SNAKE_CASE			  =    torch.tensor(
											    [[[-0.6_513, 1.5_035, -0.2_766], [-0.6_515, 1.5_046, -0.2_780], [-0.6_512, 1.5_049, -0.2_784]]])

											self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,    _A      ,    atol=1e-4))



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


