




'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
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.models.distilbert.modeling_tf_distilbert import (
			    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
			    TFDistilBertForMaskedLM,
			    TFDistilBertForMultipleChoice,
			    TFDistilBertForQuestionAnswering,
			    TFDistilBertForSequenceClassification,
			    TFDistilBertForTokenClassification,
			    TFDistilBertModel,
			)
class 		SCREAMING_SNAKE_CASE			:




				'''simple docstring'''





				def __init__(   self  ,						SCREAMING_SNAKE_CASE__  ,						):
							'''simple docstring'''







							snake_case:       Tuple        =       parent
							snake_case:       Optional[Any]        =       13
							snake_case:       Optional[int]        =       7
							snake_case:       List[str]        =       True
							snake_case:       Tuple        =       True
							snake_case:       Dict        =       False
							snake_case:       List[str]        =       True
							snake_case:       Dict        =       99
							snake_case:       Optional[Any]        =       32
							snake_case:       Tuple        =       2
							snake_case:       Union[str, Any]        =       4
							snake_case:       Union[str, Any]        =       37
							snake_case:       Dict        =       'gelu'
							snake_case:       List[str]        =       0.1
							snake_case:       Tuple        =       0.1
							snake_case:       List[str]        =       5_12
							snake_case:       int        =       16
							snake_case:       Tuple        =       2
							snake_case:       List[Any]        =       0.02
							snake_case:       Tuple        =       3
							snake_case:       List[str]        =       4
							snake_case:       Dict        =       None







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       List[str]        =       ids_tensor([self.batch_size, self.seq_length]  ,						self.vocab_size				)

							snake_case:       Tuple        =       None
							if self.use_input_mask:
										snake_case:       Union[str, Any]        =       random_attention_mask([self.batch_size, self.seq_length]				)

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

							snake_case:       str        =       DistilBertConfig(
							    vocab_size=self.vocab_size  ,						dim=self.hidden_size  ,						n_layers=self.num_hidden_layers  ,						n_heads=self.num_attention_heads  ,						hidden_dim=self.intermediate_size  ,						hidden_act=self.hidden_act  ,						dropout=self.hidden_dropout_prob  ,						attention_dropout=self.attention_probs_dropout_prob  ,						max_position_embeddings=self.max_position_embeddings  ,						initializer_range=self.initializer_range  ,						)

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







				def        _UpperCamelCase							(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__				):
							'''simple docstring'''







							snake_case:       Optional[int]        =       TFDistilBertModel(config=SCREAMING_SNAKE_CASE__				)
							snake_case:       int        =       {'input_ids': input_ids, 'attention_mask': input_mask}

							snake_case:       List[str]        =       model(SCREAMING_SNAKE_CASE__				)

							snake_case:       List[Any]        =       [input_ids, input_mask]

							snake_case:       Dict        =       model(SCREAMING_SNAKE_CASE__				)

							self.parent.assertEqual(result.last_hidden_state.shape  ,						(self.batch_size, self.seq_length, self.hidden_size)				)







				def        _UpperCamelCase							(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__				):
							'''simple docstring'''







							snake_case:       Optional[Any]        =       TFDistilBertForMaskedLM(config=SCREAMING_SNAKE_CASE__				)
							snake_case:       List[Any]        =       {'input_ids': input_ids, 'attention_mask': input_mask}
							snake_case:       int        =       model(SCREAMING_SNAKE_CASE__				)
							self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.vocab_size)				)







				def        _UpperCamelCase							(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__				):
							'''simple docstring'''







							snake_case:       str        =       TFDistilBertForQuestionAnswering(config=SCREAMING_SNAKE_CASE__				)
							snake_case:       Tuple        =       {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							}
							snake_case:       int        =       model(SCREAMING_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        _UpperCamelCase							(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__				):
							'''simple docstring'''







							snake_case:       Optional[int]        =       self.num_labels
							snake_case:       int        =       TFDistilBertForSequenceClassification(SCREAMING_SNAKE_CASE__				)
							snake_case:       Any        =       {'input_ids': input_ids, 'attention_mask': input_mask}
							snake_case:       List[str]        =       model(SCREAMING_SNAKE_CASE__				)
							self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_labels)				)







				def        _UpperCamelCase							(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__				):
							'''simple docstring'''







							snake_case:       int        =       self.num_choices
							snake_case:       List[str]        =       TFDistilBertForMultipleChoice(SCREAMING_SNAKE_CASE__				)
							snake_case:       int        =       tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__  ,						1				)  ,						(1, self.num_choices, 1)				)
							snake_case:       Optional[int]        =       tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__  ,						1				)  ,						(1, self.num_choices, 1)				)
							snake_case:       int        =       {
							    'input_ids': multiple_choice_inputs_ids,
							    'attention_mask': multiple_choice_input_mask,
							}
							snake_case:       List[Any]        =       model(SCREAMING_SNAKE_CASE__				)
							self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_choices)				)







				def        _UpperCamelCase							(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__				):
							'''simple docstring'''







							snake_case:       List[str]        =       self.num_labels
							snake_case:       Union[str, Any]        =       TFDistilBertForTokenClassification(SCREAMING_SNAKE_CASE__				)
							snake_case:       Tuple        =       {'input_ids': input_ids, 'attention_mask': input_mask}
							snake_case:       str        =       model(SCREAMING_SNAKE_CASE__				)
							self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.num_labels)				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Dict        =       self.prepare_config_and_inputs()
							(snake_case):       str        =       config_and_inputs
							snake_case:       Optional[Any]        =       {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict






@require_tf
class 		SCREAMING_SNAKE_CASE			(     snake_case    ,      snake_case    ,      unittest.TestCase							):




				'''simple docstring'''





				__UpperCamelCase     				=   (
				    (
				        TFDistilBertModel,
				        TFDistilBertForMaskedLM,
				        TFDistilBertForQuestionAnswering,
				        TFDistilBertForSequenceClassification,
				        TFDistilBertForTokenClassification,
				        TFDistilBertForMultipleChoice,
				    )
				    if is_tf_available()
				    else None
				)
				__UpperCamelCase     				=   (
				    {
				        "feature-extraction": TFDistilBertModel,
				        "fill-mask": TFDistilBertForMaskedLM,
				        "question-answering": TFDistilBertForQuestionAnswering,
				        "text-classification": TFDistilBertForSequenceClassification,
				        "token-classification": TFDistilBertForTokenClassification,
				        "zero-shot": TFDistilBertForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				__UpperCamelCase     				=   False
				__UpperCamelCase     				=   False







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       List[str]        =       TFDistilBertModelTester(self				)
							snake_case:       Any        =       ConfigTester(self  ,						config_class=SCREAMING_SNAKE_CASE__  ,						dim=37				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							self.config_tester.run_common_tests()







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Dict        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_model(*SCREAMING_SNAKE_CASE__				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       List[str]        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_masked_lm(*SCREAMING_SNAKE_CASE__				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       str        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_question_answering(*SCREAMING_SNAKE_CASE__				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Optional[int]        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_sequence_classification(*SCREAMING_SNAKE_CASE__				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       List[str]        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_multiple_choice(*SCREAMING_SNAKE_CASE__				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Any        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_distilbert_for_token_classification(*SCREAMING_SNAKE_CASE__				)







				@slow
				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]				):
										snake_case:       int        =       TFDistilBertModel.from_pretrained(SCREAMING_SNAKE_CASE__				)
										self.assertIsNotNone(SCREAMING_SNAKE_CASE__				)






@require_tf
class 		SCREAMING_SNAKE_CASE			(     unittest.TestCase							):




				'''simple docstring'''





				@slow
				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       int        =       TFDistilBertModel.from_pretrained('distilbert-base-uncased'				)
							snake_case:       int        =       tf.constant([[0, 1, 2, 3, 4, 5]]				)
							snake_case:       int        =       model(SCREAMING_SNAKE_CASE__				)[0]

							snake_case:       Union[str, Any]        =       [1, 6, 7_68]
							self.assertEqual(output.shape  ,						SCREAMING_SNAKE_CASE__				)

							snake_case:       Dict        =       tf.constant(
							    [
							        [
							            [0.19_26_18_85, -0.13_73_29_55, 0.4_11_97_99],
							            [0.22_15_01_56, -0.07_42_26_61, 0.39_03_72_04],
							            [0.22_75_60_18, -0.0_89_64_14, 0.3_70_14_67],
							        ]
							    ]				)
							tf.debugging.assert_near(output[:, :3, :3]  ,						SCREAMING_SNAKE_CASE__  ,						atol=1E-4				)





"""simple docstring"""






from __future__ import annotations







def 	_snake_case     (							lowercase__						):
				_lowerCamelCase	:     int       =       len(lowercase__						)
				# We need to create solution object to save path.
				_lowerCamelCase	:     Tuple       =       [[0 for _ in range(lowercase__						)] for _ in range(lowercase__						)]
				_lowerCamelCase	:     Optional[Any]       =       run_maze(lowercase__				,       0				,       0				,       lowercase__						)
				if solved:
								print('\n'.join(str(lowercase__						) for row in solutions						)						)
				else:
								print('No solution exists!'						)
				return solved







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						):
				_lowerCamelCase	:     Optional[int]       =       len(lowercase__						)
				# Final check point.
				if i == j == (size - 1):
								_lowerCamelCase	:     Optional[Any]       =       1
								return True

				_lowerCamelCase	:     List[str]       =       (not i < 0) and (not j < 0)  # Check lower bounds
				_lowerCamelCase	:     List[str]       =       (i < size) and (j < size)  # Check upper bounds

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

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

												_lowerCamelCase	:     Dict       =       0
												return False
				return False


if __name__ == "__main__":
			import doctest

			doctest.testmod()