

"""simple docstring"""





from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import tensorflow as tf

				from transformers import TF_MODEL_FOR_PRETRAINING_MAPPING
				from transformers.models.albert.modeling_tf_albert import (
				    TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFAlbertForMaskedLM,
				    TFAlbertForMultipleChoice,
				    TFAlbertForPreTraining,
				    TFAlbertForQuestionAnswering,
				    TFAlbertForSequenceClassification,
				    TFAlbertForTokenClassification,
				    TFAlbertModel,
				)

class     __a   :

			"""simple docstring"""

			def __init__(							self     :					int						,  lowercase_     :					int						,  lowercase_     :					str=13						,  lowercase_     :					Any=7						,  lowercase_     :					Optional[int]=True						,  lowercase_     :					List[str]=True						,  lowercase_     :					int=True						,  lowercase_     :					Union[str, Any]=True						,  lowercase_     :					Dict=99						,  lowercase_     :					str=16						,  lowercase_     :					Optional[Any]=32						,  lowercase_     :					List[Any]=2						,  lowercase_     :					Union[str, Any]=4						,  lowercase_     :					List[Any]=37						,  lowercase_     :					str="gelu"						,  lowercase_     :					Union[str, Any]=0.1						,  lowercase_     :					List[Any]=0.1						,  lowercase_     :					int=512						,  lowercase_     :					List[Any]=16						,  lowercase_     :					Optional[Any]=2						,  lowercase_     :					int=0.0_2						,  lowercase_     :					Optional[int]=3						,  lowercase_     :					Dict=4						,  lowercase_     :					Dict=None						,  ):
								UpperCamelCase__		:    str         =parent
								UpperCamelCase__		:    List[str]         =13
								UpperCamelCase__		:    List[Any]         =7
								UpperCamelCase__		:    Tuple         =True
								UpperCamelCase__		:    Optional[Any]         =True
								UpperCamelCase__		:    Union[str, Any]         =True
								UpperCamelCase__		:    List[Any]         =True
								UpperCamelCase__		:    Optional[int]         =99
								UpperCamelCase__		:    List[str]         =16
								UpperCamelCase__		:    List[Any]         =32
								UpperCamelCase__		:    Optional[Any]         =2
								UpperCamelCase__		:    Dict         =4
								UpperCamelCase__		:    Optional[int]         =37
								UpperCamelCase__		:    int         ='''gelu'''
								UpperCamelCase__		:    Optional[Any]         =0.1
								UpperCamelCase__		:    str         =0.1
								UpperCamelCase__		:    Tuple         =512
								UpperCamelCase__		:    List[str]         =16
								UpperCamelCase__		:    Optional[int]         =2
								UpperCamelCase__		:    Any         =0.0_2
								UpperCamelCase__		:    str         =3
								UpperCamelCase__		:    List[str]         =4
								UpperCamelCase__		:    Optional[int]         =None






			def    _lowerCAmelCase			(							self     :					Dict						):
								UpperCamelCase__		:    Tuple         =ids_tensor([self.batch_size, self.seq_length]						,  self.vocab_size						)

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

								UpperCamelCase__		:    Optional[int]         =None
								if self.use_token_type_ids:
													UpperCamelCase__		:    List[Any]         =ids_tensor([self.batch_size, self.seq_length]						,  self.type_vocab_size						)

								UpperCamelCase__		:    Optional[int]         =None
								UpperCamelCase__		:    str         =None
								UpperCamelCase__		:    Dict         =None
								if self.use_labels:
													UpperCamelCase__		:    List[Any]         =ids_tensor([self.batch_size]						,  self.type_sequence_label_size						)
													UpperCamelCase__		:    Union[str, Any]         =ids_tensor([self.batch_size, self.seq_length]						,  self.num_labels						)
													UpperCamelCase__		:    int         =ids_tensor([self.batch_size]						,  self.num_choices						)

								UpperCamelCase__		:    Tuple         =AlbertConfig(
								    vocab_size=self.vocab_size						,  hidden_size=self.hidden_size						,  embedding_size=self.embedding_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						,  )

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






			def    _lowerCAmelCase			(							self     :					List[Any]						,  lowercase_     :					List[Any]						,  lowercase_     :					Optional[int]						,  lowercase_     :					List[Any]						,  lowercase_     :					Union[str, Any]						,  lowercase_     :					Optional[int]						,  lowercase_     :					Any						,  lowercase_     :					Dict						):
								UpperCamelCase__		:    Tuple         =TFAlbertModel(config=lowercase_						)
								# inputs = {'input_ids': input_ids,
								#           'attention_mask': input_mask,
								#           'token_type_ids': token_type_ids}
								# sequence_output, pooled_output = model(**inputs)
								UpperCamelCase__		:    Tuple         ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								UpperCamelCase__		:    List[str]         =model(lowercase_						)

								UpperCamelCase__		:    Optional[Any]         =[input_ids, input_mask]
								UpperCamelCase__		:    Union[str, Any]         =model(lowercase_						)

								UpperCamelCase__		:    Optional[int]         =model(lowercase_						)

								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     :					List[str]						,  lowercase_     :					Tuple						,  lowercase_     :					int						,  lowercase_     :					Dict						,  lowercase_     :					Union[str, Any]						,  lowercase_     :					Optional[Any]						,  lowercase_     :					int						,  lowercase_     :					Dict						):
								UpperCamelCase__		:    int         =self.num_labels
								UpperCamelCase__		:    Tuple         =TFAlbertForPreTraining(config=lowercase_						)
								UpperCamelCase__		:    Optional[Any]         ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								UpperCamelCase__		:    List[Any]         =model(lowercase_						)
								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, self.num_labels)						)






			def    _lowerCAmelCase			(							self     :					str						,  lowercase_     :					Optional[int]						,  lowercase_     :					Optional[int]						,  lowercase_     :					List[str]						,  lowercase_     :					List[Any]						,  lowercase_     :					List[str]						,  lowercase_     :					Tuple						,  lowercase_     :					Optional[int]						):
								UpperCamelCase__		:    Union[str, Any]         =TFAlbertForMaskedLM(config=lowercase_						)
								UpperCamelCase__		:    Tuple         ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								UpperCamelCase__		:    Dict         =model(lowercase_						)
								self.parent.assertEqual(result.logits.shape						,  (self.batch_size, self.seq_length, self.vocab_size)						)






			def    _lowerCAmelCase			(							self     :					Optional[int]						,  lowercase_     :					List[str]						,  lowercase_     :					Union[str, Any]						,  lowercase_     :					Optional[int]						,  lowercase_     :					List[str]						,  lowercase_     :					Optional[int]						,  lowercase_     :					Optional[int]						,  lowercase_     :					Tuple						):
								UpperCamelCase__		:    str         =self.num_labels
								UpperCamelCase__		:    int         =TFAlbertForSequenceClassification(config=lowercase_						)
								UpperCamelCase__		:    List[Any]         ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								UpperCamelCase__		:    Any         =model(lowercase_						)
								self.parent.assertEqual(result.logits.shape						,  (self.batch_size, self.num_labels)						)






			def    _lowerCAmelCase			(							self     :					Dict						,  lowercase_     :					Optional[Any]						,  lowercase_     :					Dict						,  lowercase_     :					List[Any]						,  lowercase_     :					Optional[int]						,  lowercase_     :					List[Any]						,  lowercase_     :					Any						,  lowercase_     :					str						):
								UpperCamelCase__		:    List[Any]         =TFAlbertForQuestionAnswering(config=lowercase_						)
								UpperCamelCase__		:    Any         ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								UpperCamelCase__		:    List[Any]         =model(lowercase_						)
								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     :					List[str]						,  lowercase_     :					Tuple						,  lowercase_     :					Union[str, Any]						,  lowercase_     :					Optional[int]						,  lowercase_     :					Optional[Any]						,  lowercase_     :					List[str]						,  lowercase_     :					Dict						,  lowercase_     :					Any						):
								UpperCamelCase__		:    Dict         =self.num_choices
								UpperCamelCase__		:    List[str]         =TFAlbertForMultipleChoice(config=lowercase_						)
								UpperCamelCase__		:    Any         =tf.tile(tf.expand_dims(lowercase_						,  1						)						,  (1, self.num_choices, 1)						)
								UpperCamelCase__		:    Optional[int]         =tf.tile(tf.expand_dims(lowercase_						,  1						)						,  (1, self.num_choices, 1)						)
								UpperCamelCase__		:    Tuple         =tf.tile(tf.expand_dims(lowercase_						,  1						)						,  (1, self.num_choices, 1)						)
								UpperCamelCase__		:    Any         ={
								    '''input_ids''': multiple_choice_inputs_ids,
								    '''attention_mask''': multiple_choice_input_mask,
								    '''token_type_ids''': multiple_choice_token_type_ids,
								}
								UpperCamelCase__		:    Dict         =model(lowercase_						)
								self.parent.assertListEqual(list(result['''logits'''].shape						)						,  [self.batch_size, self.num_choices]						)






			def    _lowerCAmelCase			(							self     :					Optional[int]						,  lowercase_     :					int						,  lowercase_     :					Any						,  lowercase_     :					Optional[int]						,  lowercase_     :					int						,  lowercase_     :					List[str]						,  lowercase_     :					Dict						,  lowercase_     :					Optional[Any]						):
								UpperCamelCase__		:    str         =self.num_labels
								UpperCamelCase__		:    Union[str, Any]         =TFAlbertForTokenClassification(config=lowercase_						)
								UpperCamelCase__		:    List[str]         ={
								    '''input_ids''': input_ids,
								    '''attention_mask''': input_mask,
								    '''token_type_ids''': token_type_ids,
								}
								UpperCamelCase__		:    int         =model(lowercase_						)
								self.parent.assertListEqual(list(result['''logits'''].shape						)						,  [self.batch_size, self.seq_length, self.num_labels]						)






			def    _lowerCAmelCase			(							self     :					Tuple						):
								UpperCamelCase__		:    Any         =self.prepare_config_and_inputs()
								(
								    (
								    UpperCamelCase__
								)  ,			(
								    UpperCamelCase__
								)  ,			(
								    UpperCamelCase__
								)  ,			(
								    UpperCamelCase__
								)  ,			(
								    UpperCamelCase__
								)  ,			(
								    UpperCamelCase__
								)  ,			(
								    UpperCamelCase__
								)  ,			
								)		:    Union[str, Any]         =config_and_inputs
								UpperCamelCase__		:    Tuple         ={'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict



@require_tf
class     __a   (      snake_case__,    snake_case__,    unittest.TestCase    ):

			"""simple docstring"""

			SCREAMING_SNAKE_CASE_						     =						(
			    (
			        TFAlbertModel,
			        TFAlbertForPreTraining,
			        TFAlbertForMaskedLM,
			        TFAlbertForSequenceClassification,
			        TFAlbertForQuestionAnswering,
			        TFAlbertForTokenClassification,
			        TFAlbertForMultipleChoice,
			    )
			    if is_tf_available()
			    else ()
			)
			SCREAMING_SNAKE_CASE_						     =						(
			    {
			        'feature-extraction': TFAlbertModel,
			        'fill-mask': TFAlbertForMaskedLM,
			        'question-answering': TFAlbertForQuestionAnswering,
			        'text-classification': TFAlbertForSequenceClassification,
			        'token-classification': TFAlbertForTokenClassification,
			        'zero-shot': TFAlbertForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			SCREAMING_SNAKE_CASE_						     =						False
			SCREAMING_SNAKE_CASE_						     =						False






			def    _lowerCAmelCase			(							self     :					Dict						,  lowercase_     :					Union[str, Any]						,  lowercase_     :					Optional[Any]						,  lowercase_     :					Any=False						):
								UpperCamelCase__		:    Optional[Any]         =super()._prepare_for_class(lowercase_						,  lowercase_						,  return_labels=lowercase_						)

								if return_labels:
													if model_class in get_values(lowercase_						):
																		UpperCamelCase__		:    Dict         =tf.zeros(self.model_tester.batch_size						,  dtype=tf.intaa						)

								return inputs_dict






			def    _lowerCAmelCase			(							self     :					List[Any]						):
								UpperCamelCase__		:    Any         =TFAlbertModelTester(self						)
								UpperCamelCase__		:    Union[str, Any]         =ConfigTester(self						,  config_class=lowercase_						,  hidden_size=37						)






			def    _lowerCAmelCase			(							self     :					Any						):
								self.config_tester.run_common_tests()






			def    _lowerCAmelCase			(							self     :					int						):
								UpperCamelCase__		:    str         =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_model(*lowercase_						)






			def    _lowerCAmelCase			(							self     :					List[str]						):
								UpperCamelCase__		:    Optional[int]         =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_pretraining(*lowercase_						)






			def    _lowerCAmelCase			(							self     :					Dict						):
								UpperCamelCase__		:    str         =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_masked_lm(*lowercase_						)






			def    _lowerCAmelCase			(							self     :					List[str]						):
								UpperCamelCase__		:    Tuple         =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_multiple_choice(*lowercase_						)






			def    _lowerCAmelCase			(							self     :					Any						):
								UpperCamelCase__		:    int         =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_sequence_classification(*lowercase_						)






			def    _lowerCAmelCase			(							self     :					Any						):
								UpperCamelCase__		:    int         =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_question_answering(*lowercase_						)






			@slow
			def    _lowerCAmelCase			(							self     :					Dict						):
								for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													UpperCamelCase__		:    Tuple         =TFAlbertModel.from_pretrained(lowercase_						)
													self.assertIsNotNone(lowercase_						)



@require_tf
class     __a   (      unittest.TestCase    ):

			"""simple docstring"""

			@slow
			def    _lowerCAmelCase			(							self     :					List[str]						):
								UpperCamelCase__		:    List[str]         =TFAlbertForPreTraining.from_pretrained('''albert-base-v2'''						)
								UpperCamelCase__		:    List[Any]         =tf.constant([[0, 1, 2, 3, 4, 5]]						)
								UpperCamelCase__		:    Optional[Any]         =model(lowercase_						)[0]

								UpperCamelCase__		:    List[str]         =[1, 6, 3_0000]
								self.assertEqual(output.shape						,  lowercase_						)

								UpperCamelCase__		:    Dict         =tf.constant(
								    [
								        [
								            [4.5_9_5_6_6_8, 0.7_4_4_6_2_7_5_4, -1.8_1_8_1_4_7],
								            [4.5_9_5_4_3_4_7, 0.7_4_5_4_1_8_4, -1.8_1_8_8_2_5_8],
								            [4.5_9_5_4_9_0_5, 0.7_4_4_8_2_3_5, -1.8_1_8_2_3_1_6],
								        ]
								    ]						)
								tf.debugging.assert_near(output[:, :3, :3]						,  lowercase_						,  atol=1e-4						)





"""simple docstring"""





def        _lowerCAmelCase      (						UpperCAmelCase     :							list[list[int]]				):


					'''simple docstring'''






					UpperCamelCase__		:    Dict         =[list(UpperCAmelCase				) for row in matrix]
					if matrix and isinstance(UpperCAmelCase      ,							UpperCAmelCase				):
										if isinstance(matrix[0]      ,							UpperCAmelCase				):
															UpperCamelCase__		:    List[Any]         =0
															for row in matrix:
																				if prev_len == 0:
																									UpperCamelCase__		:    Optional[Any]         =len(UpperCAmelCase				)
																									UpperCamelCase__		:    Optional[int]         =True
																				else:
																									UpperCamelCase__		:    List[str]         =prev_len == len(UpperCAmelCase				)
										else:
															UpperCamelCase__		:    Tuple         =True
					else:
										UpperCamelCase__		:    Optional[Any]         =False

					return result



def        _lowerCAmelCase      (						UpperCAmelCase     :							list[list[int]]				):


					'''simple docstring'''






					if check_matrix(UpperCAmelCase				) and len(UpperCAmelCase				) > 0:
										UpperCamelCase__		:    Optional[int]         =[list(UpperCAmelCase				) for row in a]
										UpperCamelCase__		:    Any         =len(UpperCAmelCase				)
										if isinstance(a[0]      ,							UpperCAmelCase				):
															UpperCamelCase__		:    Tuple         =len(a[0]				)
										else:
															for dat in a:
																				print(UpperCAmelCase				)
															return

										# horizotal printing increasing
										for i in range(0      ,							UpperCAmelCase				):
															print(a[0][i]				)
										# vertical printing down
										for i in range(1      ,							UpperCAmelCase				):
															print(a[i][mat_col - 1]				)
										# horizotal printing decreasing
										if mat_row > 1:
															for i in range(mat_col - 2      ,							-1      ,							-1				):
																				print(a[mat_row - 1][i]				)
        # vertical printing up
										for i in range(mat_row - 2      ,							0      ,							-1				):
															print(a[i][0]				)
										UpperCamelCase__		:    Tuple         =[row[1 : mat_col - 1] for row in a[1 : mat_row - 1]]
										if len(UpperCAmelCase				) > 0:
															spiral_print_clockwise(UpperCAmelCase				)
										else:
															return
					else:
										print('''Not a valid matrix'''				)
										return



def        _lowerCAmelCase      (						UpperCAmelCase     :							list[list]				):


					'''simple docstring'''






					if matrix:
										return list(matrix.pop(0				)				) + spiral_traversal(list(zip(*UpperCAmelCase				)				)[::-1]				)
					else:
										return []


# driver code
if __name__ == "__main__":
				import doctest

				doctest.testmod()

				_SCREAMING_SNAKE_CASE       :  int        = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 1_0, 1_1, 1_2]]
				spiral_print_clockwise(a)


