






import os
from itertools import chain
from random import randrange, shuffle

import pytest

from .sola import PokerHand

lowerCamelCase : List[Any]						   =       (
    '''4S 3H 2C 7S 5H''',
    '''9D 8H 2C 6S 7H''',
    '''2D 6D 9D TH 7D''',
    '''TC 8C 2S JH 6C''',
    '''JH 8S TH AH QH''',
    '''TS KS 5S 9S AC''',
    '''KD 6S 9D TH AD''',
    '''KS 8D 4D 9S 4S''',  # pair
    '''8C 4S KH JS 4D''',  # pair
    '''QH 8H KD JH 8S''',  # pair
    '''KC 4H KS 2H 8D''',  # pair
    '''KD 4S KC 3H 8S''',  # pair
    '''AH 8S AS KC JH''',  # pair
    '''3H 4C 4H 3S 2H''',  # 2 pairs
    '''5S 5D 2C KH KH''',  # 2 pairs
    '''3C KH 5D 5S KH''',  # 2 pairs
    '''AS 3C KH AD KH''',  # 2 pairs
    '''7C 7S 3S 7H 5S''',  # 3 of a kind
    '''7C 7S KH 2H 7H''',  # 3 of a kind
    '''AC KH QH AH AS''',  # 3 of a kind
    '''2H 4D 3C AS 5S''',  # straight (low ace)
    '''3C 5C 4C 2C 6H''',  # straight
    '''6S 8S 7S 5H 9H''',  # straight
    '''JS QS 9H TS KH''',  # straight
    '''QC KH TS JS AH''',  # straight (high ace)
    '''8C 9C 5C 3C TC''',  # flush
    '''3S 8S 9S 5S KS''',  # flush
    '''4C 5C 9C 8C KC''',  # flush
    '''JH 8H AH KH QH''',  # flush
    '''3D 2H 3H 2C 2D''',  # full house
    '''2H 2C 3S 3H 3D''',  # full house
    '''KH KC 3S 3H 3D''',  # full house
    '''JC 6H JS JD JH''',  # 4 of a kind
    '''JC 7H JS JD JH''',  # 4 of a kind
    '''JC KH JS JD JH''',  # 4 of a kind
    '''2S AS 4S 5S 3S''',  # straight flush (low ace)
    '''2D 6D 3D 4D 5D''',  # straight flush
    '''5C 6C 3C 7C 4C''',  # straight flush
    '''JH 9H TH KH QH''',  # straight flush
    '''JH AH TH KH QH''',  # royal flush (high ace straight flush)
)

lowerCamelCase : List[Any]						   =       (
    ('''2H 3H 4H 5H 6H''', '''KS AS TS QS JS''', '''Loss'''),
    ('''2H 3H 4H 5H 6H''', '''AS AD AC AH JD''', '''Win'''),
    ('''AS AH 2H AD AC''', '''JS JD JC JH 3D''', '''Win'''),
    ('''2S AH 2H AS AC''', '''JS JD JC JH AD''', '''Loss'''),
    ('''2S AH 2H AS AC''', '''2H 3H 5H 6H 7H''', '''Win'''),
    ('''AS 3S 4S 8S 2S''', '''2H 3H 5H 6H 7H''', '''Win'''),
    ('''2H 3H 5H 6H 7H''', '''2S 3H 4H 5S 6C''', '''Win'''),
    ('''2S 3H 4H 5S 6C''', '''3D 4C 5H 6H 2S''', '''Tie'''),
    ('''2S 3H 4H 5S 6C''', '''AH AC 5H 6H AS''', '''Win'''),
    ('''2S 2H 4H 5S 4C''', '''AH AC 5H 6H AS''', '''Loss'''),
    ('''2S 2H 4H 5S 4C''', '''AH AC 5H 6H 7S''', '''Win'''),
    ('''6S AD 7H 4S AS''', '''AH AC 5H 6H 7S''', '''Loss'''),
    ('''2S AH 4H 5S KC''', '''AH AC 5H 6H 7S''', '''Loss'''),
    ('''2S 3H 6H 7S 9C''', '''7H 3C TH 6H 9S''', '''Loss'''),
    ('''4S 5H 6H TS AC''', '''3S 5H 6H TS AC''', '''Win'''),
    ('''2S AH 4H 5S 6C''', '''AD 4C 5H 6H 2C''', '''Tie'''),
    ('''AS AH 3H AD AC''', '''AS AH 2H AD AC''', '''Win'''),
    ('''AH AC 5H 5C QS''', '''AH AC 5H 5C KS''', '''Loss'''),
    ('''AH AC 5H 5C QS''', '''KH KC 5H 5C QS''', '''Win'''),
    ('''7C 7S KH 2H 7H''', '''3C 3S AH 2H 3H''', '''Win'''),
    ('''3C 3S AH 2H 3H''', '''7C 7S KH 2H 7H''', '''Loss'''),
    ('''6H 5H 4H 3H 2H''', '''5H 4H 3H 2H AH''', '''Win'''),
    ('''5H 4H 3H 2H AH''', '''5H 4H 3H 2H AH''', '''Tie'''),
    ('''5H 4H 3H 2H AH''', '''6H 5H 4H 3H 2H''', '''Loss'''),
    ('''AH AD KS KC AC''', '''AH KD KH AC KC''', '''Win'''),
    ('''2H 4D 3C AS 5S''', '''2H 4D 3C 6S 5S''', '''Loss'''),
    ('''2H 3S 3C 3H 2S''', '''3S 3C 2S 2H 2D''', '''Win'''),
    ('''4D 6D 5D 2D JH''', '''3S 8S 3H TC KH''', '''Loss'''),
    ('''4S 6C 8S 3S 7S''', '''AD KS 2D 7D 7C''', '''Loss'''),
    ('''6S 4C 7H 8C 3H''', '''5H JC AH 9D 9C''', '''Loss'''),
    ('''9D 9H JH TC QH''', '''3C 2S JS 5C 7H''', '''Win'''),
    ('''2H TC 8S AD 9S''', '''4H TS 7H 2C 5C''', '''Win'''),
    ('''9D 3S 2C 7S 7C''', '''JC TD 3C TC 9H''', '''Loss'''),
)

lowerCamelCase : Tuple						   =       (
    ('''2H 3H 4H 5H 6H''', True),
    ('''AS AH 2H AD AC''', False),
    ('''2H 3H 5H 6H 7H''', True),
    ('''KS AS TS QS JS''', True),
    ('''8H 9H QS JS TH''', False),
    ('''AS 3S 4S 8S 2S''', True),
)

lowerCamelCase : Optional[int]						   =       (
    ('''2H 3H 4H 5H 6H''', True),
    ('''AS AH 2H AD AC''', False),
    ('''2H 3H 5H 6H 7H''', False),
    ('''KS AS TS QS JS''', True),
    ('''8H 9H QS JS TH''', True),
)

lowerCamelCase : List[Any]						   =       (
    ('''2H 4D 3C AS 5S''', True, [5, 4, 3, 2, 14]),
    ('''2H 5D 3C AS 5S''', False, [14, 5, 5, 3, 2]),
    ('''JH QD KC AS TS''', False, [14, 13, 12, 11, 10]),
    ('''9D 3S 2C 7S 7C''', False, [9, 7, 7, 3, 2]),
)

lowerCamelCase : int						   =       (
    ('''JH AH TH KH QH''', 0),
    ('''JH 9H TH KH QH''', 0),
    ('''JC KH JS JD JH''', 7),
    ('''KH KC 3S 3H 3D''', 6),
    ('''8C 9C 5C 3C TC''', 0),
    ('''JS QS 9H TS KH''', 0),
    ('''7C 7S KH 2H 7H''', 3),
    ('''3C KH 5D 5S KH''', 2),
    ('''QH 8H KD JH 8S''', 1),
    ('''2D 6D 9D TH 7D''', 0),
)

lowerCamelCase : Any						   =       (
    ('''JH AH TH KH QH''', 23),
    ('''JH 9H TH KH QH''', 22),
    ('''JC KH JS JD JH''', 21),
    ('''KH KC 3S 3H 3D''', 20),
    ('''8C 9C 5C 3C TC''', 19),
    ('''JS QS 9H TS KH''', 18),
    ('''7C 7S KH 2H 7H''', 17),
    ('''3C KH 5D 5S KH''', 16),
    ('''QH 8H KD JH 8S''', 15),
    ('''2D 6D 9D TH 7D''', 14),
)
def       snake_case_		(     ):
							__lowercase			,			__lowercase      :							Dict				=     randrange(len(lowerCAmelCase_      )      ), randrange(len(lowerCAmelCase_      )      )
							__lowercase      :							int				=     ["""Loss""", """Tie""", """Win"""][(play >= oppo) + (play > oppo)]
							__lowercase			,			__lowercase      :							Dict				=     SORTED_HANDS[play], SORTED_HANDS[oppo]
							return hand, other, expected
def       snake_case_		(     lowerCAmelCase_       :						int = 100      ):
							return (generate_random_hand() for _ in range(lowerCAmelCase_      ))
@pytest.mark.parametrize("""hand, expected"""       ,       lowerCAmelCase_      )
def       snake_case_		(     lowerCAmelCase_       :						Optional[int]       ,       lowerCAmelCase_       :						Optional[int]      ):
							assert PokerHand(lowerCAmelCase_      )._is_flush() == expected
@pytest.mark.parametrize("""hand, expected"""       ,       lowerCAmelCase_      )
def       snake_case_		(     lowerCAmelCase_       :						Any       ,       lowerCAmelCase_       :						Tuple      ):
							assert PokerHand(lowerCAmelCase_      )._is_straight() == expected
@pytest.mark.parametrize("""hand, expected, card_values"""       ,       lowerCAmelCase_      )
def       snake_case_		(     lowerCAmelCase_       :						List[str]       ,       lowerCAmelCase_       :						List[Any]       ,       lowerCAmelCase_       :						int      ):
							__lowercase      :							Union[str, Any]				=     PokerHand(lowerCAmelCase_      )
							assert player._is_five_high_straight() == expected
							assert player._card_values == card_values
@pytest.mark.parametrize("""hand, expected"""       ,       lowerCAmelCase_      )
def       snake_case_		(     lowerCAmelCase_       :						Union[str, Any]       ,       lowerCAmelCase_       :						str      ):
							assert PokerHand(lowerCAmelCase_      )._is_same_kind() == expected
@pytest.mark.parametrize("""hand, expected"""       ,       lowerCAmelCase_      )
def       snake_case_		(     lowerCAmelCase_       :						Any       ,       lowerCAmelCase_       :						Optional[int]      ):
							assert PokerHand(lowerCAmelCase_      )._hand_type == expected
@pytest.mark.parametrize("""hand, other, expected"""       ,       lowerCAmelCase_      )
def       snake_case_		(     lowerCAmelCase_       :						Any       ,       lowerCAmelCase_       :						Union[str, Any]       ,       lowerCAmelCase_       :						Any      ):
							assert PokerHand(lowerCAmelCase_      ).compare_with(PokerHand(lowerCAmelCase_      )      ) == expected
@pytest.mark.parametrize("""hand, other, expected"""       ,       generate_random_hands()      )
def       snake_case_		(     lowerCAmelCase_       :						str       ,       lowerCAmelCase_       :						Tuple       ,       lowerCAmelCase_       :						Optional[int]      ):
							assert PokerHand(lowerCAmelCase_      ).compare_with(PokerHand(lowerCAmelCase_      )      ) == expected
def       snake_case_		(     ):
							__lowercase      :							Tuple				=     [PokerHand(lowerCAmelCase_      ) for hand in SORTED_HANDS]
							__lowercase      :							List[Any]				=     poker_hands.copy()
							shuffle(lowerCAmelCase_      )
							__lowercase      :							Optional[int]				=     chain(sorted(lowerCAmelCase_      )      )
							for index, hand in enumerate(lowerCAmelCase_      ):
														assert hand == poker_hands[index]
def       snake_case_		(     ):
							# Test that five high straights are compared correctly.
							__lowercase      :							Dict				=     [PokerHand("""2D AC 3H 4H 5S"""      ), PokerHand("""2S 3H 4H 5S 6C"""      )]
							pokerhands.sort(reverse=lowerCAmelCase_      )
							assert pokerhands[0].__str__() == "2S 3H 4H 5S 6C"
def       snake_case_		(     ):
							# Multiple calls to five_high_straight function should still return True
							# and shouldn't mutate the list in every call other than the first.
							__lowercase      :							Any				=     PokerHand("""2C 4S AS 3D 5C"""      )
							__lowercase      :							Optional[Any]				=     True
							__lowercase      :							Tuple				=     [5, 4, 3, 2, 14]
							for _ in range(10      ):
														assert pokerhand._is_five_high_straight() == expected
														assert pokerhand._card_values == expected_card_values



def       snake_case_		(     ):
							# Problem number 54 from Project Euler
							# Testing from poker_hands.txt file
							__lowercase      :							Any				=     0
							__lowercase      :							Optional[Any]				=     os.path.abspath(os.path.dirname(lowerCAmelCase_      )      )
							__lowercase      :							int				=     os.path.join(lowerCAmelCase_       ,       """poker_hands.txt"""      )
							with open(lowerCAmelCase_      ) as file_hand:
														for line in file_hand:
																					__lowercase      :							List[Any]				=     line[:14].strip()
																					__lowercase      :							Any				=     line[15:].strip()
																					__lowercase			,			__lowercase      :							Any				=     PokerHand(lowerCAmelCase_      ), PokerHand(lowerCAmelCase_      )
																					__lowercase      :							str				=     player.compare_with(lowerCAmelCase_      )
																					if output == "Win":
																												answer += 1
							assert answer == 376







from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, 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 import (
	    TFConvBertForMaskedLM,
	    TFConvBertForMultipleChoice,
	    TFConvBertForQuestionAnswering,
	    TFConvBertForSequenceClassification,
	    TFConvBertForTokenClassification,
	    TFConvBertModel,
	)

class 		lowerCAmelCase     :

					'''simple docstring'''

					def __init__(  self				:	Union[str, Any]		,     __a				:	Dict		,     __a				:	Union[str, Any]=13		,     __a				:	Dict=7		,     __a				:	Dict=True		,     __a				:	Dict=True		,     __a				:	Any=True		,     __a				:	List[str]=True		,     __a				:	int=99		,     __a				:	Optional[int]=32		,     __a				:	str=2		,     __a				:	int=4		,     __a				:	List[str]=37		,     __a				:	Union[str, Any]="gelu"		,     __a				:	Union[str, Any]=0.1		,     __a				:	Union[str, Any]=0.1		,     __a				:	List[Any]=512		,     __a				:	int=16		,     __a				:	Union[str, Any]=2		,     __a				:	Union[str, Any]=0.02		,     __a				:	List[str]=3		,     __a				:	Dict=4		,     __a				:	Optional[Any]=None		,     )			->  Optional[Any]:


												"""simple docstring"""

												__lowercase      :							Any				=     parent
												__lowercase      :							Tuple				=     13
												__lowercase      :							Dict				=     7
												__lowercase      :							List[Any]				=     True
												__lowercase      :							Tuple				=     True
												__lowercase      :							List[str]				=     True
												__lowercase      :							Any				=     True
												__lowercase      :							Optional[int]				=     99
												__lowercase      :							str				=     384
												__lowercase      :							Optional[Any]				=     2
												__lowercase      :							Dict				=     4
												__lowercase      :							str				=     37
												__lowercase      :							Optional[int]				=     """gelu"""
												__lowercase      :							int				=     0.1
												__lowercase      :							Union[str, Any]				=     0.1
												__lowercase      :							Tuple				=     512
												__lowercase      :							Tuple				=     16
												__lowercase      :							Optional[int]				=     2
												__lowercase      :							Optional[Any]				=     0.02
												__lowercase      :							Dict				=     3
												__lowercase      :							Union[str, Any]				=     4
												__lowercase      :							Tuple				=     128
												__lowercase      :							Optional[Any]				=     2
												__lowercase      :							int				=     9
												__lowercase      :							List[Any]				=     1
												__lowercase      :							Union[str, Any]				=     None



					def       lowerCAmelCase				(  self				:	str							)			->  List[Any]:


												"""simple docstring"""

												__lowercase      :							Any				=     ids_tensor([self.batch_size, self.seq_length]		,     self.vocab_size							)

												__lowercase      :							Optional[Any]				=     None
												if self.use_input_mask:
																			__lowercase      :							Dict				=     random_attention_mask([self.batch_size, self.seq_length]							)

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

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

												__lowercase      :							Optional[int]				=     ConvBertConfig(
												    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		,     return_dict=__a		,     )

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



					def       lowerCAmelCase				(  self				:	Dict		,     __a				:	List[Any]		,     __a				:	List[str]		,     __a				:	Union[str, Any]		,     __a				:	str		,     __a				:	Union[str, Any]		,     __a				:	Tuple		,     __a				:	Tuple							)			->  Dict:


												"""simple docstring"""

												__lowercase      :							Dict				=     TFConvBertModel(config=__a							)
												__lowercase      :							Tuple				=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

												__lowercase      :							Any				=     [input_ids, input_mask]
												__lowercase      :							Dict				=     model(__a							)

												__lowercase      :							str				=     model(__a							)

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



					def       lowerCAmelCase				(  self				:	Tuple		,     __a				:	Union[str, Any]		,     __a				:	Any		,     __a				:	Tuple		,     __a				:	Union[str, Any]		,     __a				:	str		,     __a				:	Dict		,     __a				:	str							)			->  Dict:


												"""simple docstring"""

												__lowercase      :							Optional[int]				=     TFConvBertForMaskedLM(config=__a							)
												__lowercase      :							List[Any]				=     {
												    """input_ids""": input_ids,
												    """attention_mask""": input_mask,
												    """token_type_ids""": token_type_ids,
												}
												__lowercase      :							Any				=     model(__a							)
												self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.seq_length, self.vocab_size)							)



					def       lowerCAmelCase				(  self				:	Optional[int]		,     __a				:	int		,     __a				:	Any		,     __a				:	Optional[int]		,     __a				:	int		,     __a				:	int		,     __a				:	List[Any]		,     __a				:	Optional[int]							)			->  List[Any]:


												"""simple docstring"""

												__lowercase      :							str				=     self.num_labels
												__lowercase      :							List[Any]				=     TFConvBertForSequenceClassification(config=__a							)
												__lowercase      :							int				=     {
												    """input_ids""": input_ids,
												    """attention_mask""": input_mask,
												    """token_type_ids""": token_type_ids,
												}

												__lowercase      :							List[str]				=     model(__a							)
												self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.num_labels)							)



					def       lowerCAmelCase				(  self				:	Optional[int]		,     __a				:	Any		,     __a				:	Optional[Any]		,     __a				:	int		,     __a				:	Optional[int]		,     __a				:	Tuple		,     __a				:	int		,     __a				:	int							)			->  Dict:


												"""simple docstring"""

												__lowercase      :							Tuple				=     self.num_choices
												__lowercase      :							Dict				=     TFConvBertForMultipleChoice(config=__a							)
												__lowercase      :							List[str]				=     tf.tile(tf.expand_dims(__a		,     1							)		,     (1, self.num_choices, 1)							)
												__lowercase      :							int				=     tf.tile(tf.expand_dims(__a		,     1							)		,     (1, self.num_choices, 1)							)
												__lowercase      :							str				=     tf.tile(tf.expand_dims(__a		,     1							)		,     (1, self.num_choices, 1)							)
												__lowercase      :							str				=     {
												    """input_ids""": multiple_choice_inputs_ids,
												    """attention_mask""": multiple_choice_input_mask,
												    """token_type_ids""": multiple_choice_token_type_ids,
												}
												__lowercase      :							Dict				=     model(__a							)
												self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.num_choices)							)



					def       lowerCAmelCase				(  self				:	List[str]		,     __a				:	str		,     __a				:	List[str]		,     __a				:	List[str]		,     __a				:	List[str]		,     __a				:	Any		,     __a				:	Tuple		,     __a				:	Union[str, Any]							)			->  Optional[int]:


												"""simple docstring"""

												__lowercase      :							Tuple				=     self.num_labels
												__lowercase      :							Tuple				=     TFConvBertForTokenClassification(config=__a							)
												__lowercase      :							Dict				=     {
												    """input_ids""": input_ids,
												    """attention_mask""": input_mask,
												    """token_type_ids""": token_type_ids,
												}
												__lowercase      :							str				=     model(__a							)
												self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.seq_length, self.num_labels)							)



					def       lowerCAmelCase				(  self				:	List[Any]		,     __a				:	Optional[int]		,     __a				:	List[str]		,     __a				:	Optional[Any]		,     __a				:	int		,     __a				:	Tuple		,     __a				:	Any		,     __a				:	Union[str, Any]							)			->  List[Any]:


												"""simple docstring"""

												__lowercase      :							Any				=     TFConvBertForQuestionAnswering(config=__a							)
												__lowercase      :							str				=     {
												    """input_ids""": input_ids,
												    """attention_mask""": input_mask,
												    """token_type_ids""": token_type_ids,
												}

												__lowercase      :							List[Any]				=     model(__a							)
												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				:	Tuple							)			->  Tuple:


												"""simple docstring"""

												__lowercase      :							Tuple				=     self.prepare_config_and_inputs()
												(
												    (
												    __lowercase
												)			,			(
												    __lowercase
												)			,			(
												    __lowercase
												)			,			(
												    __lowercase
												)			,			(
												    __lowercase
												)			,			(
												    __lowercase
												)			,			(
												    __lowercase
												)			,			
												)      :							int				=     config_and_inputs
												__lowercase      :							Union[str, Any]				=     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
												return config, inputs_dict







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

					'''simple docstring'''

					_A						:			Dict									=      (
					    (
					        TFConvBertModel,
					        TFConvBertForMaskedLM,
					        TFConvBertForQuestionAnswering,
					        TFConvBertForSequenceClassification,
					        TFConvBertForTokenClassification,
					        TFConvBertForMultipleChoice,
					    )
					    if is_tf_available()
					    else ()
					)
					_A						:			str									=      (
					    {
					        '''feature-extraction''': TFConvBertModel,
					        '''fill-mask''': TFConvBertForMaskedLM,
					        '''question-answering''': TFConvBertForQuestionAnswering,
					        '''text-classification''': TFConvBertForSequenceClassification,
					        '''token-classification''': TFConvBertForTokenClassification,
					        '''zero-shot''': TFConvBertForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					_A						:			Union[str, Any]									=      False
					_A						:			List[str]									=      False
					_A						:			Dict									=      False



					def       lowerCAmelCase				(  self				:	List[str]							)			->  int:


												"""simple docstring"""

												__lowercase      :							int				=     TFConvBertModelTester(self							)
												__lowercase      :							Tuple				=     ConfigTester(self		,     config_class=__a		,     hidden_size=37							)



					def       lowerCAmelCase				(  self				:	Optional[int]							)			->  Optional[Any]:


												"""simple docstring"""

												self.config_tester.run_common_tests()



					def       lowerCAmelCase				(  self				:	Optional[Any]							)			->  Union[str, Any]:


												"""simple docstring"""

												__lowercase      :							Optional[Any]				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*__a							)



					def       lowerCAmelCase				(  self				:	Dict							)			->  Union[str, Any]:


												"""simple docstring"""

												__lowercase      :							Union[str, Any]				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_masked_lm(*__a							)



					def       lowerCAmelCase				(  self				:	Union[str, Any]							)			->  Union[str, Any]:


												"""simple docstring"""

												__lowercase      :							int				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_multiple_choice(*__a							)



					def       lowerCAmelCase				(  self				:	str							)			->  Any:


												"""simple docstring"""

												__lowercase      :							List[str]				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_question_answering(*__a							)



					def       lowerCAmelCase				(  self				:	str							)			->  str:


												"""simple docstring"""

												__lowercase      :							List[Any]				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_sequence_classification(*__a							)



					def       lowerCAmelCase				(  self				:	str							)			->  Any:


												"""simple docstring"""

												__lowercase      :							Optional[int]				=     self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_token_classification(*__a							)



					@slow
					def       lowerCAmelCase				(  self				:	str							)			->  Any:


												"""simple docstring"""

												__lowercase			,			__lowercase      :							Optional[int]				=     self.model_tester.prepare_config_and_inputs_for_common()
												__lowercase      :							Union[str, Any]				=     True
												__lowercase      :							List[Any]				=     True

												if hasattr(__a		,     """use_cache"""							):
																			__lowercase      :							Optional[Any]				=     True

												__lowercase      :							List[str]				=     getattr(self.model_tester		,     """encoder_seq_length"""		,     self.model_tester.seq_length							)
												__lowercase      :							int				=     getattr(self.model_tester		,     """key_length"""		,     __a							)

												for model_class in self.all_model_classes:
																			__lowercase      :							Optional[Any]				=     self._prepare_for_class(__a		,     __a							)
																			__lowercase      :							Tuple				=     model_class(__a							)
																			__lowercase      :							Tuple				=     len(model(__a							)							)

																			with tempfile.TemporaryDirectory() as tmpdirname:
																										model.save_pretrained(__a		,     saved_model=__a							)
																										__lowercase      :							List[Any]				=     os.path.join(__a		,     """saved_model"""		,     """1"""							)
																										__lowercase      :							str				=     tf.keras.models.load_model(__a							)
																										__lowercase      :							Optional[int]				=     model(__a							)

																										if self.is_encoder_decoder:
																																	__lowercase      :							Union[str, Any]				=     outputs["""encoder_hidden_states"""]
																																	__lowercase      :							Union[str, Any]				=     outputs["""encoder_attentions"""]
																										else:
																																	__lowercase      :							Union[str, Any]				=     outputs["""hidden_states"""]
																																	__lowercase      :							List[str]				=     outputs["""attentions"""]

																										self.assertEqual(len(__a							)		,     __a							)

																										__lowercase      :							List[Any]				=     getattr(
																										    self.model_tester		,     """expected_num_hidden_layers"""		,     self.model_tester.num_hidden_layers + 1							)

																										self.assertEqual(len(__a							)		,     __a							)
																										self.assertListEqual(
																										    list(output_hidden_states[0].shape[-2:]							)		,     [self.model_tester.seq_length, self.model_tester.hidden_size]		,     )

																										self.assertEqual(len(__a							)		,     self.model_tester.num_hidden_layers							)
																										self.assertListEqual(
																										    list(output_attentions[0].shape[-3:]							)		,     [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]		,     )



					@slow
					def       lowerCAmelCase				(  self				:	Union[str, Any]							)			->  List[Any]:


												"""simple docstring"""

												__lowercase      :							str				=     TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""							)
												self.assertIsNotNone(__a							)



					def       lowerCAmelCase				(  self				:	Any							)			->  List[Any]:


												"""simple docstring"""

												__lowercase			,			__lowercase      :							int				=     self.model_tester.prepare_config_and_inputs_for_common()
												__lowercase      :							List[str]				=     True
												__lowercase      :							List[Any]				=     getattr(self.model_tester		,     """decoder_seq_length"""		,     self.model_tester.seq_length							)
												__lowercase      :							Optional[int]				=     getattr(self.model_tester		,     """encoder_seq_length"""		,     self.model_tester.seq_length							)
												__lowercase      :							List[str]				=     getattr(self.model_tester		,     """key_length"""		,     __a							)
												__lowercase      :							List[Any]				=     getattr(self.model_tester		,     """key_length"""		,     __a							)

												def check_decoder_attentions_output(__a				:	List[str]							):
																			__lowercase      :							Union[str, Any]				=     len(__a							)
																			self.assertEqual(out_len % 2		,     0							)
																			__lowercase      :							Any				=     outputs.decoder_attentions
																			self.assertEqual(len(__a							)		,     self.model_tester.num_hidden_layers							)
																			self.assertListEqual(
																			    list(decoder_attentions[0].shape[-3:]							)		,     [self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]		,     )

												def check_encoder_attentions_output(__a				:	str							):
																			__lowercase      :							str				=     [
																			    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
																			]
																			self.assertEqual(len(__a							)		,     self.model_tester.num_hidden_layers							)
																			self.assertListEqual(
																			    list(attentions[0].shape[-3:]							)		,     [self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]		,     )

												for model_class in self.all_model_classes:
																			__lowercase      :							int				=     True
																			__lowercase      :							Any				=     False
																			__lowercase      :							List[Any]				=     model_class(__a							)
																			__lowercase      :							Tuple				=     model(self._prepare_for_class(__a		,     __a							)							)
																			__lowercase      :							Dict				=     len(__a							)
																			self.assertEqual(config.output_hidden_states		,     __a							)
																			check_encoder_attentions_output(__a							)

																			if self.is_encoder_decoder:
																										__lowercase      :							Any				=     model_class(__a							)
																										__lowercase      :							List[str]				=     model(self._prepare_for_class(__a		,     __a							)							)
																										self.assertEqual(config.output_hidden_states		,     __a							)
																										check_decoder_attentions_output(__a							)

																			# Check that output attentions can also be changed via the config
																			del inputs_dict["output_attentions"]
																			__lowercase      :							Dict				=     True
																			__lowercase      :							Optional[Any]				=     model_class(__a							)
																			__lowercase      :							Optional[int]				=     model(self._prepare_for_class(__a		,     __a							)							)
																			self.assertEqual(config.output_hidden_states		,     __a							)
																			check_encoder_attentions_output(__a							)

																			# Check attention is always last and order is fine
																			__lowercase      :							List[str]				=     True
																			__lowercase      :							List[Any]				=     True
																			__lowercase      :							Any				=     model_class(__a							)
																			__lowercase      :							Optional[int]				=     model(self._prepare_for_class(__a		,     __a							)							)

																			self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)		,     len(__a							)							)
																			self.assertEqual(model.config.output_hidden_states		,     __a							)
																			check_encoder_attentions_output(__a							)







@require_tf
class 		lowerCAmelCase     ( unittest.TestCase			):

					'''simple docstring'''

					@slow
					def       lowerCAmelCase				(  self				:	Dict							)			->  Union[str, Any]:


												"""simple docstring"""

												__lowercase      :							List[str]				=     TFConvBertModel.from_pretrained("""YituTech/conv-bert-base"""							)
												__lowercase      :							str				=     tf.constant([[0, 1, 2, 3, 4, 5]]							)
												__lowercase      :							Tuple				=     model(__a							)[0]

												__lowercase      :							Any				=     [1, 6, 768]
												self.assertEqual(output.shape		,     __a							)

												__lowercase      :							Optional[Any]				=     tf.constant(
												    [
												        [
												            [-0.03475493, -0.4686034, -0.30638832],
												            [0.22637248, -0.26988646, -0.7423424],
												            [0.10324868, -0.45013508, -0.58280784],
												        ]
												    ]							)
												tf.debugging.assert_near(output[:, :3, :3]		,     __a		,     atol=1E-4							)