




"""simple docstring"""

# This Python program implements an optimal binary search tree (abbreviated BST)
# building dynamic programming algorithm that delivers O(n^2) performance.
#
# The goal of the optimal BST problem is to build a low-cost BST for a
# given set of nodes, each with its own key and frequency. The frequency
# of the node is defined as how many time the node is being searched.
# The search cost of binary search tree is given by this formula:
#
# cost(1, n) = sum{i = 1 to n}((depth(node_i) + 1) * node_i_freq)
#
# where n is number of nodes in the BST. The characteristic of low-cost
# BSTs is having a faster overall search time than other implementations.
# The reason for their fast search time is that the nodes with high
# frequencies will be placed near the root of the tree while the nodes
# with low frequencies will be placed near the leaves of the tree thus
# reducing search time in the most frequent instances.
import sys
from random import randint



class  _snake_case				:

				'''simple docstring'''




				def __init__(							self      :  str					,							snake_case      :  Optional[Any]					,							snake_case      :  str     ):
								UpperCAmelCase_					:Union[str, Any]      			=      key
								UpperCAmelCase_					:str      			=      freq





				def __str__(							self      :  Optional[Any]     ):
								return f'Node(key={self.key}, freq={self.freq})'



def 				a (						__snake_case     :				int,    __snake_case     :				Optional[int],    __snake_case     :				Tuple,    __snake_case     :				Any,    __snake_case     :				Dict,    __snake_case     :				List[str]  ):



				'''simple docstring'''





				if i > j or i < 0 or j > len(__snake_case  ) - 1:
								return

				UpperCAmelCase_					:List[str]      			=      root[i][j]
				if parent == -1:  # root does not have a parent
								print(f'{key[node]} is the root of the binary search tree.'  )
				elif is_left:
								print(f'{key[node]} is the left child of key {parent}.'  )
				else:
								print(f'{key[node]} is the right child of key {parent}.'  )

				print_binary_search_tree(__snake_case,    __snake_case,    __snake_case,    node - 1,    key[node],    __snake_case  )
				print_binary_search_tree(__snake_case,    __snake_case,    node + 1,    __snake_case,    key[node],    __snake_case  )



def 				a (						__snake_case     :				Optional[Any]  ):



				'''simple docstring'''





				nodes.sort(key=lambda __snake_case  : node.key  )

				UpperCAmelCase_					:List[str]      			=      len(__snake_case  )

				UpperCAmelCase_					:Any      			=      [nodes[i].key for i in range(__snake_case  )]
				UpperCAmelCase_					:int      			=      [nodes[i].freq for i in range(__snake_case  )]

				# This 2D array stores the overall tree cost (which's as minimized as possible);
				# for a single key, cost is equal to frequency of the key.
				UpperCAmelCase_					:Dict      			=      [[freqs[i] if i == j else 0 for j in range(__snake_case  )] for i in range(__snake_case  )]
				# sum[i][j] stores the sum of key frequencies between i and j inclusive in nodes
				# array
				UpperCAmelCase_					:Optional[Any]      			=      [[freqs[i] if i == j else 0 for j in range(__snake_case  )] for i in range(__snake_case  )]
				# stores tree roots that will be used later for constructing binary search tree
				UpperCAmelCase_					:int      			=      [[i if i == j else 0 for j in range(__snake_case  )] for i in range(__snake_case  )]

				for interval_length in range(2,    n + 1  ):
								for i in range(n - interval_length + 1  ):
												UpperCAmelCase_					:Union[str, Any]      			=      i + interval_length - 1

												UpperCAmelCase_					:Optional[int]      			=      sys.maxsize  # set the value to "infinity"
												UpperCAmelCase_					:List[Any]      			=      total[i][j - 1] + freqs[j]

												# Apply Knuth's optimization
												# Loop without optimization: for r in range(i, j + 1):
												for r in range(root[i][j - 1],    root[i + 1][j] + 1  ):  # r is a temporal root
																UpperCAmelCase_					:Any      			=      dp[i][r - 1] if r != i else 0  # optimal cost for left subtree
																UpperCAmelCase_					:Optional[int]      			=      dp[r + 1][j] if r != j else 0  # optimal cost for right subtree
																UpperCAmelCase_					:Union[str, Any]      			=      left + total[i][j] + right

																if dp[i][j] > cost:
																				UpperCAmelCase_					:Optional[Any]      			=      cost
																				UpperCAmelCase_					:Optional[int]      			=      r

				print('''Binary search tree nodes:'''  )
				for node in nodes:
								print(__snake_case  )

				print(f'\nThe cost of optimal BST for given tree nodes is {dp[0][n - 1]}.'  )
				print_binary_search_tree(__snake_case,    __snake_case,    0,    n - 1,    -1,    __snake_case  )



def 				a (						):



				'''simple docstring'''





				UpperCAmelCase_					:Union[str, Any]      			=      [Node(__snake_case,    randint(1,    50  )  ) for i in range(10,    0,    -1  )]
				find_optimal_binary_search_tree(__snake_case  )


if __name__ == "__main__":
						main()








"""simple docstring"""

import unittest

from transformers import ElectraConfig, 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, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    MODEL_FOR_PRETRAINING_MAPPING,
						    ElectraForCausalLM,
						    ElectraForMaskedLM,
						    ElectraForMultipleChoice,
						    ElectraForPreTraining,
						    ElectraForQuestionAnswering,
						    ElectraForSequenceClassification,
						    ElectraForTokenClassification,
						    ElectraModel,
						)
						from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST



class  _snake_case				:

				'''simple docstring'''




				def __init__(							self      :  List[str]					,							snake_case      :  Dict					,							snake_case      :  Optional[Any]=13					,							snake_case      :  Dict=7					,							snake_case      :  int=True					,							snake_case      :  Union[str, Any]=True					,							snake_case      :  Dict=True					,							snake_case      :  str=True					,							snake_case      :  Any=99					,							snake_case      :  Any=32					,							snake_case      :  Any=5					,							snake_case      :  List[Any]=4					,							snake_case      :  Tuple=37					,							snake_case      :  Optional[Any]="gelu"					,							snake_case      :  int=0.1					,							snake_case      :  Dict=0.1					,							snake_case      :  Tuple=512					,							snake_case      :  int=16					,							snake_case      :  str=2					,							snake_case      :  Optional[Any]=0.02					,							snake_case      :  List[Any]=3					,							snake_case      :  Dict=4					,							snake_case      :  Union[str, Any]=None					,							):
								UpperCAmelCase_					:List[Any]      			=      parent
								UpperCAmelCase_					:Any      			=      batch_size
								UpperCAmelCase_					:List[str]      			=      seq_length
								UpperCAmelCase_					:Optional[Any]      			=      is_training
								UpperCAmelCase_					:Tuple      			=      use_input_mask
								UpperCAmelCase_					:Any      			=      use_token_type_ids
								UpperCAmelCase_					:Dict      			=      use_labels
								UpperCAmelCase_					:Tuple      			=      vocab_size
								UpperCAmelCase_					:Optional[Any]      			=      hidden_size
								UpperCAmelCase_					:Optional[int]      			=      num_hidden_layers
								UpperCAmelCase_					:str      			=      num_attention_heads
								UpperCAmelCase_					:List[str]      			=      intermediate_size
								UpperCAmelCase_					:Any      			=      hidden_act
								UpperCAmelCase_					:Dict      			=      hidden_dropout_prob
								UpperCAmelCase_					:Optional[int]      			=      attention_probs_dropout_prob
								UpperCAmelCase_					:Dict      			=      max_position_embeddings
								UpperCAmelCase_					:Dict      			=      type_vocab_size
								UpperCAmelCase_					:Any      			=      type_sequence_label_size
								UpperCAmelCase_					:Optional[Any]      			=      initializer_range
								UpperCAmelCase_					:str      			=      num_labels
								UpperCAmelCase_					:Any      			=      num_choices
								UpperCAmelCase_					:str      			=      scope





				def 				snake_case_ (							self      :  Tuple     ):
								UpperCAmelCase_					:str      			=      ids_tensor([self.batch_size, self.seq_length]					,							self.vocab_size     )

								UpperCAmelCase_					:Optional[int]      			=      None
								if self.use_input_mask:
												UpperCAmelCase_					:Any      			=      random_attention_mask([self.batch_size, self.seq_length]     )

								UpperCAmelCase_					:Optional[Any]      			=      None
								if self.use_token_type_ids:
												UpperCAmelCase_					:Dict      			=      ids_tensor([self.batch_size, self.seq_length]					,							self.type_vocab_size     )

								UpperCAmelCase_					:str      			=      None
								UpperCAmelCase_					:Dict      			=      None
								UpperCAmelCase_					:str      			=      None
								if self.use_labels:
												UpperCAmelCase_					:str      			=      ids_tensor([self.batch_size]					,							self.type_sequence_label_size     )
												UpperCAmelCase_					:List[Any]      			=      ids_tensor([self.batch_size, self.seq_length]					,							self.num_labels     )
												UpperCAmelCase_					:Tuple      			=      ids_tensor([self.batch_size]					,							self.num_choices     )
												UpperCAmelCase_					:Dict      			=      ids_tensor([self.batch_size, self.seq_length]					,							1     )

								UpperCAmelCase_					:Dict      			=      self.get_config()

								return (
								    config,
								    input_ids,
								    token_type_ids,
								    input_mask,
								    sequence_labels,
								    token_labels,
								    choice_labels,
								    fake_token_labels,
								)





				def 				snake_case_ (							self      :  str     ):
								return ElectraConfig(
								    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					,							is_decoder=snake_case					,							initializer_range=self.initializer_range					,							)





				def 				snake_case_ (							self      :  List[Any]     ):
								(
								    (
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,
								)					:str      			=      self.prepare_config_and_inputs()

								UpperCAmelCase_					:Union[str, Any]      			=      True
								UpperCAmelCase_					:Any      			=      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
								UpperCAmelCase_					:str      			=      ids_tensor([self.batch_size, self.seq_length]					,							vocab_size=2     )

								return (
								    config,
								    input_ids,
								    token_type_ids,
								    input_mask,
								    sequence_labels,
								    token_labels,
								    choice_labels,
								    encoder_hidden_states,
								    encoder_attention_mask,
								)





				def 				snake_case_ (							self      :  Union[str, Any]					,							snake_case      :  Tuple					,							snake_case      :  Tuple					,							snake_case      :  List[str]					,							snake_case      :  int					,							snake_case      :  str					,							snake_case      :  Dict					,							snake_case      :  Any					,							snake_case      :  Union[str, Any]					,							):
								UpperCAmelCase_					:str      			=      ElectraModel(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:Dict      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case     )
								UpperCAmelCase_					:Tuple      			=      model(snake_case					,							token_type_ids=snake_case     )
								UpperCAmelCase_					:List[str]      			=      model(snake_case     )
								self.parent.assertEqual(result.last_hidden_state.shape					,							(self.batch_size, self.seq_length, self.hidden_size)     )





				def 				snake_case_ (							self      :  int					,							snake_case      :  Any					,							snake_case      :  Optional[Any]					,							snake_case      :  List[Any]					,							snake_case      :  Union[str, Any]					,							snake_case      :  Optional[Any]					,							snake_case      :  Optional[Any]					,							snake_case      :  List[Any]					,							snake_case      :  str					,							snake_case      :  Any					,							):
								UpperCAmelCase_					:Union[str, Any]      			=      True
								UpperCAmelCase_					:Optional[int]      			=      ElectraModel(snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:int      			=      model(
								    snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							encoder_hidden_states=snake_case					,							encoder_attention_mask=snake_case					,							)
								UpperCAmelCase_					:int      			=      model(
								    snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							encoder_hidden_states=snake_case					,							)
								UpperCAmelCase_					:List[str]      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case     )
								self.parent.assertEqual(result.last_hidden_state.shape					,							(self.batch_size, self.seq_length, self.hidden_size)     )





				def 				snake_case_ (							self      :  str					,							snake_case      :  Any					,							snake_case      :  Dict					,							snake_case      :  Optional[int]					,							snake_case      :  Optional[int]					,							snake_case      :  int					,							snake_case      :  List[str]					,							snake_case      :  List[Any]					,							snake_case      :  List[str]					,							):
								UpperCAmelCase_					:Tuple      			=      ElectraForMaskedLM(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:str      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length, self.vocab_size)     )





				def 				snake_case_ (							self      :  List[str]					,							snake_case      :  Dict					,							snake_case      :  Union[str, Any]					,							snake_case      :  Union[str, Any]					,							snake_case      :  Optional[Any]					,							snake_case      :  List[str]					,							snake_case      :  Optional[int]					,							snake_case      :  Union[str, Any]					,							snake_case      :  int					,							snake_case      :  Tuple					,							):
								UpperCAmelCase_					:str      			=      ElectraForCausalLM(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:Optional[Any]      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length, self.vocab_size)     )





				def 				snake_case_ (							self      :  int					,							snake_case      :  List[Any]					,							snake_case      :  List[str]					,							snake_case      :  Dict					,							snake_case      :  Optional[Any]					,							snake_case      :  Union[str, Any]					,							snake_case      :  Optional[Any]					,							snake_case      :  List[Any]					,							snake_case      :  List[str]					,							):
								UpperCAmelCase_					:Union[str, Any]      			=      self.num_labels
								UpperCAmelCase_					:Optional[int]      			=      ElectraForTokenClassification(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:List[str]      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length, self.num_labels)     )





				def 				snake_case_ (							self      :  Tuple					,							snake_case      :  Tuple					,							snake_case      :  int					,							snake_case      :  int					,							snake_case      :  Optional[Any]					,							snake_case      :  Optional[int]					,							snake_case      :  Union[str, Any]					,							snake_case      :  List[str]					,							snake_case      :  List[Any]					,							):
								UpperCAmelCase_					:List[str]      			=      self.num_labels
								UpperCAmelCase_					:Union[str, Any]      			=      ElectraForPreTraining(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:int      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length)     )





				def 				snake_case_ (							self      :  Dict					,							snake_case      :  Any					,							snake_case      :  List[Any]					,							snake_case      :  Optional[int]					,							snake_case      :  Optional[Any]					,							snake_case      :  Optional[int]					,							snake_case      :  Dict					,							snake_case      :  int					,							snake_case      :  int					,							):
								UpperCAmelCase_					:Optional[Any]      			=      self.num_labels
								UpperCAmelCase_					:Optional[int]      			=      ElectraForSequenceClassification(snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:Any      			=      model(snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case     )
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.num_labels)     )





				def 				snake_case_ (							self      :  Optional[int]					,							snake_case      :  Union[str, Any]					,							snake_case      :  List[str]					,							snake_case      :  Optional[int]					,							snake_case      :  List[Any]					,							snake_case      :  List[str]					,							snake_case      :  str					,							snake_case      :  str					,							snake_case      :  List[Any]					,							):
								UpperCAmelCase_					:Union[str, Any]      			=      ElectraForQuestionAnswering(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:Optional[Any]      			=      model(
								    snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							start_positions=snake_case					,							end_positions=snake_case					,							)
								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 				snake_case_ (							self      :  Union[str, Any]					,							snake_case      :  Optional[int]					,							snake_case      :  List[str]					,							snake_case      :  str					,							snake_case      :  Any					,							snake_case      :  str					,							snake_case      :  Optional[int]					,							snake_case      :  Optional[int]					,							snake_case      :  Optional[int]					,							):
								UpperCAmelCase_					:Union[str, Any]      			=      self.num_choices
								UpperCAmelCase_					:Dict      			=      ElectraForMultipleChoice(config=snake_case     )
								model.to(snake_case     )
								model.eval()
								UpperCAmelCase_					:List[Any]      			=      input_ids.unsqueeze(1     ).expand(-1					,							self.num_choices					,							-1     ).contiguous()
								UpperCAmelCase_					:Dict      			=      token_type_ids.unsqueeze(1     ).expand(-1					,							self.num_choices					,							-1     ).contiguous()
								UpperCAmelCase_					:int      			=      input_mask.unsqueeze(1     ).expand(-1					,							self.num_choices					,							-1     ).contiguous()
								UpperCAmelCase_					:Optional[int]      			=      model(
								    snake_case					,							attention_mask=snake_case					,							token_type_ids=snake_case					,							labels=snake_case					,							)
								self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.num_choices)     )





				def 				snake_case_ (							self      :  Any     ):
								UpperCAmelCase_					:List[Any]      			=      self.prepare_config_and_inputs()
								(
								    (
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,(
								    UpperCAmelCase_
								)			,
								)					:List[str]      			=      config_and_inputs
								UpperCAmelCase_					:Dict      			=      {'''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'''




				UpperCamelCase__		     =(
				    (
				        ElectraModel,
				        ElectraForPreTraining,
				        ElectraForMaskedLM,
				        ElectraForCausalLM,
				        ElectraForMultipleChoice,
				        ElectraForTokenClassification,
				        ElectraForSequenceClassification,
				        ElectraForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				UpperCamelCase__		     =(
				    {
				        """feature-extraction""": ElectraModel,
				        """fill-mask""": ElectraForMaskedLM,
				        """question-answering""": ElectraForQuestionAnswering,
				        """text-classification""": ElectraForSequenceClassification,
				        """text-generation""": ElectraForCausalLM,
				        """token-classification""": ElectraForTokenClassification,
				        """zero-shot""": ElectraForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				UpperCamelCase__		     =True





				def 				snake_case_ (							self      :  List[str]					,							snake_case      :  List[str]					,							snake_case      :  Tuple					,							snake_case      :  List[Any]=False     ):
								UpperCAmelCase_					:Optional[int]      			=      super()._prepare_for_class(snake_case					,							snake_case					,							return_labels=snake_case     )

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





				def 				snake_case_ (							self      :  Optional[int]     ):
								UpperCAmelCase_					:int      			=      ElectraModelTester(self     )
								UpperCAmelCase_					:List[str]      			=      ConfigTester(self					,							config_class=snake_case					,							hidden_size=37     )





				def 				snake_case_ (							self      :  List[Any]     ):
								self.config_tester.run_common_tests()





				def 				snake_case_ (							self      :  List[Any]     ):
								UpperCAmelCase_					:Union[str, Any]      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_model(*snake_case     )





				def 				snake_case_ (							self      :  List[str]     ):
								UpperCAmelCase_					:str      			=      self.model_tester.prepare_config_and_inputs_for_decoder()
								self.model_tester.create_and_check_electra_model_as_decoder(*snake_case     )





				def 				snake_case_ (							self      :  Union[str, Any]     ):
								UpperCAmelCase_					:Dict      			=      self.model_tester.prepare_config_and_inputs()
								for type in ["absolute", "relative_key", "relative_key_query"]:
												UpperCAmelCase_					:Dict      			=      type
												self.model_tester.create_and_check_electra_model(*snake_case     )





				def 				snake_case_ (							self      :  str     ):
								UpperCAmelCase_					:Dict      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_masked_lm(*snake_case     )





				def 				snake_case_ (							self      :  Tuple     ):
								UpperCAmelCase_					:Dict      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_token_classification(*snake_case     )





				def 				snake_case_ (							self      :  Optional[int]     ):
								UpperCAmelCase_					:Optional[int]      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_pretraining(*snake_case     )





				def 				snake_case_ (							self      :  Dict     ):
								UpperCAmelCase_					:Any      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_sequence_classification(*snake_case     )





				def 				snake_case_ (							self      :  List[Any]     ):
								UpperCAmelCase_					:Union[str, Any]      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_question_answering(*snake_case     )





				def 				snake_case_ (							self      :  Any     ):
								UpperCAmelCase_					:int      			=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_electra_for_multiple_choice(*snake_case     )





				@slow
				def 				snake_case_ (							self      :  Dict     ):
								for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCAmelCase_					:Optional[int]      			=      ElectraModel.from_pretrained(snake_case     )
												self.assertIsNotNone(snake_case     )





				def 				snake_case_ (							self      :  Any     ):
								UpperCAmelCase_					:Any      			=      self.model_tester.prepare_config_and_inputs_for_decoder()
								self.model_tester.create_and_check_electra_for_causal_lm(*snake_case     )



@require_torch
class  _snake_case				(							unittest.TestCase       ):

				'''simple docstring'''




				@slow
				def 				snake_case_ (							self      :  List[Any]     ):
								UpperCAmelCase_					:Optional[int]      			=      ElectraModel.from_pretrained('''google/electra-small-discriminator'''     )
								UpperCAmelCase_					:Dict      			=      torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]     )
								UpperCAmelCase_					:int      			=      torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
								UpperCAmelCase_					:Optional[int]      			=      model(snake_case					,							attention_mask=snake_case     )[0]
								UpperCAmelCase_					:Optional[Any]      			=      torch.Size((1, 11, 256)     )
								self.assertEqual(output.shape					,							snake_case     )
								UpperCAmelCase_					:Optional[int]      			=      torch.tensor(
								    [[[0.4_471, 0.6_821, -0.3_265], [0.4_627, 0.5_255, -0.3_668], [0.4_532, 0.3_313, -0.4_344]]]     )

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


