
'''simple docstring'''



import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
						import jax.numpy as jnp

						from transformers.models.albert.modeling_flax_albert import (
						    FlaxAlbertForMaskedLM,
						    FlaxAlbertForMultipleChoice,
						    FlaxAlbertForPreTraining,
						    FlaxAlbertForQuestionAnswering,
						    FlaxAlbertForSequenceClassification,
						    FlaxAlbertForTokenClassification,
						    FlaxAlbertModel,
						)




class     UpperCAmelCase_	(						unittest.TestCase					):






						'''simple docstring'''






						def __init__(   self       ,  _lowercase       ,  _lowercase=13       ,  _lowercase=7       ,  _lowercase=True       ,  _lowercase=True       ,  _lowercase=True       ,  _lowercase=True       ,  _lowercase=99       ,  _lowercase=32       ,  _lowercase=5       ,  _lowercase=4       ,  _lowercase=37       ,  _lowercase="gelu"       ,  _lowercase=0.1       ,  _lowercase=0.1       ,  _lowercase=512       ,  _lowercase=16       ,  _lowercase=2       ,  _lowercase=0.02       ,  _lowercase=4       ,  ):

												"""simple docstring"""



												_lowerCAmelCase    		=					parent
												_lowerCAmelCase    		=					batch_size
												_lowerCAmelCase    		=					seq_length
												_lowerCAmelCase    		=					is_training
												_lowerCAmelCase    		=					use_attention_mask
												_lowerCAmelCase    		=					use_token_type_ids
												_lowerCAmelCase    		=					use_labels
												_lowerCAmelCase    		=					vocab_size
												_lowerCAmelCase    		=					hidden_size
												_lowerCAmelCase    		=					num_hidden_layers
												_lowerCAmelCase    		=					num_attention_heads
												_lowerCAmelCase    		=					intermediate_size
												_lowerCAmelCase    		=					hidden_act
												_lowerCAmelCase    		=					hidden_dropout_prob
												_lowerCAmelCase    		=					attention_probs_dropout_prob
												_lowerCAmelCase    		=					max_position_embeddings
												_lowerCAmelCase    		=					type_vocab_size
												_lowerCAmelCase    		=					type_sequence_label_size
												_lowerCAmelCase    		=					initializer_range
												_lowerCAmelCase    		=					num_choices




						def    _lowercase      (   self ):

												"""simple docstring"""



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

												_lowerCAmelCase    		=					None
												if self.use_attention_mask:
																		_lowerCAmelCase    		=					random_attention_mask([self.batch_size, self.seq_length] )

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

												_lowerCAmelCase    		=					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       ,  is_decoder=_lowercase       ,  initializer_range=self.initializer_range       ,  )

												return config, input_ids, token_type_ids, attention_mask




						def    _lowercase      (   self ):

												"""simple docstring"""



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






@require_flax
class     UpperCAmelCase_	(						_SCREAMING_SNAKE_CASE			,				unittest.TestCase					):






						'''simple docstring'''






						_lowercase						: Union[str, Any]										=  (
						    (
						        FlaxAlbertModel,
						        FlaxAlbertForPreTraining,
						        FlaxAlbertForMaskedLM,
						        FlaxAlbertForMultipleChoice,
						        FlaxAlbertForQuestionAnswering,
						        FlaxAlbertForSequenceClassification,
						        FlaxAlbertForTokenClassification,
						        FlaxAlbertForQuestionAnswering,
						    )
						    if is_flax_available()
						    else ()
						)




						def    _lowercase      (   self ):

												"""simple docstring"""



												_lowerCAmelCase    		=					FlaxAlbertModelTester(self )




						@slow
						def    _lowercase      (   self ):

												"""simple docstring"""



												for model_class_name in self.all_model_classes:
																		_lowerCAmelCase    		=					model_class_name.from_pretrained("""albert-base-v2""" )
																		_lowerCAmelCase    		=					model(np.ones((1, 1) ) )
																		self.assertIsNotNone(_lowercase )






@require_flax
class     UpperCAmelCase_	(						unittest.TestCase					):






						'''simple docstring'''






						@slow
						def    _lowercase      (   self ):

												"""simple docstring"""



												_lowerCAmelCase    		=					FlaxAlbertModel.from_pretrained("""albert-base-v2""" )
												_lowerCAmelCase    		=					np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]] )
												_lowerCAmelCase    		=					np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
												_lowerCAmelCase    		=					model(_lowercase       ,  attention_mask=_lowercase )[0]
												_lowerCAmelCase    		=					(1, 11, 768)
												self.assertEqual(output.shape       ,  _lowercase )
												_lowerCAmelCase    		=					np.array(
												    [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]] )

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


'''simple docstring'''



import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


_lowercase          =						False
try:
						_lowercase          =						_is_package_available("""google.colab""")
except ModuleNotFoundError:
						pass




@input.register
class     UpperCAmelCase_	:






						'''simple docstring'''






						def __init__(   self       ,  _lowercase = None       ,  _lowercase = [] ):

												"""simple docstring"""



												_lowerCAmelCase    		=					0
												_lowerCAmelCase    		=					choices
												_lowerCAmelCase    		=					prompt
												if sys.platform == "win32":
																		_lowerCAmelCase    		=					"""*"""
												else:
																		_lowerCAmelCase    		=					"""➔ """




						def    _lowercase      (   self       ,  _lowercase       ,  _lowercase = "" ):

												"""simple docstring"""



												if sys.platform != "win32":
																		writeColor(self.choices[index]       ,  32       ,  _lowercase )
												else:
																		forceWrite(self.choices[index]       ,  _lowercase )




						def    _lowercase      (   self       ,  _lowercase ):

												"""simple docstring"""



												if index == self.position:
																		forceWrite(F' {self.arrow_char} ' )
																		self.write_choice(_lowercase )
												else:
																		forceWrite(F'    {self.choices[index]}' )
												reset_cursor()




						def    _lowercase      (   self       ,  _lowercase       ,  _lowercase = 1 ):

												"""simple docstring"""



												_lowerCAmelCase    		=					self.position
												if direction == Direction.DOWN:
																		if self.position + 1 >= len(self.choices ):
																								return
																		self.position += num_spaces
												else:
																		if self.position - 1 < 0:
																								return
																		self.position -= num_spaces
												clear_line()
												self.print_choice(_lowercase )
												move_cursor(_lowercase       ,  direction.name )
												self.print_choice(self.position )




						@input.mark(KEYMAP["""up"""] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												self.move_direction(Direction.UP )




						@input.mark(KEYMAP["""down"""] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												self.move_direction(Direction.DOWN )




						@input.mark(KEYMAP["""newline"""] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												move_cursor(len(self.choices ) - self.position       ,  """DOWN""" )
												return self.position




						@input.mark(KEYMAP["""interrupt"""] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												move_cursor(len(self.choices ) - self.position       ,  """DOWN""" )
												raise KeyboardInterrupt




						@input.mark_multiple(*[KEYMAP[str(_lowercase )] for number in range(10 )] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												_lowerCAmelCase    		=					int(chr(self.current_selection ) )
												_lowerCAmelCase    		=					index - self.position
												if index == self.position:
																		return
												if index < len(self.choices ):
																		if self.position > index:
																								self.move_direction(Direction.UP       ,  -movement )
																		elif self.position < index:
																								self.move_direction(Direction.DOWN       ,  _lowercase )
																		else:
																								return
												else:
																		return




						def    _lowercase      (   self       ,  _lowercase = 0 ):

												"""simple docstring"""



												if self.prompt:
																		linebreak()
																		forceWrite(self.prompt       ,  """\n""" )
																		if in_colab:
																								forceWrite("""Please input a choice index (starting from 0), and press enter"""       ,  """\n""" )
																		else:
																								forceWrite("""Please select a choice using the arrow or number keys, and selecting with enter"""       ,  """\n""" )
												_lowerCAmelCase    		=					default_choice
												for i in range(len(self.choices ) ):
																		self.print_choice(_lowercase )
																		forceWrite("""\n""" )
												move_cursor(len(self.choices ) - self.position       ,  """UP""" )
												with cursor.hide():
																		while True:
																								if in_colab:
																														try:
																																				_lowerCAmelCase    		=					int(builtins.input() )
																														except ValueError:
																																				_lowerCAmelCase    		=					default_choice
																								else:
																														_lowerCAmelCase    		=					self.handle_input()
																								if choice is not None:
																														reset_cursor()
																														for _ in range(len(self.choices ) + 1 ):
																																				move_cursor(1       ,  """UP""" )
																																				clear_line()
																														self.write_choice(_lowercase       ,  """\n""" )
																														return choice
