
import inspect
import unittest

from datasets import load_dataset
from packaging import version

from transformers import BeitConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch
			from torch import nn

			from transformers import (
			    MODEL_MAPPING,
			    BeitForImageClassification,
			    BeitForMaskedImageModeling,
			    BeitForSemanticSegmentation,
			    BeitModel,
			)
			from transformers.models.beit.modeling_beit import BEIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			import PIL
			from PIL import Image

			from transformers import BeitImageProcessor





class 			_lowerCAmelCase      :




				def __init__(      self       ,       _UpperCamelCase       ,       _UpperCamelCase=100       ,       _UpperCamelCase=13       ,       _UpperCamelCase=30       ,       _UpperCamelCase=2       ,       _UpperCamelCase=3       ,       _UpperCamelCase=True       ,       _UpperCamelCase=True       ,       _UpperCamelCase=32       ,       _UpperCamelCase=4       ,       _UpperCamelCase=4       ,       _UpperCamelCase=37       ,       _UpperCamelCase="gelu"       ,       _UpperCamelCase=0.1       ,       _UpperCamelCase=0.1       ,       _UpperCamelCase=10       ,       _UpperCamelCase=0.02       ,       _UpperCamelCase=3       ,       _UpperCamelCase=None       ,       _UpperCamelCase=[0, 1, 2, 3]       ,       )       ->   Any:
							lowerCAmelCase_      			=			parent
							lowerCAmelCase_      			=			100
							lowerCAmelCase_      			=			batch_size
							lowerCAmelCase_      			=			image_size
							lowerCAmelCase_      			=			patch_size
							lowerCAmelCase_      			=			num_channels
							lowerCAmelCase_      			=			is_training
							lowerCAmelCase_      			=			use_labels
							lowerCAmelCase_      			=			hidden_size
							lowerCAmelCase_      			=			num_hidden_layers
							lowerCAmelCase_      			=			num_attention_heads
							lowerCAmelCase_      			=			intermediate_size
							lowerCAmelCase_      			=			hidden_act
							lowerCAmelCase_      			=			hidden_dropout_prob
							lowerCAmelCase_      			=			attention_probs_dropout_prob
							lowerCAmelCase_      			=			type_sequence_label_size
							lowerCAmelCase_      			=			initializer_range
							lowerCAmelCase_      			=			scope
							lowerCAmelCase_      			=			out_indices
							lowerCAmelCase_      			=			num_labels

							# in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
							lowerCAmelCase_      			=			(image_size // patch_size) ** 2
							lowerCAmelCase_      			=			num_patches + 1




				def   __a		(      self  )       ->   str:
							lowerCAmelCase_      			=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )

							lowerCAmelCase_      			=			None
							lowerCAmelCase_      			=			None
							if self.use_labels:
										lowerCAmelCase_      			=			ids_tensor([self.batch_size]       ,       self.type_sequence_label_size  )
										lowerCAmelCase_      			=			ids_tensor([self.batch_size, self.image_size, self.image_size]       ,       self.num_labels  )

							lowerCAmelCase_      			=			self.get_config()

							return config, pixel_values, labels, pixel_labels




				def   __a		(      self  )       ->   int:
							return BeitConfig(
							    vocab_size=self.vocab_size       ,       image_size=self.image_size       ,       patch_size=self.patch_size       ,       num_channels=self.num_channels       ,       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       ,       is_decoder=_a       ,       initializer_range=self.initializer_range       ,       out_indices=self.out_indices       ,       )




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase  )       ->   str:
							lowerCAmelCase_      			=			BeitModel(config=_a  )
							model.to(_a  )
							model.eval()
							lowerCAmelCase_      			=			model(_a  )
							self.parent.assertEqual(result.last_hidden_state.shape       ,       (self.batch_size, self.seq_length, self.hidden_size)  )




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase  )       ->   List[Any]:
							lowerCAmelCase_      			=			BeitForMaskedImageModeling(config=_a  )
							model.to(_a  )
							model.eval()
							lowerCAmelCase_      			=			model(_a  )
							self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.seq_length - 1, self.vocab_size)  )




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase  )       ->   str:
							lowerCAmelCase_      			=			self.type_sequence_label_size
							lowerCAmelCase_      			=			BeitForImageClassification(_a  )
							model.to(_a  )
							model.eval()
							lowerCAmelCase_      			=			model(_a       ,       labels=_a  )
							self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.type_sequence_label_size)  )

							# test greyscale images
							lowerCAmelCase_      			=			1
							lowerCAmelCase_      			=			BeitForImageClassification(_a  )
							model.to(_a  )
							model.eval()

							lowerCAmelCase_      			=			floats_tensor([self.batch_size, 1, self.image_size, self.image_size]  )
							lowerCAmelCase_      			=			model(_a       ,       labels=_a  )
							self.parent.assertEqual(result.logits.shape       ,       (self.batch_size, self.type_sequence_label_size)  )




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase  )       ->   Tuple:
							lowerCAmelCase_      			=			self.num_labels
							lowerCAmelCase_      			=			BeitForSemanticSegmentation(_a  )
							model.to(_a  )
							model.eval()
							lowerCAmelCase_      			=			model(_a  )
							self.parent.assertEqual(
							    result.logits.shape       ,       (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)  )
							lowerCAmelCase_      			=			model(_a       ,       labels=_a  )
							self.parent.assertEqual(
							    result.logits.shape       ,       (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)  )




				def   __a		(      self  )       ->   List[Any]:
							lowerCAmelCase_      			=			self.prepare_config_and_inputs()
							lowerCAmelCase_      			=			config_and_inputs
							lowerCAmelCase_      			=			{"""pixel_values""": pixel_values}
							return config, inputs_dict





@require_torch
class 			_lowerCAmelCase      (			UpperCamelCase__      ,   UpperCamelCase__      ,   unittest.TestCase ):
				_lowercase    	=(
				    (BeitModel, BeitForImageClassification, BeitForMaskedImageModeling, BeitForSemanticSegmentation)
				    if is_torch_available()
				    else ()
				)
				_lowercase    	=(
				    {
				        '''feature-extraction''': BeitModel,
				        '''image-classification''': BeitForImageClassification,
				        '''image-segmentation''': BeitForSemanticSegmentation,
				    }
				    if is_torch_available()
				    else {}
				)

				_lowercase    	=False
				_lowercase    	=False
				_lowercase    	=False




				def   __a		(      self  )       ->   Dict:
							lowerCAmelCase_      			=			BeitModelTester(self  )
							lowerCAmelCase_      			=			ConfigTester(self       ,       config_class=_a       ,       has_text_modality=_a       ,       hidden_size=37  )




				def   __a		(      self  )       ->   Dict:
							self.config_tester.run_common_tests()




				@unittest.skip(reason="BEiT does not use inputs_embeds"  )
				def   __a		(      self  )       ->   Any:
							pass




				@require_torch_multi_gpu
				@unittest.skip(reason="BEiT has some layers using `add_module` which doesn't work well with `nn.DataParallel`"  )
				def   __a		(      self  )       ->   Union[str, Any]:
							pass




				def   __a		(      self  )       ->   Dict:
							lowerCAmelCase_      			=			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
										lowerCAmelCase_      			=			model_class(_a  )
										self.assertIsInstance(model.get_input_embeddings()       ,       (nn.Module)  )
										lowerCAmelCase_      			=			model.get_output_embeddings()
										self.assertTrue(x is None or isinstance(_a       ,       nn.Linear  )  )




				def   __a		(      self  )       ->   Any:
							lowerCAmelCase_      			=			self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
										lowerCAmelCase_      			=			model_class(_a  )
										lowerCAmelCase_      			=			inspect.signature(model.forward  )
										# signature.parameters is an OrderedDict => so arg_names order is deterministic
										lowerCAmelCase_      			=			[*signature.parameters.keys()]

										lowerCAmelCase_      			=			["""pixel_values"""]
										self.assertListEqual(arg_names[:1]       ,       _a  )




				def   __a		(      self  )       ->   Optional[int]:
							lowerCAmelCase_      			=			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_a  )




				def   __a		(      self  )       ->   Tuple:
							lowerCAmelCase_      			=			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*_a  )




				def   __a		(      self  )       ->   List[Any]:
							lowerCAmelCase_      			=			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*_a  )




				def   __a		(      self  )       ->   Dict:
							lowerCAmelCase_      			=			self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_semantic_segmentation(*_a  )




				def   __a		(      self  )       ->   Tuple:
							if not self.model_tester.is_training:
										return

							lowerCAmelCase_      			=			self.model_tester.prepare_config_and_inputs_for_common()
							lowerCAmelCase_      			=			True

							for model_class in self.all_model_classes:
										# we don't test BeitForMaskedImageModeling
										if model_class in [*get_values(_a  ), BeitForMaskedImageModeling]:
													continue

										lowerCAmelCase_      			=			model_class(_a  )
										model.to(_a  )
										model.train()
										lowerCAmelCase_      			=			self._prepare_for_class(_a       ,       _a       ,       return_labels=_a  )
										lowerCAmelCase_      			=			model(**_a  ).loss
										loss.backward()




				def   __a		(      self  )       ->   Dict:
							lowerCAmelCase_      			=			self.model_tester.prepare_config_and_inputs_for_common()
							if not self.model_tester.is_training:
										return

							lowerCAmelCase_      			=			False
							lowerCAmelCase_      			=			True

							for model_class in self.all_model_classes:
										# we don't test BeitForMaskedImageModeling
										if (
										    model_class in [*get_values(_a  ), BeitForMaskedImageModeling]
										    or not model_class.supports_gradient_checkpointing
										):
													continue

										lowerCAmelCase_      			=			model_class(_a  )
										model.gradient_checkpointing_enable()
										model.to(_a  )
										model.train()
										lowerCAmelCase_      			=			self._prepare_for_class(_a       ,       _a       ,       return_labels=_a  )
										lowerCAmelCase_      			=			model(**_a  ).loss
										loss.backward()




				def   __a		(      self  )       ->   List[str]:
							lowerCAmelCase_      			=			self.model_tester.prepare_config_and_inputs_for_common()

							lowerCAmelCase_      			=			_config_zero_init(_a  )
							for model_class in self.all_model_classes:
										lowerCAmelCase_      			=			model_class(config=_a  )
										for name, param in model.named_parameters():
													# we skip lambda parameters as these require special initial values
													# determined by config.layer_scale_init_value
													if "lambda" in name:
																continue
													if param.requires_grad:
																self.assertIn(
																    ((param.data.mean() * 1e9).round() / 1e9).item()       ,       [0.0, 1.0]       ,       msg=f"""Parameter {name} of model {model_class} seems not properly initialized"""       ,       )




				@slow
				def   __a		(      self  )       ->   Union[str, Any]:
							for model_name in BEIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowerCAmelCase_      			=			BeitModel.from_pretrained(_a  )
										self.assertIsNotNone(_a  )






def      lowerCamelCase__       (       ):




			"""simple docstring"""


			lowerCAmelCase_      			=			Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"       )
			return image





@require_torch
@require_vision
class 			_lowerCAmelCase      (			unittest.TestCase ):




				@cached_property
				def   __a		(      self  )       ->   Any:
							return BeitImageProcessor.from_pretrained("microsoft/beit-base-patch16-224"  ) if is_vision_available() else None




				@slow
				def   __a		(      self  )       ->   str:
							lowerCAmelCase_      			=			BeitForMaskedImageModeling.from_pretrained("microsoft/beit-base-patch16-224-pt22k"  ).to(_a  )

							lowerCAmelCase_      			=			self.default_image_processor
							lowerCAmelCase_      			=			prepare_img()
							lowerCAmelCase_      			=			image_processor(images=_a       ,       return_tensors="pt"  ).pixel_values.to(_a  )

							# prepare bool_masked_pos
							lowerCAmelCase_      			=			torch.ones((1, 196)       ,       dtype=torch.bool  ).to(_a  )

							# forward pass
							with torch.no_grad():
										lowerCAmelCase_      			=			model(pixel_values=_a       ,       bool_masked_pos=_a  )
							lowerCAmelCase_      			=			outputs.logits

							# verify the logits
							lowerCAmelCase_      			=			torch.Size((1, 196, 8_192)  )
							self.assertEqual(logits.shape       ,       _a  )

							lowerCAmelCase_      			=			torch.tensor(
							    [[-3.2437, 0.5072, -13.9174], [-3.2456, 0.4948, -13.9401], [-3.2033, 0.5121, -13.8550]]  ).to(_a  )

							self.assertTrue(torch.allclose(logits[bool_masked_pos][:3, :3]       ,       _a       ,       atol=1e-2  )  )




				@slow
				def   __a		(      self  )       ->   List[str]:
							lowerCAmelCase_      			=			BeitForImageClassification.from_pretrained("microsoft/beit-base-patch16-224"  ).to(_a  )

							lowerCAmelCase_      			=			self.default_image_processor
							lowerCAmelCase_      			=			prepare_img()
							lowerCAmelCase_      			=			image_processor(images=_a       ,       return_tensors="pt"  ).to(_a  )

							# forward pass
							with torch.no_grad():
										lowerCAmelCase_      			=			model(**_a  )
							lowerCAmelCase_      			=			outputs.logits

							# verify the logits
							lowerCAmelCase_      			=			torch.Size((1, 1_000)  )
							self.assertEqual(logits.shape       ,       _a  )

							lowerCAmelCase_      			=			torch.tensor([-1.2385, -1.0987, -1.0108]  ).to(_a  )

							self.assertTrue(torch.allclose(logits[0, :3]       ,       _a       ,       atol=1e-4  )  )

							lowerCAmelCase_      			=			281
							self.assertEqual(logits.argmax(-1  ).item()       ,       _a  )




				@slow
				def   __a		(      self  )       ->   Dict:
							lowerCAmelCase_      			=			BeitForImageClassification.from_pretrained("microsoft/beit-large-patch16-224-pt22k-ft22k"  ).to(
							    _a  )

							lowerCAmelCase_      			=			self.default_image_processor
							lowerCAmelCase_      			=			prepare_img()
							lowerCAmelCase_      			=			image_processor(images=_a       ,       return_tensors="pt"  ).to(_a  )

							# forward pass
							with torch.no_grad():
										lowerCAmelCase_      			=			model(**_a  )
							lowerCAmelCase_      			=			outputs.logits

							# verify the logits
							lowerCAmelCase_      			=			torch.Size((1, 21_841)  )
							self.assertEqual(logits.shape       ,       _a  )

							lowerCAmelCase_      			=			torch.tensor([1.6881, -0.2787, 0.5901]  ).to(_a  )

							self.assertTrue(torch.allclose(logits[0, :3]       ,       _a       ,       atol=1e-4  )  )

							lowerCAmelCase_      			=			2_396
							self.assertEqual(logits.argmax(-1  ).item()       ,       _a  )




				@slow
				def   __a		(      self  )       ->   str:
							lowerCAmelCase_      			=			BeitForSemanticSegmentation.from_pretrained("microsoft/beit-base-finetuned-ade-640-640"  )
							lowerCAmelCase_      			=			model.to(_a  )

							lowerCAmelCase_      			=			BeitImageProcessor(do_resize=_a       ,       size=640       ,       do_center_crop=_a  )

							lowerCAmelCase_      			=			load_dataset("hf-internal-testing/fixtures_ade20k"       ,       split="test"  )
							lowerCAmelCase_      			=			Image.open(ds[0]["file"]  )
							lowerCAmelCase_      			=			image_processor(images=_a       ,       return_tensors="pt"  ).to(_a  )

							# forward pass
							with torch.no_grad():
										lowerCAmelCase_      			=			model(**_a  )
							lowerCAmelCase_      			=			outputs.logits

							# verify the logits
							lowerCAmelCase_      			=			torch.Size((1, 150, 160, 160)  )
							self.assertEqual(logits.shape       ,       _a  )

							lowerCAmelCase_      			=			version.parse(PIL.__version__  ) < version.parse("9.0.0"  )

							if is_pillow_less_than_a:
										lowerCAmelCase_      			=			torch.tensor(
										    [
										        [[-4.9225, -2.3954, -3.0522], [-2.8822, -1.0046, -1.7561], [-2.9549, -1.3228, -2.1347]],
										        [[-5.8168, -3.4129, -4.0778], [-3.8651, -2.2214, -3.0277], [-3.8356, -2.4643, -3.3535]],
										        [[-0.0078, 3.9952, 4.0754], [2.9856, 4.6944, 5.0035], [3.2413, 4.7813, 4.9969]],
										    ]       ,       device=_a       ,       )
							else:
										lowerCAmelCase_      			=			torch.tensor(
										    [
										        [[-4.8960, -2.3688, -3.0355], [-2.8478, -0.9836, -1.7418], [-2.9449, -1.3332, -2.1456]],
										        [[-5.8081, -3.4124, -4.1006], [-3.8561, -2.2081, -3.0323], [-3.8365, -2.4601, -3.3669]],
										        [[-0.0309, 3.9868, 4.0540], [2.9640, 4.6877, 4.9976], [3.2081, 4.7690, 4.9942]],
										    ]       ,       device=_a       ,       )

							self.assertTrue(torch.allclose(logits[0, :3, :3, :3]       ,       _a       ,       atol=1e-4  )  )




				@slow
				def   __a		(      self  )       ->   int:
							lowerCAmelCase_      			=			BeitForSemanticSegmentation.from_pretrained("microsoft/beit-base-finetuned-ade-640-640"  )
							lowerCAmelCase_      			=			model.to(_a  )

							lowerCAmelCase_      			=			BeitImageProcessor(do_resize=_a       ,       size=640       ,       do_center_crop=_a  )

							lowerCAmelCase_      			=			load_dataset("hf-internal-testing/fixtures_ade20k"       ,       split="test"  )
							lowerCAmelCase_      			=			Image.open(ds[0]["file"]  )
							lowerCAmelCase_      			=			image_processor(images=_a       ,       return_tensors="pt"  ).to(_a  )

							# forward pass
							with torch.no_grad():
										lowerCAmelCase_      			=			model(**_a  )

							lowerCAmelCase_      			=			outputs.logits.detach().cpu()

							lowerCAmelCase_      			=			image_processor.post_process_semantic_segmentation(outputs=_a       ,       target_sizes=[(500, 300)]  )
							lowerCAmelCase_      			=			torch.Size((500, 300)  )
							self.assertEqual(segmentation[0].shape       ,       _a  )

							lowerCAmelCase_      			=			image_processor.post_process_semantic_segmentation(outputs=_a  )
							lowerCAmelCase_      			=			torch.Size((160, 160)  )
							self.assertEqual(segmentation[0].shape       ,       _a  )





import os
import re
import shutil
import sys
import tempfile
import unittest

import black


_A     =  os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, "utils"))

import check_copies  # noqa: E402


# This is the reference code that will be used in the tests.
# If BertLMPredictionHead is changed in modeling_bert.py, this code needs to be manually updated.
_A     =  "    def __init__(self, config):\n        super().__init__()\n        self.transform = BertPredictionHeadTransform(config)\n\n        # The output weights are the same as the input embeddings, but there is\n        # an output-only bias for each token.\n        self.decoder = nn.Linear(config.hidden_size, config.vocab_size, bias=False)\n\n        self.bias = nn.Parameter(torch.zeros(config.vocab_size))\n\n        # Need a link between the two variables so that the bias is correctly resized with `resize_token_embeddings`\n        self.decoder.bias = self.bias\n\n    def forward(self, hidden_states):\n        hidden_states = self.transform(hidden_states)\n        hidden_states = self.decoder(hidden_states)\n        return hidden_states\n"





class 			_lowerCAmelCase      (			unittest.TestCase ):




				def   __a		(      self  )       ->   Any:
							lowerCAmelCase_      			=			tempfile.mkdtemp()
							os.makedirs(os.path.join(self.transformer_dir       ,       "models/bert/"  )  )
							lowerCAmelCase_      			=			self.transformer_dir
							shutil.copy(
							    os.path.join(_UpperCamelCase       ,       "src/transformers/models/bert/modeling_bert.py"  )       ,       os.path.join(self.transformer_dir       ,       "models/bert/modeling_bert.py"  )       ,       )




				def   __a		(      self  )       ->   List[Any]:
							lowerCAmelCase_      			=			"src/transformers"
							shutil.rmtree(self.transformer_dir  )




				def   __a		(      self       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase       ,       _UpperCamelCase=None  )       ->   Optional[int]:
							lowerCAmelCase_      			=			comment + f"""\nclass {class_name}(nn.Module):\n""" + class_code
							if overwrite_result is not None:
										lowerCAmelCase_      			=			comment + f"""\nclass {class_name}(nn.Module):\n""" + overwrite_result
							lowerCAmelCase_      			=			black.Mode(target_versions={black.TargetVersion.PYaa}       ,       line_length=119  )
							lowerCAmelCase_      			=			black.format_str(_UpperCamelCase       ,       mode=_UpperCamelCase  )
							lowerCAmelCase_      			=			os.path.join(self.transformer_dir       ,       "new_code.py"  )
							with open(_UpperCamelCase       ,       "w"       ,       newline="\n"  ) as f:
										f.write(_UpperCamelCase  )
							if overwrite_result is None:
										self.assertTrue(len(check_copies.is_copy_consistent(_UpperCamelCase  )  ) == 0  )
							else:
										check_copies.is_copy_consistent(f.name       ,       overwrite=_UpperCamelCase  )
										with open(_UpperCamelCase       ,       "r"  ) as f:
													self.assertTrue(f.read()       ,       _UpperCamelCase  )




				def   __a		(      self  )       ->   Any:
							lowerCAmelCase_      			=			check_copies.find_code_in_transformers("models.bert.modeling_bert.BertLMPredictionHead"  )
							self.assertEqual(_UpperCamelCase       ,       _UpperCamelCase  )




				def   __a		(      self  )       ->   Any:
							# Base copy consistency
							self.check_copy_consistency(
							    "# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead"       ,       "BertLMPredictionHead"       ,       REFERENCE_CODE + "\n"       ,       )

							# With no empty line at the end
							self.check_copy_consistency(
							    "# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead"       ,       "BertLMPredictionHead"       ,       _UpperCamelCase       ,       )

							# Copy consistency with rename
							self.check_copy_consistency(
							    "# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel"       ,       "TestModelLMPredictionHead"       ,       re.sub("Bert"       ,       "TestModel"       ,       _UpperCamelCase  )       ,       )

							# Copy consistency with a really long name
							lowerCAmelCase_      			=			"TestModelWithAReallyLongNameBecauseSomePeopleLikeThatForSomeReason"
							self.check_copy_consistency(
							    f"""# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->{long_class_name}"""       ,       f"""{long_class_name}LMPredictionHead"""       ,       re.sub("Bert"       ,       _UpperCamelCase       ,       _UpperCamelCase  )       ,       )

							# Copy consistency with overwrite
							self.check_copy_consistency(
							    "# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel"       ,       "TestModelLMPredictionHead"       ,       _UpperCamelCase       ,       overwrite_result=re.sub("Bert"       ,       "TestModel"       ,       _UpperCamelCase  )       ,       )




				def   __a		(      self  )       ->   Any:
							lowerCAmelCase_      			=			check_copies.LOCALIZED_READMES["README_zh-hans.md"]

							lowerCAmelCase_      			=			(
							    "1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the"
							    " Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for"
							    " Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong"
							    " Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut.\n1."
							    " **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (from HuggingFace),"
							    " released together with the paper [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and"
							    " lighter](https://arxiv.org/abs/1910.01108) by Victor Sanh, Lysandre Debut and Thomas Wolf. The same"
							    " method has been applied to compress GPT2 into"
							    " [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into"
							    " [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),"
							    " Multilingual BERT into"
							    " [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German"
							    " version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)**"
							    " (from Google Research/Stanford University) released with the paper [ELECTRA: Pre-training text encoders"
							    " as discriminators rather than generators](https://arxiv.org/abs/2003.10555) by Kevin Clark, Minh-Thang"
							    " Luong, Quoc V. Le, Christopher D. Manning."
							)
							lowerCAmelCase_      			=			(
							    "1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"
							    " Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"
							    " Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"
							    " Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"
							)
							lowerCAmelCase_      			=			(
							    "1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"
							    " Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"
							    " Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"
							    " Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n1."
							    " **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (来自 HuggingFace) 伴随论文"
							    " [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and"
							    " lighter](https://arxiv.org/abs/1910.01108) 由 Victor Sanh, Lysandre Debut and Thomas Wolf 发布。 The same"
							    " method has been applied to compress GPT2 into"
							    " [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into"
							    " [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),"
							    " Multilingual BERT into"
							    " [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German"
							    " version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)** (来自"
							    " Google Research/Stanford University) 伴随论文 [ELECTRA: Pre-training text encoders as discriminators rather"
							    " than generators](https://arxiv.org/abs/2003.10555) 由 Kevin Clark, Minh-Thang Luong, Quoc V. Le,"
							    " Christopher D. Manning 发布。\n"
							)

							lowerCAmelCase_			,						lowerCAmelCase_      			=			check_copies.convert_to_localized_md(
							    _UpperCamelCase       ,       _UpperCamelCase       ,       localized_readme["format_model_list"]  )

							self.assertFalse(_UpperCamelCase  )
							self.assertEqual(_UpperCamelCase       ,       _UpperCamelCase  )

							lowerCAmelCase_			,						lowerCAmelCase_      			=			check_copies.convert_to_localized_md(
							    _UpperCamelCase       ,       _UpperCamelCase       ,       localized_readme["format_model_list"]  )

							# Check whether the number of models is equal to README.md after conversion.
							self.assertTrue(_UpperCamelCase  )

							lowerCAmelCase_      			=			(
							    "1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the"
							    " Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for"
							    " Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong"
							    " Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut."
							)
							lowerCAmelCase_      			=			(
							    "1. **[ALBERT](https://huggingface.co/transformers/main/model_doc/albert.html)** (来自 Google Research and"
							    " the Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"
							    " Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"
							    " Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"
							)
							lowerCAmelCase_      			=			(
							    "1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"
							    " Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"
							    " Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"
							    " Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"
							)

							lowerCAmelCase_			,						lowerCAmelCase_      			=			check_copies.convert_to_localized_md(
							    _UpperCamelCase       ,       _UpperCamelCase       ,       localized_readme["format_model_list"]  )

							# Check if the model link is synchronized.
							self.assertEqual(_UpperCamelCase       ,       _UpperCamelCase  )



