




import collections
import os
import re
from pathlib import Path


__lowerCamelCase :      Union[str, Any]										=				'src/transformers'


# Matches is_xxx_available()
__lowerCamelCase :      int										=				re.compile(R"""is\_([a-z_]*)_available()""")
# Catches a one-line _import_struct = {xxx}
__lowerCamelCase :      List[Any]										=				re.compile(R"""^_import_structure\s+=\s+\{([^\}]+)\}""")
# Catches a line with a key-values pattern: "bla": ["foo", "bar"]
__lowerCamelCase :      Dict										=				re.compile(R"""\s+\"\S*\":\s+\[([^\]]*)\]""")
# Catches a line if not is_foo_available
__lowerCamelCase :      int										=				re.compile(R"""^\s*if\s+not\s+is\_[a-z_]*\_available\(\)""")
# Catches a line _import_struct["bla"].append("foo")
__lowerCamelCase :      Any										=				re.compile(R"""^\s*_import_structure\[\"\S*\"\]\.append\(\"(\S*)\"\)""")
# Catches a line _import_struct["bla"].extend(["foo", "bar"]) or _import_struct["bla"] = ["foo", "bar"]
__lowerCamelCase :      List[str]										=				re.compile(R"""^\s*_import_structure\[\S*\](?:\.extend\(|\s*=\s+)\[([^\]]*)\]""")
# Catches a line with an object between quotes and a comma:     "MyModel",
__lowerCamelCase :      List[Any]										=				re.compile(R"""^\s+\"([^\"]+)\",""")
# Catches a line with objects between brackets only:    ["foo", "bar"],
__lowerCamelCase :      Optional[int]										=				re.compile(R"""^\s+\[([^\]]+)\]""")
# Catches a line with from foo import bar, bla, boo
__lowerCamelCase :      int										=				re.compile(R"""\s+from\s+\S*\s+import\s+([^\(\s].*)\n""")
# Catches a line with try:
__lowerCamelCase :      Union[str, Any]										=				re.compile(R"""^\s*try:""")
# Catches a line with else:
__lowerCamelCase :      Optional[Any]										=				re.compile(R"""^\s*else:""")







def 					SCREAMING_SNAKE_CASE    (			snake_case_ :							Union[str, Any]       ):


	if _re_test_backend.search(lowerCAmelCase__       ) is None:
		return None
	snake_case__			:				Any       =  [b[0] for b in _re_backend.findall(lowerCAmelCase__       )]
	backends.sort()
	return "_and_".join(lowerCAmelCase__       )







def 					SCREAMING_SNAKE_CASE    (			snake_case_ :							List[str]       ):


	with open(lowerCAmelCase__					,  "r"					,  encoding="utf-8"					,  newline="\n"       ) as f:
		snake_case__			:				Optional[int]       =  f.readlines()

	snake_case__			:				int       =  0
	while line_index < len(lowerCAmelCase__       ) and not lines[line_index].startswith("_import_structure = {"       ):
		line_index += 1

	# If this is a traditional init, just return.
	if line_index >= len(lowerCAmelCase__       ):
		return None

	# First grab the objects without a specific backend in _import_structure
	snake_case__			:				Optional[int]       =  []
	while not lines[line_index].startswith("if TYPE_CHECKING"       ) and find_backend(lines[line_index]       ) is None:
		snake_case__			:				List[Any]       =  lines[line_index]
		# If we have everything on a single line, let's deal with it.
		if _re_one_line_import_struct.search(lowerCAmelCase__       ):
			snake_case__			:				Optional[int]       =  _re_one_line_import_struct.search(lowerCAmelCase__       ).groups()[0]
			snake_case__			:				Union[str, Any]       =  re.findall(R"\[([^\]]+)\]"					,  lowerCAmelCase__       )
			for imp in imports:
				objects.extend([obj[1:-1] for obj in imp.split(", "       )]       )
			line_index += 1
			continue
		snake_case__			:				int       =  _re_import_struct_key_value.search(lowerCAmelCase__       )
		if single_line_import_search is not None:
			snake_case__			:				str       =  [obj[1:-1] for obj in single_line_import_search.groups()[0].split(", "       ) if len(lowerCAmelCase__       ) > 0]
			objects.extend(lowerCAmelCase__       )
		elif line.startswith(" " * 8 + "\""       ):
			objects.append(line[9:-3]       )
		line_index += 1

	snake_case__			:				Any       =  {"""none""": objects}
	# Let's continue with backend-specific objects in _import_structure
	while not lines[line_index].startswith("if TYPE_CHECKING"       ):
		# If the line is an if not is_backend_available, we grab all objects associated.
		snake_case__			:				Optional[int]       =  find_backend(lines[line_index]       )
		# Check if the backend declaration is inside a try block:
		if _re_try.search(lines[line_index - 1]       ) is None:
			snake_case__			:				Tuple       =  None

		if backend is not None:
			line_index += 1

			# Scroll until we hit the else block of try-except-else
			while _re_else.search(lines[line_index]       ) is None:
				line_index += 1

			line_index += 1

			snake_case__			:				Dict       =  []
			# Until we unindent, add backend objects to the list
			while len(lines[line_index]       ) <= 1 or lines[line_index].startswith(" " * 4       ):
				snake_case__			:				int       =  lines[line_index]
				if _re_import_struct_add_one.search(lowerCAmelCase__       ) is not None:
					objects.append(_re_import_struct_add_one.search(lowerCAmelCase__       ).groups()[0]       )
				elif _re_import_struct_add_many.search(lowerCAmelCase__       ) is not None:
					snake_case__			:				Optional[Any]       =  _re_import_struct_add_many.search(lowerCAmelCase__       ).groups()[0].split(", "       )
					snake_case__			:				int       =  [obj[1:-1] for obj in imports if len(lowerCAmelCase__       ) > 0]
					objects.extend(lowerCAmelCase__       )
				elif _re_between_brackets.search(lowerCAmelCase__       ) is not None:
					snake_case__			:				Optional[Any]       =  _re_between_brackets.search(lowerCAmelCase__       ).groups()[0].split(", "       )
					snake_case__			:				List[Any]       =  [obj[1:-1] for obj in imports if len(lowerCAmelCase__       ) > 0]
					objects.extend(lowerCAmelCase__       )
				elif _re_quote_object.search(lowerCAmelCase__       ) is not None:
					objects.append(_re_quote_object.search(lowerCAmelCase__       ).groups()[0]       )
				elif line.startswith(" " * 8 + "\""       ):
					objects.append(line[9:-3]       )
				elif line.startswith(" " * 12 + "\""       ):
					objects.append(line[13:-3]       )
				line_index += 1

			snake_case__			:				List[Any]       =  objects
		else:
			line_index += 1

    # At this stage we are in the TYPE_CHECKING part, first grab the objects without a specific backend
	snake_case__			:				Optional[Any]       =  []
	while (
	    line_index < len(lowerCAmelCase__       )
	    and find_backend(lines[line_index]       ) is None
	    and not lines[line_index].startswith("else"       )
	):
		snake_case__			:				int       =  lines[line_index]
		snake_case__			:				Any       =  _re_import.search(lowerCAmelCase__       )
		if single_line_import_search is not None:
			objects.extend(single_line_import_search.groups()[0].split(", "       )       )
		elif line.startswith(" " * 8       ):
			objects.append(line[8:-2]       )
		line_index += 1

	snake_case__			:				str       =  {"""none""": objects}
	# Let's continue with backend-specific objects
	while line_index < len(lowerCAmelCase__       ):
		# If the line is an if is_backend_available, we grab all objects associated.
		snake_case__			:				Tuple       =  find_backend(lines[line_index]       )
		# Check if the backend declaration is inside a try block:
		if _re_try.search(lines[line_index - 1]       ) is None:
			snake_case__			:				Dict       =  None

		if backend is not None:
			line_index += 1

			# Scroll until we hit the else block of try-except-else
			while _re_else.search(lines[line_index]       ) is None:
				line_index += 1

			line_index += 1

			snake_case__			:				List[str]       =  []
			# Until we unindent, add backend objects to the list
			while len(lines[line_index]       ) <= 1 or lines[line_index].startswith(" " * 8       ):
				snake_case__			:				int       =  lines[line_index]
				snake_case__			:				Tuple       =  _re_import.search(lowerCAmelCase__       )
				if single_line_import_search is not None:
					objects.extend(single_line_import_search.groups()[0].split(", "       )       )
				elif line.startswith(" " * 12       ):
					objects.append(line[12:-2]       )
				line_index += 1

			snake_case__			:				Optional[Any]       =  objects
		else:
			line_index += 1

	return import_dict_objects, type_hint_objects







def 					SCREAMING_SNAKE_CASE    (			snake_case_ :							Any					,  snake_case_ :							List[str]       ):


	def find_duplicates(snake_case_ :							Dict       ):
		return [k for k, v in collections.Counter(lowerCAmelCase__       ).items() if v > 1]

	if list(import_dict_objects.keys()       ) != list(type_hint_objects.keys()       ):
		return ["Both sides of the init do not have the same backends!"]

	snake_case__			:				str       =  []
	for key in import_dict_objects.keys():
		snake_case__			:				Any       =  find_duplicates(import_dict_objects[key]       )
		if duplicate_imports:
			errors.append(F'''Duplicate _import_structure definitions for: {duplicate_imports}'''       )
		snake_case__			:				Optional[Any]       =  find_duplicates(type_hint_objects[key]       )
		if duplicate_type_hints:
			errors.append(F'''Duplicate TYPE_CHECKING objects for: {duplicate_type_hints}'''       )

		if sorted(set(import_dict_objects[key]       )       ) != sorted(set(type_hint_objects[key]       )       ):
			snake_case__			:				Union[str, Any]       =  """base imports""" if key == """none""" else F'''{key} backend'''
			errors.append(F'''Differences for {name}:'''       )
			for a in type_hint_objects[key]:
				if a not in import_dict_objects[key]:
					errors.append(F'''  {a} in TYPE_HINT but not in _import_structure.'''       )
			for a in import_dict_objects[key]:
				if a not in type_hint_objects[key]:
					errors.append(F'''  {a} in _import_structure but not in TYPE_HINT.'''       )
	return errors







def 					SCREAMING_SNAKE_CASE    (			):
	snake_case__			:				Tuple       =  []
	for root, _, files in os.walk(lowerCAmelCase__       ):
		if "__init__.py" in files:
			snake_case__			:				List[Any]       =  os.path.join(lowerCAmelCase__					,  "__init__.py"       )
			snake_case__			:				Any       =  parse_init(lowerCAmelCase__       )
			if objects is not None:
				snake_case__			:				Union[str, Any]       =  analyze_results(*lowerCAmelCase__       )
				if len(lowerCAmelCase__       ) > 0:
					snake_case__			:				int       =  F'''Problem in {fname}, both halves do not define the same objects.\n{errors[0]}'''
					failures.append("\n".join(lowerCAmelCase__       )       )
	if len(lowerCAmelCase__       ) > 0:
		raise ValueError("\n\n".join(lowerCAmelCase__       )       )







def 					SCREAMING_SNAKE_CASE    (			):
	snake_case__			:				Union[str, Any]       =  []
	for path, directories, files in os.walk(lowerCAmelCase__       ):
		for folder in directories:
			# Ignore private modules
			if folder.startswith("_"       ):
				directories.remove(lowerCAmelCase__       )
				continue
			# Ignore leftovers from branches (empty folders apart from pycache)
			if len(list((Path(lowerCAmelCase__       ) / folder).glob("*.py"       )       )       ) == 0:
				continue
			snake_case__			:				Any       =  str((Path(lowerCAmelCase__       ) / folder).relative_to(lowerCAmelCase__       )       )
			snake_case__			:				Union[str, Any]       =  short_path.replace(os.path.sep					,  "."       )
			submodules.append(lowerCAmelCase__       )
		for fname in files:
			if fname == "__init__.py":
				continue
			snake_case__			:				Optional[Any]       =  str((Path(lowerCAmelCase__       ) / fname).relative_to(lowerCAmelCase__       )       )
			snake_case__			:				Dict       =  short_path.replace(".py"					,  ""       ).replace(os.path.sep					,  "."       )
			if len(submodule.split("."       )       ) == 1:
				submodules.append(lowerCAmelCase__       )
	return submodules


__lowerCamelCase :      str										=				[
    'convert_pytorch_checkpoint_to_tf2',
    'modeling_flax_pytorch_utils',
    'models.esm.openfold_utils',
]







def 					SCREAMING_SNAKE_CASE    (			):
	from transformers.utils import direct_transformers_import

	snake_case__			:				Union[str, Any]       =  direct_transformers_import(lowerCAmelCase__       )

	snake_case__			:				List[str]       =  set(transformers._import_structure.keys()       )
	# This contains all the base keys of the _import_structure object defined in the init, but if the user is missing
	# some optional dependencies, they may not have all of them. Thus we read the init to read all additions and
	# (potentiall re-) add them.
	with open(os.path.join(lowerCAmelCase__					,  "__init__.py"       )					,  "r"       ) as f:
		snake_case__			:				Optional[Any]       =  f.read()
	import_structure_keys.update(set(re.findall(R"import_structure\[\"([^\"]*)\"\]"					,  lowerCAmelCase__       )       )       )

	snake_case__			:				List[str]       =  [
	    module
	    for module in get_transformers_submodules()
	    if module not in IGNORE_SUBMODULES and module not in import_structure_keys
	]

	if len(lowerCAmelCase__       ) > 0:
		snake_case__			:				str       =  """\n""".join(F'''- {module}''' for module in module_not_registered       )
		raise ValueError(
		    "The following submodules are not properly registed in the main init of Transformers:\n"
		    F'''{list_of_modules}\n'''
		    "Make sure they appear somewhere in the keys of `_import_structure` with an empty list as value."       )


if __name__ == "__main__":
	check_all_inits()
	check_submodules()











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





					"""simple docstring"""






					def __init__( self					:  Union[str, Any]							,		__A					:  str							,		__A					:  Optional[Any]=1_3							,		__A					:  Dict=7							,		__A					:  List[str]=True							,		__A					:  Any=True							,		__A					:  str=True							,		__A					:  Optional[Any]=True							,		__A					:  List[str]=9_9							,		__A					:  Dict=3_2							,		__A					:  Tuple=2							,		__A					:  Tuple=4							,		__A					:  Dict=3_7							,		__A					:  Tuple="gelu"							,		__A					:  Any=0.1							,		__A					:  str=0.1							,		__A					:  int=5_1_2							,		__A					:  Union[str, Any]=1_6							,		__A					:  Optional[int]=2							,		__A					:  Union[str, Any]=0.0_2							,		__A					:  Tuple=3							,		__A					:  Union[str, Any]=4							,		__A					:  Optional[int]=None							,		):
						snake_case__			:				Optional[int]       =  parent
						snake_case__			:				Optional[Any]       =  1_3
						snake_case__			:				int       =  7
						snake_case__			:				Optional[int]       =  True
						snake_case__			:				Optional[Any]       =  True
						snake_case__			:				List[str]       =  True
						snake_case__			:				int       =  True
						snake_case__			:				Optional[int]       =  9_9
						snake_case__			:				Union[str, Any]       =  3_8_4
						snake_case__			:				Optional[Any]       =  2
						snake_case__			:				Union[str, Any]       =  4
						snake_case__			:				Any       =  3_7
						snake_case__			:				Any       =  "gelu"
						snake_case__			:				str       =  0.1
						snake_case__			:				Optional[Any]       =  0.1
						snake_case__			:				Union[str, Any]       =  5_1_2
						snake_case__			:				Optional[Any]       =  1_6
						snake_case__			:				List[Any]       =  2
						snake_case__			:				Optional[int]       =  0.0_2
						snake_case__			:				Dict       =  3
						snake_case__			:				Any       =  4
						snake_case__			:				int       =  1_2_8
						snake_case__			:				Dict       =  2
						snake_case__			:				Any       =  9
						snake_case__			:				List[str]       =  1
						snake_case__			:				List[Any]       =  None



					def 	_lowercase					( self					:  List[str]	):
						snake_case__			:				Optional[int]       =  ids_tensor([self.batch_size, self.seq_length]							,		self.vocab_size	)

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

						snake_case__			:				Union[str, Any]       =  None
						if self.use_token_type_ids:
							snake_case__			:				Tuple       =  ids_tensor([self.batch_size, self.seq_length]							,		self.type_vocab_size	)

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

						snake_case__			:				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 	_lowercase					( self					:  Dict							,		__A					:  Dict							,		__A					:  Dict							,		__A					:  Union[str, Any]							,		__A					:  Optional[int]							,		__A					:  Any							,		__A					:  Union[str, Any]							,		__A					:  Tuple	):
						snake_case__			:				Optional[int]       =  TFConvBertModel(config=__A	)
						snake_case__			:				Optional[int]       =  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

						snake_case__			:				List[str]       =  [input_ids, input_mask]
						snake_case__			:				Union[str, Any]       =  model(__A	)

						snake_case__			:				str       =  model(__A	)

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



					def 	_lowercase					( self					:  Union[str, Any]							,		__A					:  List[Any]							,		__A					:  Any							,		__A					:  Union[str, Any]							,		__A					:  int							,		__A					:  Optional[Any]							,		__A					:  Dict							,		__A					:  Optional[int]	):
						snake_case__			:				List[str]       =  TFConvBertForMaskedLM(config=__A	)
						snake_case__			:				Any       =  {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						    "token_type_ids": token_type_ids,
						}
						snake_case__			:				int       =  model(__A	)
						self.parent.assertEqual(result.logits.shape							,		(self.batch_size, self.seq_length, self.vocab_size)	)



					def 	_lowercase					( self					:  Tuple							,		__A					:  Union[str, Any]							,		__A					:  List[Any]							,		__A					:  Any							,		__A					:  List[Any]							,		__A					:  List[Any]							,		__A					:  Optional[int]							,		__A					:  List[str]	):
						snake_case__			:				Any       =  self.num_labels
						snake_case__			:				List[Any]       =  TFConvBertForSequenceClassification(config=__A	)
						snake_case__			:				Any       =  {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						    "token_type_ids": token_type_ids,
						}

						snake_case__			:				Optional[int]       =  model(__A	)
						self.parent.assertEqual(result.logits.shape							,		(self.batch_size, self.num_labels)	)



					def 	_lowercase					( self					:  int							,		__A					:  List[Any]							,		__A					:  Union[str, Any]							,		__A					:  Optional[Any]							,		__A					:  List[Any]							,		__A					:  Union[str, Any]							,		__A					:  Union[str, Any]							,		__A					:  Optional[int]	):
						snake_case__			:				Optional[Any]       =  self.num_choices
						snake_case__			:				Any       =  TFConvBertForMultipleChoice(config=__A	)
						snake_case__			:				Optional[int]       =  tf.tile(tf.expand_dims(__A							,		1	)							,		(1, self.num_choices, 1)	)
						snake_case__			:				Optional[Any]       =  tf.tile(tf.expand_dims(__A							,		1	)							,		(1, self.num_choices, 1)	)
						snake_case__			:				Optional[int]       =  tf.tile(tf.expand_dims(__A							,		1	)							,		(1, self.num_choices, 1)	)
						snake_case__			:				int       =  {
						    "input_ids": multiple_choice_inputs_ids,
						    "attention_mask": multiple_choice_input_mask,
						    "token_type_ids": multiple_choice_token_type_ids,
						}
						snake_case__			:				Optional[Any]       =  model(__A	)
						self.parent.assertEqual(result.logits.shape							,		(self.batch_size, self.num_choices)	)



					def 	_lowercase					( self					:  List[str]							,		__A					:  Tuple							,		__A					:  str							,		__A					:  Union[str, Any]							,		__A					:  Union[str, Any]							,		__A					:  Any							,		__A					:  int							,		__A					:  Tuple	):
						snake_case__			:				Dict       =  self.num_labels
						snake_case__			:				str       =  TFConvBertForTokenClassification(config=__A	)
						snake_case__			:				Optional[Any]       =  {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						    "token_type_ids": token_type_ids,
						}
						snake_case__			:				List[str]       =  model(__A	)
						self.parent.assertEqual(result.logits.shape							,		(self.batch_size, self.seq_length, self.num_labels)	)



					def 	_lowercase					( self					:  Optional[int]							,		__A					:  Union[str, Any]							,		__A					:  List[Any]							,		__A					:  List[str]							,		__A					:  Any							,		__A					:  Any							,		__A					:  Optional[int]							,		__A					:  Optional[Any]	):
						snake_case__			:				Any       =  TFConvBertForQuestionAnswering(config=__A	)
						snake_case__			:				List[str]       =  {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						    "token_type_ids": token_type_ids,
						}

						snake_case__			:				int       =  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 	_lowercase					( self					:  Any	):
						snake_case__			:				List[Any]       =  self.prepare_config_and_inputs()
						(
						    (
						    snake_case__
						),						(
						    snake_case__
						),						(
						    snake_case__
						),						(
						    snake_case__
						),						(
						    snake_case__
						),						(
						    snake_case__
						),						(
						    snake_case__
						),						
						)			:				List[str]       =  config_and_inputs
						snake_case__			:				Tuple       =  {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
						return config, inputs_dict



@require_tf
class 							SCREAMING_SNAKE_CASE__						(    UpperCamelCase_			,       UpperCamelCase_			,       unittest.TestCase						):





					"""simple docstring"""






					a_     =		(
					    (
					        TFConvBertModel,
					        TFConvBertForMaskedLM,
					        TFConvBertForQuestionAnswering,
					        TFConvBertForSequenceClassification,
					        TFConvBertForTokenClassification,
					        TFConvBertForMultipleChoice,
					    )
					    if is_tf_available()
					    else ()
					)
					a_     =		(
					    {
					        "feature-extraction": TFConvBertModel,
					        "fill-mask": TFConvBertForMaskedLM,
					        "question-answering": TFConvBertForQuestionAnswering,
					        "text-classification": TFConvBertForSequenceClassification,
					        "token-classification": TFConvBertForTokenClassification,
					        "zero-shot": TFConvBertForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					a_     =		False
					a_     =		False
					a_     =		False



					def 	_lowercase					( self					:  int	):
						snake_case__			:				Optional[Any]       =  TFConvBertModelTester(self	)
						snake_case__			:				List[str]       =  ConfigTester(self							,		config_class=__A							,		hidden_size=3_7	)



					def 	_lowercase					( self					:  List[Any]	):
						self.config_tester.run_common_tests()



					def 	_lowercase					( self					:  Any	):
						snake_case__			:				List[str]       =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__A	)



					def 	_lowercase					( self					:  Union[str, Any]	):
						snake_case__			:				Any       =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*__A	)



					def 	_lowercase					( self					:  Dict	):
						snake_case__			:				str       =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*__A	)



					def 	_lowercase					( self					:  Optional[Any]	):
						snake_case__			:				List[str]       =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*__A	)



					def 	_lowercase					( self					:  Optional[int]	):
						snake_case__			:				int       =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*__A	)



					def 	_lowercase					( self					:  Dict	):
						snake_case__			:				Any       =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*__A	)



					@slow
					def 	_lowercase					( self					:  Dict	):
						snake_case__,						snake_case__			:				Tuple       =  self.model_tester.prepare_config_and_inputs_for_common()
						snake_case__			:				int       =  True
						snake_case__			:				int       =  True

						if hasattr(__A							,		"use_cache"	):
							snake_case__			:				Optional[Any]       =  True

						snake_case__			:				Dict       =  getattr(self.model_tester							,		"encoder_seq_length"							,		self.model_tester.seq_length	)
						snake_case__			:				List[str]       =  getattr(self.model_tester							,		"key_length"							,		__A	)

						for model_class in self.all_model_classes:
							snake_case__			:				Tuple       =  self._prepare_for_class(__A							,		__A	)
							snake_case__			:				List[str]       =  model_class(__A	)
							snake_case__			:				List[Any]       =  len(model(__A	)	)

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

								if self.is_encoder_decoder:
									snake_case__			:				Tuple       =  outputs["encoder_hidden_states"]
									snake_case__			:				str       =  outputs["encoder_attentions"]
								else:
									snake_case__			:				Dict       =  outputs["hidden_states"]
									snake_case__			:				Tuple       =  outputs["attentions"]

								self.assertEqual(len(__A	)							,		__A	)

								snake_case__			:				int       =  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 	_lowercase					( self					:  Tuple	):
						snake_case__			:				Optional[Any]       =  TFConvBertModel.from_pretrained("YituTech/conv-bert-base"	)
						self.assertIsNotNone(__A	)






					def 	_lowercase					( self					:  List[str]	):
						snake_case__,						snake_case__			:				Optional[Any]       =  self.model_tester.prepare_config_and_inputs_for_common()
						snake_case__			:				Optional[Any]       =  True
						snake_case__			:				List[Any]       =  getattr(self.model_tester							,		"decoder_seq_length"							,		self.model_tester.seq_length	)
						snake_case__			:				int       =  getattr(self.model_tester							,		"encoder_seq_length"							,		self.model_tester.seq_length	)
						snake_case__			:				Any       =  getattr(self.model_tester							,		"key_length"							,		__A	)
						snake_case__			:				List[Any]       =  getattr(self.model_tester							,		"key_length"							,		__A	)

						def check_decoder_attentions_output(__A					:  Optional[int]	):
							snake_case__			:				Optional[Any]       =  len(__A	)
							self.assertEqual(out_len % 2							,		0	)
							snake_case__			:				Optional[int]       =  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					:  Any	):
							snake_case__			:				List[Any]       =  [
							    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:
							snake_case__			:				Optional[int]       =  True
							snake_case__			:				Any       =  False
							snake_case__			:				Dict       =  model_class(__A	)
							snake_case__			:				List[Any]       =  model(self._prepare_for_class(__A							,		__A	)	)
							snake_case__			:				Dict       =  len(__A	)
							self.assertEqual(config.output_hidden_states							,		__A	)
							check_encoder_attentions_output(__A	)

							if self.is_encoder_decoder:
								snake_case__			:				str       =  model_class(__A	)
								snake_case__			:				List[Any]       =  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"]
							snake_case__			:				Optional[int]       =  True
							snake_case__			:				Optional[Any]       =  model_class(__A	)
							snake_case__			:				Union[str, Any]       =  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
							snake_case__			:				Optional[int]       =  True
							snake_case__			:				List[Any]       =  True
							snake_case__			:				Any       =  model_class(__A	)
							snake_case__			:				str       =  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 							SCREAMING_SNAKE_CASE__						(    unittest.TestCase						):





					"""simple docstring"""






					@slow
					def 	_lowercase					( self					:  int	):
						snake_case__			:				int       =  TFConvBertModel.from_pretrained("YituTech/conv-bert-base"	)
						snake_case__			:				int       =  tf.constant([[0, 1, 2, 3, 4, 5]]	)
						snake_case__			:				str       =  model(__A	)[0]

						snake_case__			:				int       =  [1, 6, 7_6_8]
						self.assertEqual(output.shape							,		__A	)

						snake_case__			:				List[Any]       =  tf.constant(
						    [
						        [
						            [-0.0_3_4_7_5_4_9_3, -0.4_6_8_6_0_3_4, -0.3_0_6_3_8_8_3_2],
						            [0.2_2_6_3_7_2_4_8, -0.2_6_9_8_8_6_4_6, -0.7_4_2_3_4_2_4],
						            [0.1_0_3_2_4_8_6_8, -0.4_5_0_1_3_5_0_8, -0.5_8_2_8_0_7_8_4],
						        ]
						    ]	)
						tf.debugging.assert_near(output[:, :3, :3]							,		__A							,		atol=1e-4	)



