





'''simple docstring'''





import io
import os
import unicodedata
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


_a						=   logging.get_logger(__name__)

_a						=   "▁"

_a						=   {"vocab_file": "vocab.txt", "sentencepiece_model_ckpt": "sentencepiece.bpe.model"}

_a						=   {
    "sentencepiece_model_file": "sentencepiece.bpe.model",
    "vocab_file": "vocab.txt",
}

_a						=   {
    "vocab_file": {
        "ernie-m-base": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt",
        "ernie-m-large": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt",
    },
    "sentencepiece_model_file": {
        "ernie-m-base": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model",
        "ernie-m-large": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model",
    },
}

_a						=   {
    "ernie-m-base": 514,
    "ernie-m-large": 514,
}

_a						=   {
    "ernie-m-base": {"do_lower_case": False},
    "ernie-m-large": {"do_lower_case": False},
}






class       __A					(					lowerCAmelCase				):

			'''simple docstring'''







			lowerCAmelCase_							  =		["""input_ids"""]

			lowerCAmelCase_							  =		VOCAB_FILES_NAMES
			lowerCAmelCase_							  =		PRETRAINED_INIT_CONFIGURATION
			lowerCAmelCase_							  =		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			lowerCAmelCase_							  =		PRETRAINED_VOCAB_FILES_MAP
			lowerCAmelCase_							  =		RESOURCE_FILES_NAMES





			def __init__(					self ,						__lowerCAmelCase ,						__lowerCAmelCase=None ,						__lowerCAmelCase=False ,						__lowerCAmelCase="utf8" ,						__lowerCAmelCase="[UNK]" ,						__lowerCAmelCase="[SEP]" ,						__lowerCAmelCase="[PAD]" ,						__lowerCAmelCase="[CLS]" ,						__lowerCAmelCase="[MASK]" ,						__lowerCAmelCase = None ,						**__lowerCAmelCase ,						):



				'''simple docstring'''







				lowerCamelCase__              =	{} if sp_model_kwargs is None else sp_model_kwargs
				super().__init__(
				    do_lower_case=__lowerCAmelCase ,						unk_token=__lowerCAmelCase ,						sep_token=__lowerCAmelCase ,						pad_token=__lowerCAmelCase ,						cls_token=__lowerCAmelCase ,						mask_token=__lowerCAmelCase ,						vocab_file=__lowerCAmelCase ,						encoding=__lowerCAmelCase ,						sp_model_kwargs=self.sp_model_kwargs ,						**__lowerCAmelCase ,						)
				lowerCamelCase__              =	do_lower_case
				lowerCamelCase__              =	sentencepiece_model_ckpt
				lowerCamelCase__              =	spm.SentencePieceProcessor(**self.sp_model_kwargs							)
				self.sp_model.Load(__lowerCAmelCase							)

				# to mimic paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer functioning
				if vocab_file is not None:
					lowerCamelCase__              =	self.load_vocab(filepath=__lowerCAmelCase							)
				else:
					lowerCamelCase__              =	{self.sp_model.id_to_piece(__lowerCAmelCase							): id for id in range(self.sp_model.get_piece_size()							)}
				lowerCamelCase__              =	{v: k for k, v in self.vocab.items()}





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				if text is None:
					return None

				lowerCamelCase__              =	self.tokenize(__lowerCAmelCase							)
				lowerCamelCase__       ,			lowerCamelCase__              =	'''''', []

				for i, ch in enumerate(__lowerCAmelCase							):
					if ch in self.SP_CHAR_MAPPING:
						lowerCamelCase__              =	self.SP_CHAR_MAPPING.get(__lowerCAmelCase							)
					else:
						lowerCamelCase__              =	unicodedata.normalize('''NFKC''' ,						__lowerCAmelCase							)
					if self.is_whitespace(__lowerCAmelCase							):
						continue
					normalized_text += ch
					char_mapping.extend([i] * len(__lowerCAmelCase							)							)

				lowerCamelCase__       ,			lowerCamelCase__       ,			lowerCamelCase__              =	normalized_text, [], 0

				if self.do_lower_case:
					lowerCamelCase__              =	text.lower()

				for token in split_tokens:
					if token[:1] == "▁":
						lowerCamelCase__              =	token[1:]
					lowerCamelCase__              =	text[offset:].index(__lowerCAmelCase							) + offset
					lowerCamelCase__              =	start + len(__lowerCAmelCase							)

					token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)							)
					lowerCamelCase__              =	end
				return token_mapping





			@property
			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				return len(self.vocab							)





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				return dict(self.vocab ,						**self.added_tokens_encoder							)





			def __getstate__(					self							):



				'''simple docstring'''







				lowerCamelCase__              =	self.__dict__.copy()
				lowerCamelCase__              =	None
				return state





			def __setstate__(					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__              =	d

				# for backward compatibility
				if not hasattr(self ,						'''sp_model_kwargs'''							):
					lowerCamelCase__              =	{}

				lowerCamelCase__              =	spm.SentencePieceProcessor(**self.sp_model_kwargs							)
				self.sp_model.Load(self.sentencepiece_model_ckpt							)





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				return "".join((self.SP_CHAR_MAPPING.get(__lowerCAmelCase ,						__lowerCAmelCase							) for c in text)							)





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase=False ,						__lowerCAmelCase=6_4 ,						__lowerCAmelCase=0.1							):



				'''simple docstring'''







				if self.sp_model_kwargs.get('''enable_sampling'''							) is True:
					lowerCamelCase__              =	True
				if self.sp_model_kwargs.get('''alpha'''							) is not None:
					lowerCamelCase__              =	self.sp_model_kwargs.get('''alpha'''							)
				if self.sp_model_kwargs.get('''nbest_size'''							) is not None:
					lowerCamelCase__              =	self.sp_model_kwargs.get('''nbest_size'''							)

				if not enable_sampling:
					lowerCamelCase__              =	self.sp_model.EncodeAsPieces(__lowerCAmelCase							)
				else:
					lowerCamelCase__              =	self.sp_model.SampleEncodeAsPieces(__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase							)
				lowerCamelCase__              =	[]
				for pi, piece in enumerate(__lowerCAmelCase							):
					if piece == SPIECE_UNDERLINE:
						if not pieces[pi + 1].startswith(__lowerCAmelCase							) and pi != 0:
							new_pieces.append(__lowerCAmelCase							)
							continue
						else:
							continue
					lowerCamelCase__              =	0
					for i, chunk in enumerate(__lowerCAmelCase							):
						if chunk == SPIECE_UNDERLINE:
							continue
						if self.is_ch_char(__lowerCAmelCase							) or self.is_punct(__lowerCAmelCase							):
							if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
								new_pieces.append(piece[lst_i:i]							)
							new_pieces.append(__lowerCAmelCase							)
							lowerCamelCase__              =	i + 1
						elif chunk.isdigit() and i > 0 and not piece[i - 1].isdigit():
							if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
								new_pieces.append(piece[lst_i:i]							)
							lowerCamelCase__              =	i
						elif not chunk.isdigit() and i > 0 and piece[i - 1].isdigit():
							if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
								new_pieces.append(piece[lst_i:i]							)
							lowerCamelCase__              =	i
					if len(__lowerCAmelCase							) > lst_i:
						new_pieces.append(piece[lst_i:]							)
				return new_pieces





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__              =	''''''.join(__lowerCAmelCase							).replace(__lowerCAmelCase ,						''' '''							).strip()
				return out_string





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__              =	self.convert_ids_to_tokens(__lowerCAmelCase							)
				lowerCamelCase__              =	''''''.join(__lowerCAmelCase							).replace(__lowerCAmelCase ,						''' '''							).strip()
				return out_string





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				return self.vocab.get(__lowerCAmelCase ,						self.vocab.get(self.unk_token							)							)





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				return self.reverse_vocab.get(__lowerCAmelCase ,						self.unk_token							)





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase=None							):



				'''simple docstring'''







				if token_ids_a is None:
					return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
				lowerCamelCase__              =	[self.cls_token_id]
				lowerCamelCase__              =	[self.sep_token_id]
				return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase=None							):



				'''simple docstring'''







				if offset_mapping_a is None:
					return [(0, 0)] + offset_mapping_a + [(0, 0)]

				return [(0, 0)] + offset_mapping_a + [(0, 0), (0, 0)] + offset_mapping_a + [(0, 0)]





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase=None ,						__lowerCAmelCase=False							):



				'''simple docstring'''







				if already_has_special_tokens:
					if token_ids_a is not None:
						raise ValueError(
						    '''You should not supply a second sequence if the provided sequence of '''
						    '''ids is already formatted with special tokens for the model.'''							)
					return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

				if token_ids_a is not None:
					return [1] + ([0] * len(__lowerCAmelCase							)) + [1, 1] + ([0] * len(__lowerCAmelCase							)) + [1]
				return [1] + ([0] * len(__lowerCAmelCase							)) + [1]





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase = None							):



				'''simple docstring'''







				if token_ids_a is None:
					# [CLS] X [SEP]
					return (len(__lowerCAmelCase							) + 2) * [0]

				# [CLS] A [SEP] [SEP] B [SEP]
				return [0] * (len(__lowerCAmelCase							) + 1) + [1] * (len(__lowerCAmelCase							) + 3)





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				if "\u4e00" <= char <= "\u9fff":
					return True
				return False





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				if ("a" <= char <= "z") or ("A" <= char <= "Z"):
					return True
				return False





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				if char in ",;:.?!~，；：。？！《》【】":
					return True
				return False





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				if char == " " or char == "\t" or char == "\n" or char == "\r":
					return True
				if len(__lowerCAmelCase							) == 1:
					lowerCamelCase__              =	unicodedata.category(__lowerCAmelCase							)
					if cat == "Zs":
						return True
				return False





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__              =	{}
				with io.open(__lowerCAmelCase ,						'''r''' ,						encoding='''utf-8'''							) as f:
					for index, line in enumerate(__lowerCAmelCase							):
						lowerCamelCase__              =	line.rstrip('''\n'''							)
						lowerCamelCase__              =	int(__lowerCAmelCase							)

				return token_to_idx





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase = None							):



				'''simple docstring'''







				lowerCamelCase__              =	0
				if os.path.isdir(__lowerCAmelCase							):
					lowerCamelCase__              =	os.path.join(
					    __lowerCAmelCase ,						(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']							)
				else:
					lowerCamelCase__              =	(filename_prefix + '''-''' if filename_prefix else '''''') + save_directory
				with open(__lowerCAmelCase ,						'''w''' ,						encoding='''utf-8'''							) as writer:
					for token, token_index in sorted(self.vocab.items() ,						key=lambda __lowerCAmelCase							: kv[1]							):
						if index != token_index:
							logger.warning(
							    F'Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive.'
							    ''' Please check that the vocabulary is not corrupted!'''							)
							lowerCamelCase__              =	token_index
						writer.write(token + '''\n'''							)
						index += 1

				lowerCamelCase__              =	os.path.join(__lowerCAmelCase ,						'''sentencepiece.bpe.model'''							)
				with open(__lowerCAmelCase ,						'''wb'''							) as fi:
					lowerCamelCase__              =	self.sp_model.serialized_model_proto()
					fi.write(__lowerCAmelCase							)

				return (vocab_file,)










from __future__ import annotations

import unittest

from transformers import EsmConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
			import numpy
			import tensorflow as tf

			from transformers.models.esm.modeling_tf_esm import (
			    TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
			    TFEsmForMaskedLM,
			    TFEsmForSequenceClassification,
			    TFEsmForTokenClassification,
			    TFEsmModel,
			)






class       __A					:

			'''simple docstring'''







			def __init__(					self ,						__lowerCAmelCase ,						):



				'''simple docstring'''







				lowerCamelCase__              =	parent
				lowerCamelCase__              =	1_3
				lowerCamelCase__              =	7
				lowerCamelCase__              =	True
				lowerCamelCase__              =	True
				lowerCamelCase__              =	True
				lowerCamelCase__              =	9_9
				lowerCamelCase__              =	3_2
				lowerCamelCase__              =	2
				lowerCamelCase__              =	4
				lowerCamelCase__              =	3_7
				lowerCamelCase__              =	'''gelu'''
				lowerCamelCase__              =	0.1
				lowerCamelCase__              =	0.1
				lowerCamelCase__              =	5_1_2
				lowerCamelCase__              =	1_6
				lowerCamelCase__              =	2
				lowerCamelCase__              =	0.02
				lowerCamelCase__              =	3
				lowerCamelCase__              =	4
				lowerCamelCase__              =	None





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







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

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

				lowerCamelCase__              =	None
				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.seq_length] ,						self.num_labels							)
					lowerCamelCase__              =	ids_tensor([self.batch_size] ,						self.num_choices							)

				lowerCamelCase__              =	EsmConfig(
				    vocab_size=self.vocab_size ,						hidden_size=self.hidden_size ,						num_hidden_layers=self.num_hidden_layers ,						pad_token_id=1 ,						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 config, input_ids, input_mask, sequence_labels, token_labels, choice_labels





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				(
				    (
				    lowerCamelCase__
				)       ,			(
				    lowerCamelCase__
				)       ,			(
				    lowerCamelCase__
				)       ,			(
				    lowerCamelCase__
				)       ,			(
				    lowerCamelCase__
				)       ,			(
				    lowerCamelCase__
				)       ,			
				)              =	self.prepare_config_and_inputs()

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

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





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__              =	TFEsmModel(config=__lowerCAmelCase							)
				lowerCamelCase__              =	{'''input_ids''': input_ids, '''attention_mask''': input_mask}
				lowerCamelCase__              =	model(__lowerCAmelCase							)

				lowerCamelCase__              =	[input_ids, input_mask]
				lowerCamelCase__              =	model(__lowerCAmelCase							)

				lowerCamelCase__              =	model(__lowerCAmelCase							)

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





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						):



				'''simple docstring'''







				lowerCamelCase__              =	True

				lowerCamelCase__              =	TFEsmModel(config=__lowerCAmelCase							)
				lowerCamelCase__              =	{
				    '''input_ids''': input_ids,
				    '''attention_mask''': input_mask,
				    '''encoder_hidden_states''': encoder_hidden_states,
				    '''encoder_attention_mask''': encoder_attention_mask,
				}
				lowerCamelCase__              =	model(__lowerCAmelCase							)

				lowerCamelCase__              =	[input_ids, input_mask]
				lowerCamelCase__              =	model(__lowerCAmelCase ,						encoder_hidden_states=__lowerCAmelCase							)

				# Also check the case where encoder outputs are not passed
				lowerCamelCase__              =	model(__lowerCAmelCase ,						attention_mask=__lowerCAmelCase							)

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





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__              =	TFEsmForMaskedLM(config=__lowerCAmelCase							)
				lowerCamelCase__              =	model([input_ids, input_mask]							)
				self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.seq_length, self.vocab_size)							)





			def 	__lowerCamelCase       (					self ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase ,						__lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__              =	self.num_labels
				lowerCamelCase__              =	TFEsmForTokenClassification(config=__lowerCAmelCase							)
				lowerCamelCase__              =	{'''input_ids''': input_ids, '''attention_mask''': input_mask}
				lowerCamelCase__              =	model(__lowerCAmelCase							)
				self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.seq_length, self.num_labels)							)





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







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






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

			'''simple docstring'''







			lowerCAmelCase_							  =		(
			    (
			        TFEsmModel,
			        TFEsmForMaskedLM,
			        TFEsmForSequenceClassification,
			        TFEsmForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			lowerCAmelCase_							  =		(
			    {
			        """feature-extraction""": TFEsmModel,
			        """fill-mask""": TFEsmForMaskedLM,
			        """text-classification""": TFEsmForSequenceClassification,
			        """token-classification""": TFEsmForTokenClassification,
			        """zero-shot""": TFEsmForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			lowerCAmelCase_							  =		False
			lowerCAmelCase_							  =		False





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				lowerCamelCase__              =	TFEsmModelTester(self							)
				lowerCamelCase__              =	ConfigTester(self ,						config_class=__lowerCAmelCase ,						hidden_size=3_7							)





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				self.config_tester.run_common_tests()





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				lowerCamelCase__              =	self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*__lowerCAmelCase							)





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				lowerCamelCase__              =	self.model_tester.prepare_config_and_inputs_for_decoder()
				self.model_tester.create_and_check_model_as_decoder(*__lowerCAmelCase							)





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				lowerCamelCase__              =	self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*__lowerCAmelCase							)





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				lowerCamelCase__              =	self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase							)





			@slow
			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				for model_name in TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					lowerCamelCase__              =	TFEsmModel.from_pretrained(__lowerCAmelCase							)
					self.assertIsNotNone(__lowerCAmelCase							)





			@unittest.skip('''Protein models do not support embedding resizing.'''							)
			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				pass





			@unittest.skip('''Protein models do not support embedding resizing.'''							)
			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				pass





			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				lowerCamelCase__       ,			lowerCamelCase__              =	self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
					lowerCamelCase__              =	model_class(__lowerCAmelCase							)
					assert isinstance(model.get_input_embeddings() ,						tf.keras.layers.Layer							)
					if model_class is TFEsmForMaskedLM:
						# Output embedding test differs from the main test because they're a matrix, not a layer
						lowerCamelCase__              =	model.get_bias()
						assert isinstance(__lowerCAmelCase ,						__lowerCAmelCase							)
						for k, v in name.items():
							assert isinstance(__lowerCAmelCase ,						tf.Variable							)
					else:
						lowerCamelCase__              =	model.get_output_embeddings()
						assert x is None
						lowerCamelCase__              =	model.get_bias()
						assert name is None






@require_tf
class       __A					(					unittest.TestCase				):

			'''simple docstring'''







			@slow
			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				lowerCamelCase__              =	TFEsmForMaskedLM.from_pretrained('''facebook/esm2_t6_8M_UR50D'''							)

				lowerCamelCase__              =	tf.constant([[0, 1, 2, 3, 4, 5]]							)
				lowerCamelCase__              =	model(__lowerCAmelCase							)[0]
				lowerCamelCase__              =	[1, 6, 3_3]
				self.assertEqual(list(output.numpy().shape							) ,						__lowerCAmelCase							)
				# compare the actual values for a slice.
				lowerCamelCase__              =	tf.constant(
				    [
				        [
				            [8.92_1518, -10.58_9814, -6.467_1307],
				            [-6.396_7156, -13.91_1377, -1.121_1915],
				            [-7.78_1247, -13.95_1557, -3.74_0592],
				        ]
				    ]							)
				self.assertTrue(numpy.allclose(output[:, :3, :3].numpy() ,						expected_slice.numpy() ,						atol=1E-2							)							)





			@slow
			def 	__lowerCamelCase       (					self							):



				'''simple docstring'''







				lowerCamelCase__              =	TFEsmModel.from_pretrained('''facebook/esm2_t6_8M_UR50D'''							)

				lowerCamelCase__              =	tf.constant([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]							)
				lowerCamelCase__              =	model(__lowerCAmelCase							)[0]
				# compare the actual values for a slice.
				lowerCamelCase__              =	tf.constant(
				    [
				        [
				            [0.1444_3092, 0.5412_5327, 0.324_7739],
				            [0.3034_0484, 0.0052_6676, 0.3107_7722],
				            [0.3227_8043, -0.2498_7096, 0.341_4628],
				        ]
				    ]							)
				self.assertTrue(numpy.allclose(output[:, :3, :3].numpy() ,						expected_slice.numpy() ,						atol=1E-4							)							)



