

'''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 		__SCREAMING_SNAKE_CASE       :







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







				def    lowerCamelCase_  (					self    :		str      ):
										'''simple docstring'''
										lowercase   :       Tuple								=ids_tensor([self.batch_size, self.seq_length]		,				self.vocab_size      )

										lowercase   :       Any								=None
										if self.use_input_mask:
																lowercase   :       List[str]								=random_attention_mask([self.batch_size, self.seq_length]      )

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

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

										lowercase   :       Optional[Any]								=self.get_config()

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







				def    lowerCamelCase_  (					self    :		Tuple      ):
										'''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    :		int		,				UpperCAmelCase__    :		Optional[int]		,				UpperCAmelCase__    :		int		,				UpperCAmelCase__    :		Tuple		,				UpperCAmelCase__    :		Union[str, Any]		,				UpperCAmelCase__    :		Any		,				UpperCAmelCase__    :		Any		,				UpperCAmelCase__    :		int      ):
										'''simple docstring'''
										lowercase   :       Dict								=AlbertModel(config=lowerCamelCase_      )
										model.to(lowerCamelCase_      )
										model.eval()
										lowercase   :       Dict								=model(lowerCamelCase_		,				attention_mask=lowerCamelCase_		,				token_type_ids=lowerCamelCase_      )
										lowercase   :       Union[str, Any]								=model(lowerCamelCase_		,				token_type_ids=lowerCamelCase_      )
										lowercase   :       Dict								=model(lowerCamelCase_      )
										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    :		Optional[Any]		,				UpperCAmelCase__    :		Dict		,				UpperCAmelCase__    :		Dict		,				UpperCAmelCase__    :		List[str]		,				UpperCAmelCase__    :		Dict		,				UpperCAmelCase__    :		Optional[Any]		,				UpperCAmelCase__    :		str		,				UpperCAmelCase__    :		Union[str, Any]      ):
										'''simple docstring'''
										lowercase   :       List[Any]								=AlbertForPreTraining(config=lowerCamelCase_      )
										model.to(lowerCamelCase_      )
										model.eval()
										lowercase   :       Any								=model(
										    lowerCamelCase_		,				attention_mask=lowerCamelCase_		,				token_type_ids=lowerCamelCase_		,				labels=lowerCamelCase_		,				sentence_order_label=lowerCamelCase_		,				)
										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    :		List[Any]		,				UpperCAmelCase__    :		int		,				UpperCAmelCase__    :		int		,				UpperCAmelCase__    :		Any		,				UpperCAmelCase__    :		Optional[Any]		,				UpperCAmelCase__    :		int		,				UpperCAmelCase__    :		Any		,				UpperCAmelCase__    :		Any      ):
										'''simple docstring'''
										lowercase   :       List[Any]								=AlbertForMaskedLM(config=lowerCamelCase_      )
										model.to(lowerCamelCase_      )
										model.eval()
										lowercase   :       str								=model(lowerCamelCase_		,				attention_mask=lowerCamelCase_		,				token_type_ids=lowerCamelCase_		,				labels=lowerCamelCase_      )
										self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.seq_length, self.vocab_size)      )







				def    lowerCamelCase_  (					self    :		List[Any]		,				UpperCAmelCase__    :		int		,				UpperCAmelCase__    :		str		,				UpperCAmelCase__    :		List[Any]		,				UpperCAmelCase__    :		Tuple		,				UpperCAmelCase__    :		Union[str, Any]		,				UpperCAmelCase__    :		List[Any]		,				UpperCAmelCase__    :		Tuple      ):
										'''simple docstring'''
										lowercase   :       Tuple								=AlbertForQuestionAnswering(config=lowerCamelCase_      )
										model.to(lowerCamelCase_      )
										model.eval()
										lowercase   :       List[str]								=model(
										    lowerCamelCase_		,				attention_mask=lowerCamelCase_		,				token_type_ids=lowerCamelCase_		,				start_positions=lowerCamelCase_		,				end_positions=lowerCamelCase_		,				)
										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    :		int		,				UpperCAmelCase__    :		Optional[int]		,				UpperCAmelCase__    :		List[str]		,				UpperCAmelCase__    :		int		,				UpperCAmelCase__    :		Any		,				UpperCAmelCase__    :		Any		,				UpperCAmelCase__    :		int		,				UpperCAmelCase__    :		Optional[int]      ):
										'''simple docstring'''
										lowercase   :       Dict								=self.num_labels
										lowercase   :       List[Any]								=AlbertForSequenceClassification(lowerCamelCase_      )
										model.to(lowerCamelCase_      )
										model.eval()
										lowercase   :       Optional[int]								=model(lowerCamelCase_		,				attention_mask=lowerCamelCase_		,				token_type_ids=lowerCamelCase_		,				labels=lowerCamelCase_      )
										self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.num_labels)      )







				def    lowerCamelCase_  (					self    :		Tuple		,				UpperCAmelCase__    :		Union[str, Any]		,				UpperCAmelCase__    :		Union[str, Any]		,				UpperCAmelCase__    :		Dict		,				UpperCAmelCase__    :		Dict		,				UpperCAmelCase__    :		List[Any]		,				UpperCAmelCase__    :		List[Any]		,				UpperCAmelCase__    :		Union[str, Any]      ):
										'''simple docstring'''
										lowercase   :       Dict								=self.num_labels
										lowercase   :       Optional[int]								=AlbertForTokenClassification(config=lowerCamelCase_      )
										model.to(lowerCamelCase_      )
										model.eval()
										lowercase   :       Tuple								=model(lowerCamelCase_		,				attention_mask=lowerCamelCase_		,				token_type_ids=lowerCamelCase_		,				labels=lowerCamelCase_      )
										self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.seq_length, self.num_labels)      )







				def    lowerCamelCase_  (					self    :		Any		,				UpperCAmelCase__    :		Tuple		,				UpperCAmelCase__    :		Union[str, Any]		,				UpperCAmelCase__    :		Dict		,				UpperCAmelCase__    :		Optional[Any]		,				UpperCAmelCase__    :		int		,				UpperCAmelCase__    :		str		,				UpperCAmelCase__    :		List[str]      ):
										'''simple docstring'''
										lowercase   :       List[str]								=self.num_choices
										lowercase   :       Optional[Any]								=AlbertForMultipleChoice(config=lowerCamelCase_      )
										model.to(lowerCamelCase_      )
										model.eval()
										lowercase   :       List[str]								=input_ids.unsqueeze(1      ).expand(-1		,				self.num_choices		,				-1      ).contiguous()
										lowercase   :       Dict								=token_type_ids.unsqueeze(1      ).expand(-1		,				self.num_choices		,				-1      ).contiguous()
										lowercase   :       List[Any]								=input_mask.unsqueeze(1      ).expand(-1		,				self.num_choices		,				-1      ).contiguous()
										lowercase   :       Optional[Any]								=model(
										    lowerCamelCase_		,				attention_mask=lowerCamelCase_		,				token_type_ids=lowerCamelCase_		,				labels=lowerCamelCase_		,				)
										self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.num_choices)      )







				def    lowerCamelCase_  (					self    :		Any      ):
										'''simple docstring'''
										lowercase   :       Tuple								=self.prepare_config_and_inputs()
										(
										    (
										    lowercase      
										)		,  (
										    lowercase      
										)		,  (
										    lowercase      
										)		,  (
										    lowercase      
										)		,  (
										    lowercase      
										)		,  (
										    lowercase      
										)		,  (
										    lowercase      
										)		,        
										)   :       Union[str, Any]								=config_and_inputs
										lowercase   :       Optional[int]								={'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
										return config, inputs_dict





@require_torch
class 		__SCREAMING_SNAKE_CASE       ( a__	,       a__	,       unittest.TestCase			):
				lowerCamelCase_							=						(
				    (
				        AlbertModel,
				        AlbertForPreTraining,
				        AlbertForMaskedLM,
				        AlbertForMultipleChoice,
				        AlbertForSequenceClassification,
				        AlbertForTokenClassification,
				        AlbertForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				lowerCamelCase_							=						(
				    {
				        "feature-extraction": AlbertModel,
				        "fill-mask": AlbertForMaskedLM,
				        "question-answering": AlbertForQuestionAnswering,
				        "text-classification": AlbertForSequenceClassification,
				        "token-classification": AlbertForTokenClassification,
				        "zero-shot": AlbertForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				lowerCamelCase_							=						True







				def    lowerCamelCase_  (					self    :		int		,				UpperCAmelCase__    :		Union[str, Any]		,				UpperCAmelCase__    :		Any		,				UpperCAmelCase__    :		Dict=False      ):
										'''simple docstring'''
										lowercase   :       Union[str, Any]								=super()._prepare_for_class(lowerCamelCase_		,				lowerCamelCase_		,				return_labels=lowerCamelCase_      )

										if return_labels:
																if model_class in get_values(lowerCamelCase_      ):
																						lowercase   :       Dict								=torch.zeros(
																						    (self.model_tester.batch_size, self.model_tester.seq_length)		,				dtype=torch.long		,				device=lowerCamelCase_      )
																						lowercase   :       List[Any]								=torch.zeros(
																						    self.model_tester.batch_size		,				dtype=torch.long		,				device=lowerCamelCase_      )
										return inputs_dict







				def    lowerCamelCase_  (					self    :		Any      ):
										'''simple docstring'''
										lowercase   :       Union[str, Any]								=AlbertModelTester(self      )
										lowercase   :       Optional[int]								=ConfigTester(self		,				config_class=lowerCamelCase_		,				hidden_size=37      )







				def    lowerCamelCase_  (					self    :		int      ):
										'''simple docstring'''
										self.config_tester.run_common_tests()







				def    lowerCamelCase_  (					self    :		Any      ):
										'''simple docstring'''
										lowercase   :       List[str]								=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCamelCase_      )







				def    lowerCamelCase_  (					self    :		Tuple      ):
										'''simple docstring'''
										lowercase   :       Optional[int]								=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_pretraining(*lowerCamelCase_      )







				def    lowerCamelCase_  (					self    :		Dict      ):
										'''simple docstring'''
										lowercase   :       Any								=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase_      )







				def    lowerCamelCase_  (					self    :		Dict      ):
										'''simple docstring'''
										lowercase   :       Optional[int]								=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase_      )







				def    lowerCamelCase_  (					self    :		Tuple      ):
										'''simple docstring'''
										lowercase   :       List[str]								=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*lowerCamelCase_      )







				def    lowerCamelCase_  (					self    :		int      ):
										'''simple docstring'''
										lowercase   :       Any								=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase_      )







				def    lowerCamelCase_  (					self    :		Optional[int]      ):
										'''simple docstring'''
										lowercase   :       Dict								=self.model_tester.prepare_config_and_inputs()
										for type in ["absolute", "relative_key", "relative_key_query"]:
																lowercase   :       Any								=type
																self.model_tester.create_and_check_model(*lowerCamelCase_      )







				@slow
				def    lowerCamelCase_  (					self    :		Optional[int]      ):
										'''simple docstring'''
										for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																lowercase   :       Dict								=AlbertModel.from_pretrained(lowerCamelCase_      )
																self.assertIsNotNone(lowerCamelCase_      )





@require_torch
class 		__SCREAMING_SNAKE_CASE       ( unittest.TestCase			):







				@slow
				def    lowerCamelCase_  (					self    :		str      ):
										'''simple docstring'''
										lowercase   :       Any								=AlbertModel.from_pretrained('''albert-base-v2'''      )
										lowercase   :       Union[str, Any]								=torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]      )
										lowercase   :       Optional[Any]								=torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
										with torch.no_grad():
																lowercase   :       Optional[Any]								=model(lowerCamelCase_		,				attention_mask=lowerCamelCase_      )[0]
										lowercase   :       str								=torch.Size((1, 11, 768)      )
										self.assertEqual(output.shape		,				lowerCamelCase_      )
										lowercase   :       List[Any]								=torch.tensor(
										    [[[-0.65_13, 1.50_35, -0.27_66], [-0.65_15, 1.50_46, -0.27_80], [-0.65_12, 1.50_49, -0.27_84]]]      )

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








'''simple docstring'''





from __future__ import annotations






def 							_lowerCAmelCase (      __magic_name__	:    list[list[int]]	)							->     bool:
						lowercase   :       str								=len(__magic_name__	)
						# We need to create solution object to save path.
						lowercase   :       int								=[[0 for _ in range(__magic_name__	)] for _ in range(__magic_name__	)]
						lowercase   :       List[Any]								=run_maze(__magic_name__      ,   0      ,   0      ,   __magic_name__	)
						if solved:
												print('''\n'''.join(str(__magic_name__	) for row in solutions	)	)
						else:
												print('''No solution exists!'''	)
						return solved






def 							_lowerCAmelCase (      __magic_name__	:    list[list[int]]      ,   __magic_name__	:    int      ,   __magic_name__	:    int      ,   __magic_name__	:    list[list[int]]	)							->     bool:
						lowercase   :       Optional[int]								=len(__magic_name__	)
						# Final check point.
						if i == j == (size - 1):
												lowercase   :       Optional[int]								=1
												return True

						lowercase   :       Optional[int]								=(not i < 0) and (not j < 0)  # Check lower bounds
						lowercase   :       Tuple								=(i < size) and (j < size)  # Check upper bounds

						if lower_flag and upper_flag:
												# check for already visited and block points.
												lowercase   :       Union[str, Any]								=(not solutions[i][j]) and (not maze[i][j])
												if block_flag:
																		# check visited
																		lowercase   :       Union[str, Any]								=1

																		# check for directions
																		if (
																		    run_maze(__magic_name__      ,   i + 1      ,   __magic_name__      ,   __magic_name__	)
																		    or run_maze(__magic_name__      ,   __magic_name__      ,   j + 1      ,   __magic_name__	)
																		    or run_maze(__magic_name__      ,   i - 1      ,   __magic_name__      ,   __magic_name__	)
																		    or run_maze(__magic_name__      ,   __magic_name__      ,   j - 1      ,   __magic_name__	)
																		):
																								return True

																		lowercase   :       str								=0
																		return False
						return False


if __name__ == "__main__":
							import doctest

							doctest.testmod()





