


import collections
import os
import re
from pathlib import Path


__snake_case            =   "src/transformers"


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






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Optional[int]	):





			"""simple docstring"""




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






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Optional[Any]	):





			"""simple docstring"""




			with open(SCREAMING_SNAKE_CASE_       ,  """r"""       ,  encoding="""utf-8"""       ,  newline="""\n"""	) as f:
						UpperCamelCase         =					f.readlines()

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

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

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

			UpperCamelCase         =					{"""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.
						UpperCamelCase         =					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:
									UpperCamelCase         =					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

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

									UpperCamelCase         =					objects
						else:
									line_index += 1

    # At this stage we are in the TYPE_CHECKING part, first grab the objects without a specific backend
			UpperCamelCase         =					[]
			while (
			    line_index < len(SCREAMING_SNAKE_CASE_	)
			    and find_backend(lines[line_index]	) is None
			    and not lines[line_index].startswith("""else"""	)
			):
						UpperCamelCase         =					lines[line_index]
						UpperCamelCase         =					_re_import.search(SCREAMING_SNAKE_CASE_	)
						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

			UpperCamelCase         =					{"""none""": objects}
			# Let's continue with backend-specific objects
			while line_index < len(SCREAMING_SNAKE_CASE_	):
						# If the line is an if is_backend_available, we grab all objects associated.
						UpperCamelCase         =					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:
									UpperCamelCase         =					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

									UpperCamelCase         =					[]
									# Until we unindent, add backend objects to the list
									while len(lines[line_index]	) <= 1 or lines[line_index].startswith(""" """ * 8	):
												UpperCamelCase         =					lines[line_index]
												UpperCamelCase         =					_re_import.search(SCREAMING_SNAKE_CASE_	)
												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

									UpperCamelCase         =					objects
						else:
									line_index += 1

			return import_dict_objects, type_hint_objects






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		List[Any]       ,  SCREAMING_SNAKE_CASE_   :		Optional[Any]	):





			"""simple docstring"""




			def find_duplicates(SCREAMING_SNAKE_CASE_   :		Any	):
						return [k for k, v in collections.Counter(SCREAMING_SNAKE_CASE_	).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!"]

			UpperCamelCase         =					[]
			for key in import_dict_objects.keys():
						UpperCamelCase         =					find_duplicates(import_dict_objects[key]	)
						if duplicate_imports:
									errors.append(f'Duplicate _import_structure definitions for: {duplicate_imports}'	)
						UpperCamelCase         =					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]	)	):
									UpperCamelCase         =					"""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 							_lowercase    (		):





			"""simple docstring"""




			UpperCamelCase         =					[]
			for root, _, files in os.walk(SCREAMING_SNAKE_CASE_	):
						if "__init__.py" in files:
									UpperCamelCase         =					os.path.join(SCREAMING_SNAKE_CASE_       ,  """__init__.py"""	)
									UpperCamelCase         =					parse_init(SCREAMING_SNAKE_CASE_	)
									if objects is not None:
												UpperCamelCase         =					analyze_results(*SCREAMING_SNAKE_CASE_	)
												if len(SCREAMING_SNAKE_CASE_	) > 0:
															UpperCamelCase         =					f'Problem in {fname}, both halves do not define the same objects.\n{errors[0]}'
															failures.append("""\n""".join(SCREAMING_SNAKE_CASE_	)	)
			if len(SCREAMING_SNAKE_CASE_	) > 0:
						raise ValueError("""\n\n""".join(SCREAMING_SNAKE_CASE_	)	)






def 							_lowercase    (		):





			"""simple docstring"""




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


__snake_case            =   [
    "convert_pytorch_checkpoint_to_tf2",
    "modeling_flax_pytorch_utils",
    "models.esm.openfold_utils",
]






def 							_lowercase    (		):





			"""simple docstring"""




			from transformers.utils import direct_transformers_import

			UpperCamelCase         =					direct_transformers_import(SCREAMING_SNAKE_CASE_	)

			UpperCamelCase         =					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(SCREAMING_SNAKE_CASE_       ,  """__init__.py"""	)       ,  """r"""	) as f:
						UpperCamelCase         =					f.read()
			import_structure_keys.update(set(re.findall(r"""import_structure\[\"([^\"]*)\"\]"""       ,  SCREAMING_SNAKE_CASE_	)	)	)

			UpperCamelCase         =					[
			    module
			    for module in get_transformers_submodules()
			    if module not in IGNORE_SUBMODULES and module not in import_structure_keys
			]

			if len(SCREAMING_SNAKE_CASE_	) > 0:
						UpperCamelCase         =					"""\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()








import unittest

from transformers import BertGenerationConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import BertGenerationDecoder, BertGenerationEncoder




class    UpperCAmelCase					:




			def __init__(						self							:		Union[str, Any]       ,       __magic_name__							:		List[Any]       ,       __magic_name__							:		str=1_3       ,       __magic_name__							:		str=7       ,       __magic_name__							:		Optional[Any]=True       ,       __magic_name__							:		Optional[Any]=True       ,       __magic_name__							:		Tuple=9_9       ,       __magic_name__							:		List[str]=3_2       ,       __magic_name__							:		List[str]=5       ,       __magic_name__							:		int=4       ,       __magic_name__							:		Union[str, Any]=3_7       ,       __magic_name__							:		List[Any]="gelu"       ,       __magic_name__							:		Any=0.1       ,       __magic_name__							:		Union[str, Any]=0.1       ,       __magic_name__							:		List[Any]=5_0       ,       __magic_name__							:		Tuple=0.02       ,       __magic_name__							:		Optional[int]=True       ,       __magic_name__							:		Optional[Any]=None       ,       ):







						"""simple docstring"""







						UpperCamelCase         =					parent
						UpperCamelCase         =					batch_size
						UpperCamelCase         =					seq_length
						UpperCamelCase         =					is_training
						UpperCamelCase         =					use_input_mask
						UpperCamelCase         =					vocab_size
						UpperCamelCase         =					hidden_size
						UpperCamelCase         =					num_hidden_layers
						UpperCamelCase         =					num_attention_heads
						UpperCamelCase         =					intermediate_size
						UpperCamelCase         =					hidden_act
						UpperCamelCase         =					hidden_dropout_prob
						UpperCamelCase         =					attention_probs_dropout_prob
						UpperCamelCase         =					max_position_embeddings
						UpperCamelCase         =					initializer_range
						UpperCamelCase         =					use_labels
						UpperCamelCase         =					scope




			def   lowerCamelCase_					(						self							:		Optional[int]						):







						"""simple docstring"""







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

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

						if self.use_labels:
									UpperCamelCase         =					ids_tensor([self.batch_size, self.seq_length]       ,       self.vocab_size						)

						UpperCamelCase         =					self.get_config()

						return config, input_ids, input_mask, token_labels




			def   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						return BertGenerationConfig(
						    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       ,       is_decoder=__magic_name__       ,       initializer_range=self.initializer_range       ,       )




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







						"""simple docstring"""







						(
						    (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  
						)         =					self.prepare_config_and_inputs()

						UpperCamelCase         =					True
						UpperCamelCase         =					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
						UpperCamelCase         =					ids_tensor([self.batch_size, self.seq_length]       ,       vocab_size=2						)

						return (
						    config,
						    input_ids,
						    input_mask,
						    token_labels,
						    encoder_hidden_states,
						    encoder_attention_mask,
						)




			def   lowerCamelCase_					(						self							:		Tuple       ,       __magic_name__							:		List[Any]       ,       __magic_name__							:		Tuple       ,       __magic_name__							:		str       ,       __magic_name__							:		List[str]       ,       **__magic_name__							:		Optional[Any]       ,       ):







						"""simple docstring"""







						UpperCamelCase         =					BertGenerationEncoder(config=__magic_name__						)
						model.to(__magic_name__						)
						model.eval()
						UpperCamelCase         =					model(__magic_name__       ,       attention_mask=__magic_name__						)
						UpperCamelCase         =					model(__magic_name__						)
						self.parent.assertEqual(result.last_hidden_state.shape       ,       (self.batch_size, self.seq_length, self.hidden_size)						)




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       __magic_name__							:		Dict       ,       __magic_name__							:		str       ,       __magic_name__							:		Union[str, Any]       ,       __magic_name__							:		List[str]       ,       __magic_name__							:		Optional[Any]       ,       __magic_name__							:		Tuple       ,       **__magic_name__							:		Union[str, Any]       ,       ):







						"""simple docstring"""







						UpperCamelCase         =					True
						UpperCamelCase         =					BertGenerationEncoder(config=__magic_name__						)
						model.to(__magic_name__						)
						model.eval()
						UpperCamelCase         =					model(
						    __magic_name__       ,       attention_mask=__magic_name__       ,       encoder_hidden_states=__magic_name__       ,       encoder_attention_mask=__magic_name__       ,       )
						UpperCamelCase         =					model(
						    __magic_name__       ,       attention_mask=__magic_name__       ,       encoder_hidden_states=__magic_name__       ,       )
						self.parent.assertEqual(result.last_hidden_state.shape       ,       (self.batch_size, self.seq_length, self.hidden_size)						)




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       __magic_name__							:		Optional[Any]       ,       __magic_name__							:		str       ,       __magic_name__							:		List[str]       ,       __magic_name__							:		Optional[int]       ,       __magic_name__							:		str       ,       __magic_name__							:		Union[str, Any]       ,       **__magic_name__							:		Dict       ,       ):







						"""simple docstring"""







						UpperCamelCase         =					True
						UpperCamelCase         =					True
						UpperCamelCase         =					BertGenerationDecoder(config=__magic_name__						).to(__magic_name__						).eval()

						# first forward pass
						UpperCamelCase         =					model(
						    __magic_name__       ,       attention_mask=__magic_name__       ,       encoder_hidden_states=__magic_name__       ,       encoder_attention_mask=__magic_name__       ,       use_cache=__magic_name__       ,       )
						UpperCamelCase         =					outputs.past_key_values

						# create hypothetical multiple next token and extent to next_input_ids
						UpperCamelCase         =					ids_tensor((self.batch_size, 3)       ,       config.vocab_size						)
						UpperCamelCase         =					ids_tensor((self.batch_size, 3)       ,       vocab_size=2						)

						# append to next input_ids and
						UpperCamelCase         =					torch.cat([input_ids, next_tokens]       ,       dim=-1						)
						UpperCamelCase         =					torch.cat([input_mask, next_mask]       ,       dim=-1						)

						UpperCamelCase         =					model(
						    __magic_name__       ,       attention_mask=__magic_name__       ,       encoder_hidden_states=__magic_name__       ,       encoder_attention_mask=__magic_name__       ,       output_hidden_states=__magic_name__       ,       )["""hidden_states"""][0]
						UpperCamelCase         =					model(
						    __magic_name__       ,       attention_mask=__magic_name__       ,       encoder_hidden_states=__magic_name__       ,       encoder_attention_mask=__magic_name__       ,       past_key_values=__magic_name__       ,       output_hidden_states=__magic_name__       ,       )["""hidden_states"""][0]

						# select random slice
						UpperCamelCase         =					ids_tensor((1,)       ,       output_from_past.shape[-1]						).item()
						UpperCamelCase         =					output_from_no_past[:, -3:, random_slice_idx].detach()
						UpperCamelCase         =					output_from_past[:, :, random_slice_idx].detach()

						self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]						)

						# test that outputs are equal for slice
						self.parent.assertTrue(torch.allclose(__magic_name__       ,       __magic_name__       ,       atol=1e-3						)						)




			def   lowerCamelCase_					(						self							:		int       ,       __magic_name__							:		Any       ,       __magic_name__							:		List[str]       ,       __magic_name__							:		Union[str, Any]       ,       __magic_name__							:		List[Any]       ,       *__magic_name__							:		Optional[Any]       ,       ):







						"""simple docstring"""







						UpperCamelCase         =					BertGenerationDecoder(__magic_name__						)
						model.to(__magic_name__						)
						model.eval()
						UpperCamelCase         =					model(__magic_name__       ,       attention_mask=__magic_name__       ,       labels=__magic_name__						)
						self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.seq_length, self.vocab_size)						)





			def   lowerCamelCase_					(						self							:		List[Any]						):







						"""simple docstring"""







						UpperCamelCase  ,  UpperCamelCase  ,  UpperCamelCase  ,  UpperCamelCase         =					self.prepare_config_and_inputs()
						UpperCamelCase         =					{"""input_ids""": input_ids, """attention_mask""": input_mask}
						return config, inputs_dict




@require_torch
class    UpperCAmelCase					(       __snake_case      , __snake_case      , __snake_case      , unittest.TestCase    ):
			lowercase						= (BertGenerationEncoder, BertGenerationDecoder) if is_torch_available() else ()
			lowercase						= (BertGenerationDecoder,) if is_torch_available() else ()
			lowercase						= (
			    {"""feature-extraction""": BertGenerationEncoder, """text-generation""": BertGenerationDecoder}
			    if is_torch_available()
			    else {}
			)




			def   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







						UpperCamelCase         =					BertGenerationEncoderTester(self						)
						UpperCamelCase         =					ConfigTester(self       ,       config_class=__magic_name__       ,       hidden_size=3_7						)




			def   lowerCamelCase_					(						self							:		Optional[int]						):







						"""simple docstring"""







						self.config_tester.run_common_tests()




			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__magic_name__						)




			def   lowerCamelCase_					(						self							:		List[str]						):







						"""simple docstring"""







						UpperCamelCase  ,  UpperCamelCase  ,  UpperCamelCase  ,  UpperCamelCase         =					self.model_tester.prepare_config_and_inputs()
						UpperCamelCase         =					"""bert"""
						self.model_tester.create_and_check_model(__magic_name__       ,       __magic_name__       ,       __magic_name__       ,       __magic_name__						)




			def   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs_for_decoder()
						self.model_tester.create_and_check_model_as_decoder(*__magic_name__						)




			def   lowerCamelCase_					(						self							:		List[Any]						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs_for_decoder()
						self.model_tester.create_and_check_decoder_model_past_large_inputs(*__magic_name__						)




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						(
						    (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  (
						    UpperCamelCase
						)  ,  
						)         =					self.model_tester.prepare_config_and_inputs_for_decoder()

						UpperCamelCase         =					None

						self.model_tester.create_and_check_model_as_decoder(
						    __magic_name__       ,       __magic_name__       ,       __magic_name__       ,       __magic_name__       ,       __magic_name__       ,       __magic_name__       ,       )




			def   lowerCamelCase_					(						self							:		str						):







						"""simple docstring"""







						UpperCamelCase         =					self.model_tester.prepare_config_and_inputs_for_decoder()
						self.model_tester.create_and_check_for_causal_lm(*__magic_name__						)





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







						"""simple docstring"""







						UpperCamelCase         =					BertGenerationEncoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""						)
						self.assertIsNotNone(__magic_name__						)




@require_torch
class    UpperCAmelCase					(       unittest.TestCase    ):




			@slow
			def   lowerCamelCase_					(						self							:		Tuple						):







						"""simple docstring"""







						UpperCamelCase         =					BertGenerationEncoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""						)
						UpperCamelCase         =					torch.tensor([[1_0_1, 7_5_9_2, 1_0_1_0, 2_0_2_6, 3_8_9_9, 2_0_0_3, 1_0_1_4_0, 1_0_2]]						)
						with torch.no_grad():
									UpperCamelCase         =					model(__magic_name__						)[0]
						UpperCamelCase         =					torch.Size([1, 8, 1_0_2_4]						)
						self.assertEqual(output.shape       ,       __magic_name__						)
						UpperCamelCase         =					torch.tensor(
						    [[[0.1_775, 0.0_083, -0.0_321], [1.6_002, 0.1_287, 0.3_912], [2.1_473, 0.5_791, 0.6_066]]]						)
						self.assertTrue(torch.allclose(output[:, :3, :3]       ,       __magic_name__       ,       atol=1e-4						)						)




@require_torch
class    UpperCAmelCase					(       unittest.TestCase    ):




			@slow
			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					BertGenerationDecoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""						)
						UpperCamelCase         =					torch.tensor([[1_0_1, 7_5_9_2, 1_0_1_0, 2_0_2_6, 3_8_9_9, 2_0_0_3, 1_0_1_4_0, 1_0_2]]						)
						with torch.no_grad():
									UpperCamelCase         =					model(__magic_name__						)[0]
						UpperCamelCase         =					torch.Size([1, 8, 5_0_3_5_8]						)
						self.assertEqual(output.shape       ,       __magic_name__						)
						UpperCamelCase         =					torch.tensor(
						    [[[-0.5_788, -2.5_994, -3.7_054], [0.0_438, 4.7_997, 1.8_795], [1.5_862, 6.6_409, 4.4_638]]]						)
						self.assertTrue(torch.allclose(output[:, :3, :3]       ,       __magic_name__       ,       atol=1e-4						)						)




