



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 					_A :



							def __init__(	self							:  Tuple  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	):


											'''simple docstring'''

											__a		 =       parent
											__a		 =       13
											__a		 =       7
											__a		 =       True
											__a		 =       True
											__a		 =       False
											__a		 =       True
											__a		 =       99
											__a		 =       32
											__a		 =       2
											__a		 =       4
											__a		 =       37
											__a		 =       '''gelu'''
											__a		 =       0.1
											__a		 =       0.1
											__a		 =       512
											__a		 =       16
											__a		 =       2
											__a		 =       0.02
											__a		 =       3
											__a		 =       4
											__a		 =       None



							def 	_lowerCamelCase    (	self							:  List[str]):


											'''simple docstring'''

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

											__a		 =       None
											if self.use_input_mask:
															__a		 =       random_attention_mask([self.batch_size, self.seq_length])

											__a		 =       None
											__a		 =       None
											__a		 =       None
											if self.use_labels:
															__a		 =       ids_tensor([self.batch_size]  ,	self.type_sequence_label_size)
															__a		 =       ids_tensor([self.batch_size, self.seq_length]  ,	self.num_labels)
															__a		 =       ids_tensor([self.batch_size]  ,	self.num_choices)

											__a		 =       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 	_lowerCamelCase    (	self							:  Any  ,	__SCREAMING_SNAKE_CASE							:  Dict  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  Any  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  Dict  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]):


											'''simple docstring'''

											__a		 =       TFDistilBertModel(config=__SCREAMING_SNAKE_CASE)
											__a		 =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}

											__a		 =       model(__SCREAMING_SNAKE_CASE)

											__a		 =       [input_ids, input_mask]

											__a		 =       model(__SCREAMING_SNAKE_CASE)

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



							def 	_lowerCamelCase    (	self							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  Any  ,	__SCREAMING_SNAKE_CASE							:  int  ,	__SCREAMING_SNAKE_CASE							:  Dict  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]):


											'''simple docstring'''

											__a		 =       TFDistilBertForMaskedLM(config=__SCREAMING_SNAKE_CASE)
											__a		 =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
											__a		 =       model(__SCREAMING_SNAKE_CASE)
											self.parent.assertEqual(result.logits.shape  ,	(self.batch_size, self.seq_length, self.vocab_size))



							def 	_lowerCamelCase    (	self							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  int  ,	__SCREAMING_SNAKE_CASE							:  Union[str, Any]  ,	__SCREAMING_SNAKE_CASE							:  Union[str, Any]  ,	__SCREAMING_SNAKE_CASE							:  Union[str, Any]  ,	__SCREAMING_SNAKE_CASE							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  Optional[int]):


											'''simple docstring'''

											__a		 =       TFDistilBertForQuestionAnswering(config=__SCREAMING_SNAKE_CASE)
											__a		 =       {
											    '''input_ids''': input_ids,
											    '''attention_mask''': input_mask,
											}
											__a		 =       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 	_lowerCamelCase    (	self							:  str  ,	__SCREAMING_SNAKE_CASE							:  int  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  Tuple  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]  ,	__SCREAMING_SNAKE_CASE							:  Dict):


											'''simple docstring'''

											__a		 =       self.num_labels
											__a		 =       TFDistilBertForSequenceClassification(__SCREAMING_SNAKE_CASE)
											__a		 =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
											__a		 =       model(__SCREAMING_SNAKE_CASE)
											self.parent.assertEqual(result.logits.shape  ,	(self.batch_size, self.num_labels))



							def 	_lowerCamelCase    (	self							:  int  ,	__SCREAMING_SNAKE_CASE							:  str  ,	__SCREAMING_SNAKE_CASE							:  str  ,	__SCREAMING_SNAKE_CASE							:  Any  ,	__SCREAMING_SNAKE_CASE							:  str  ,	__SCREAMING_SNAKE_CASE							:  int  ,	__SCREAMING_SNAKE_CASE							:  Dict):


											'''simple docstring'''

											__a		 =       self.num_choices
											__a		 =       TFDistilBertForMultipleChoice(__SCREAMING_SNAKE_CASE)
											__a		 =       tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE  ,	1)  ,	(1, self.num_choices, 1))
											__a		 =       tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE  ,	1)  ,	(1, self.num_choices, 1))
											__a		 =       {
											    '''input_ids''': multiple_choice_inputs_ids,
											    '''attention_mask''': multiple_choice_input_mask,
											}
											__a		 =       model(__SCREAMING_SNAKE_CASE)
											self.parent.assertEqual(result.logits.shape  ,	(self.batch_size, self.num_choices))



							def 	_lowerCamelCase    (	self							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]  ,	__SCREAMING_SNAKE_CASE							:  Tuple  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]  ,	__SCREAMING_SNAKE_CASE							:  Dict  ,	__SCREAMING_SNAKE_CASE							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  Union[str, Any]):


											'''simple docstring'''

											__a		 =       self.num_labels
											__a		 =       TFDistilBertForTokenClassification(__SCREAMING_SNAKE_CASE)
											__a		 =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
											__a		 =       model(__SCREAMING_SNAKE_CASE)
											self.parent.assertEqual(result.logits.shape  ,	(self.batch_size, self.seq_length, self.num_labels))





							def 	_lowerCamelCase    (	self							:  List[str]):


											'''simple docstring'''

											__a		 =       self.prepare_config_and_inputs()
											(__a)		 =       config_and_inputs
											__a		 =       {'''input_ids''': input_ids, '''attention_mask''': input_mask}
											return config, inputs_dict


@require_tf
class 					_A (			__A   ,__A   ,unittest.TestCase					):
							UpperCamelCase__						:					Dict		      =		(
							    (
							        TFDistilBertModel,
							        TFDistilBertForMaskedLM,
							        TFDistilBertForQuestionAnswering,
							        TFDistilBertForSequenceClassification,
							        TFDistilBertForTokenClassification,
							        TFDistilBertForMultipleChoice,
							    )
							    if is_tf_available()
							    else None
							)
							UpperCamelCase__						:					str		      =		(
							    {
							        '''feature-extraction''': TFDistilBertModel,
							        '''fill-mask''': TFDistilBertForMaskedLM,
							        '''question-answering''': TFDistilBertForQuestionAnswering,
							        '''text-classification''': TFDistilBertForSequenceClassification,
							        '''token-classification''': TFDistilBertForTokenClassification,
							        '''zero-shot''': TFDistilBertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							UpperCamelCase__						:					str		      =		False
							UpperCamelCase__						:					int		      =		False



							def 	_lowerCamelCase    (	self							:  Dict):


											'''simple docstring'''

											__a		 =       TFDistilBertModelTester(self)
											__a		 =       ConfigTester(self  ,	config_class=__SCREAMING_SNAKE_CASE  ,	dim=37)



							def 	_lowerCamelCase    (	self							:  Union[str, Any]):


											'''simple docstring'''

											self.config_tester.run_common_tests()



							def 	_lowerCamelCase    (	self							:  Optional[Any]):


											'''simple docstring'''

											__a		 =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_model(*__SCREAMING_SNAKE_CASE)



							def 	_lowerCamelCase    (	self							:  Tuple):


											'''simple docstring'''

											__a		 =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_masked_lm(*__SCREAMING_SNAKE_CASE)



							def 	_lowerCamelCase    (	self							:  Optional[int]):


											'''simple docstring'''

											__a		 =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_question_answering(*__SCREAMING_SNAKE_CASE)



							def 	_lowerCamelCase    (	self							:  Any):


											'''simple docstring'''

											__a		 =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_sequence_classification(*__SCREAMING_SNAKE_CASE)



							def 	_lowerCamelCase    (	self							:  Optional[Any]):


											'''simple docstring'''

											__a		 =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_multiple_choice(*__SCREAMING_SNAKE_CASE)



							def 	_lowerCamelCase    (	self							:  str):


											'''simple docstring'''

											__a		 =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_distilbert_for_token_classification(*__SCREAMING_SNAKE_CASE)





							@slow
							def 	_lowerCamelCase    (	self							:  List[Any]):


											'''simple docstring'''

											for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]):
															__a		 =       TFDistilBertModel.from_pretrained(__SCREAMING_SNAKE_CASE)
															self.assertIsNotNone(__SCREAMING_SNAKE_CASE)


@require_tf
class 					_A (			unittest.TestCase					):



							@slow
							def 	_lowerCamelCase    (	self							:  List[str]):


											'''simple docstring'''

											__a		 =       TFDistilBertModel.from_pretrained('''distilbert-base-uncased''')
											__a		 =       tf.constant([[0, 1, 2, 3, 4, 5]])
											__a		 =       model(__SCREAMING_SNAKE_CASE)[0]

											__a		 =       [1, 6, 768]
											self.assertEqual(output.shape  ,	__SCREAMING_SNAKE_CASE)

											__a		 =       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)










__snake_case		:str   	=  [
    [0, 16, 13, 0, 0, 0],
    [0, 0, 10, 12, 0, 0],
    [0, 4, 0, 0, 14, 0],
    [0, 0, 9, 0, 0, 20],
    [0, 0, 0, 7, 0, 4],
    [0, 0, 0, 0, 0, 0],
]





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase       ):
    # Return True if there is node that has not iterated.
    __a		 =       [False] * len(_UpperCAmelCase       )
    __a		 =       [s]
    __a		 =       True

    while queue:
        __a		 =       queue.pop(0       )
        for ind in range(len(graph[u]       )       ):
            if visited[ind] is False and graph[u][ind] > 0:
                queue.append(_UpperCAmelCase       )
                __a		 =       True
                __a		 =       u

    return visited[t]





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase       ):
    __a		 =       [-1] * (len(_UpperCAmelCase       ))
    __a		 =       0
    __a		 =       []
    __a		 =       [i[:] for i in graph]  # Record original cut, copy.
    while bfs(_UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase       ):
        __a		 =       float('''Inf'''       )
        __a		 =       sink

        while s != source:
            # Find the minimum value in select path
            __a		 =       min(_UpperCAmelCase     ,				graph[parent[s]][s]       )
            __a		 =       parent[s]

        max_flow += path_flow
        __a		 =       sink

        while v != source:
            __a		 =       parent[v]
            graph[u][v] -= path_flow
            graph[v][u] += path_flow
            __a		 =       parent[v]

    for i in range(len(_UpperCAmelCase       )       ):
        for j in range(len(graph[0]       )       ):
            if graph[i][j] == 0 and temp[i][j] > 0:
                res.append((i, j)       )

    return res


if __name__ == "__main__":
 print(mincut(test_graph, source=0, sink=5))





