
"""simple docstring"""


import asyncio
import os
import re
import sys
import tempfile
import unittest
from contextlib import contextmanager
from copy import deepcopy
from distutils.util import strtobool
from enum import Enum
from importlib.util import find_spec
from pathlib import Path
from unittest.mock import patch

import pyarrow as pa
import pytest
import requests
from packaging import version

from datasets import config


if config.PY_VERSION < version.parse('''3.8'''):
		import importlib_metadata
else:
		import importlib.metadata as importlib_metadata






def       _snake_case				(		snake_case__   :     List[str]	,      snake_case__   :     List[Any]=False     ):
	try:
		A						   =   os.environ[key]
	except KeyError:
		# KEY isn't set, default to `default`.
		A						   =   default
	else:
		# KEY is set, convert it to True or False.
		try:
			A						   =   strtobool(snake_case__     )
		except ValueError:
			# More values are supported, but let's keep the message simple.
			raise ValueError(F'If set, {key} must be yes or no.'     )
	return _value


_lowercase							   =				parse_flag_from_env('''RUN_SLOW''', default=False)
_lowercase							   =				parse_flag_from_env('''RUN_REMOTE''', default=False)
_lowercase							   =				parse_flag_from_env('''RUN_LOCAL''', default=True)
_lowercase							   =				parse_flag_from_env('''RUN_PACKAGED''', default=True)

# Compression
_lowercase							   =				pytest.mark.skipif(not config.LZ4_AVAILABLE, reason='''test requires lz4''')
_lowercase							   =				pytest.mark.skipif(not config.PY7ZR_AVAILABLE, reason='''test requires py7zr''')
_lowercase							   =				pytest.mark.skipif(not config.ZSTANDARD_AVAILABLE, reason='''test requires zstandard''')

# Audio
_lowercase							   =				pytest.mark.skipif(
    # On Windows and OS X, soundfile installs sndfile
    find_spec('''soundfile''') is None or version.parse(importlib_metadata.version('''soundfile''')) < version.parse('''0.12.0'''),
    reason='''test requires sndfile>=0.12.1: \'pip install \"soundfile>=0.12.1\"\'; ''',
)

# Beam
_lowercase							   =				pytest.mark.skipif(
    not config.BEAM_AVAILABLE or config.DILL_VERSION >= version.parse('''0.3.2'''),
    reason='''test requires apache-beam and a compatible dill version''',
)

# Dill-cloudpickle compatibility
_lowercase							   =				pytest.mark.skipif(
    config.DILL_VERSION <= version.parse('''0.3.2'''),
    reason='''test requires dill>0.3.2 for cloudpickle compatibility''',
)

# Windows
_lowercase							   =				pytest.mark.skipif(
    sys.platform == '''win32''',
    reason='''test should not be run on Windows''',
)






def       _snake_case				(		snake_case__   :     int     ):
	try:
		import faiss  # noqa
	except ImportError:
		A						   =   unittest.skip('test requires faiss'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     Dict     ):
	try:
		import regex  # noqa
	except ImportError:
		A						   =   unittest.skip('test requires regex'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     List[str]     ):
	try:
		import elasticsearch  # noqa
	except ImportError:
		A						   =   unittest.skip('test requires elasticsearch'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     int     ):
	try:
		import sqlalchemy  # noqa
	except ImportError:
		A						   =   unittest.skip('test requires sqlalchemy'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     List[Any]     ):
	if not config.TORCH_AVAILABLE:
		A						   =   unittest.skip('test requires PyTorch'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     Optional[Any]     ):
	if not config.TF_AVAILABLE:
		A						   =   unittest.skip('test requires TensorFlow'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     Tuple     ):
	if not config.JAX_AVAILABLE:
		A						   =   unittest.skip('test requires JAX'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     List[Any]     ):
	if not config.PIL_AVAILABLE:
		A						   =   unittest.skip('test requires Pillow'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     Any     ):
	try:
		import transformers  # noqa F401
	except ImportError:
		return unittest.skip('test requires transformers'     )(snake_case__     )
	else:
		return test_case






def       _snake_case				(		snake_case__   :     Any     ):
	try:
		import tiktoken  # noqa F401
	except ImportError:
		return unittest.skip('test requires tiktoken'     )(snake_case__     )
	else:
		return test_case






def       _snake_case				(		snake_case__   :     Union[str, Any]     ):
	try:
		import spacy  # noqa F401
	except ImportError:
		return unittest.skip('test requires spacy'     )(snake_case__     )
	else:
		return test_case






def       _snake_case				(		snake_case__   :     Tuple     ):

	def _require_spacy_model(snake_case__   :     Union[str, Any]     ):
		try:
			import spacy  # noqa F401

			spacy.load(snake_case__     )
		except ImportError:
			return unittest.skip('test requires spacy'     )(snake_case__     )
		except OSError:
			return unittest.skip('test requires spacy model \'{}\''.format(snake_case__     )     )(snake_case__     )
		else:
			return test_case

	return _require_spacy_model






def       _snake_case				(		snake_case__   :     Optional[int]     ):
	try:
		import pyspark  # noqa F401
	except ImportError:
		return unittest.skip('test requires pyspark'     )(snake_case__     )
	else:
		return test_case






def       _snake_case				(		snake_case__   :     str     ):
	try:
		import joblibspark  # noqa F401
	except ImportError:
		return unittest.skip('test requires joblibspark'     )(snake_case__     )
	else:
		return test_case






def       _snake_case				(		snake_case__   :     Tuple     ):
	if not _run_slow_tests or _run_slow_tests == 0:
		A						   =   unittest.skip('test is slow'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     Optional[int]     ):
	if not _run_local_tests or _run_local_tests == 0:
		A						   =   unittest.skip('test is local'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     Union[str, Any]     ):
	if not _run_packaged_tests or _run_packaged_tests == 0:
		A						   =   unittest.skip('test is packaged'     )(snake_case__     )
	return test_case






def       _snake_case				(		snake_case__   :     str     ):
	if not _run_remote_tests or _run_remote_tests == 0:
		A						   =   unittest.skip('test requires remote'     )(snake_case__     )
	return test_case






def       _snake_case				(		*snake_case__   :     Union[str, Any]     ):
	def decorate(cls   :     Tuple     ):
		for name, fn in cls.__dict__.items():
			if callable(snake_case__     ) and name.startswith('test'     ):
				for decorator in decorators:
					A						   =   decorator(snake_case__     )
				setattr(cls	,      snake_case__	,      snake_case__     )
		return cls

	return decorate







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						pass







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						_lowerCamelCase:    List[str]      =    0
						_lowerCamelCase:    Dict      =    1
						_lowerCamelCase:    Any      =    2






@contextmanager
def       _snake_case				(		snake_case__   :     Optional[Any]=OfflineSimulationMode.CONNECTION_FAILS	,      snake_case__   :     Optional[Any]=1e-16     ):
	A						   =   requests.Session().request

	def timeout_request(snake_case__   :     Tuple	,      snake_case__   :     Dict	,      snake_case__   :     Dict	,      **snake_case__   :     Tuple     ):
		# Change the url to an invalid url so that the connection hangs
		A						   =   'https://10.255.255.1'
		if kwargs.get('timeout'     ) is None:
			raise RequestWouldHangIndefinitelyError(
			    F'Tried a call to {url} in offline mode with no timeout set. Please set a timeout.'     )
		A						   =   timeout
		try:
			return online_request(snake_case__	,      snake_case__	,      **snake_case__     )
		except Exception as e:
			# The following changes in the error are just here to make the offline timeout error prettier
			A						   =   url
			A						   =   e.args[0]
			A						   =   (max_retry_error.args[0].replace('10.255.255.1'	,      F'OfflineMock[{url}]'     ),)
			A						   =   (max_retry_error,)
			raise

	def raise_connection_error(snake_case__   :     Optional[Any]	,      snake_case__   :     Dict	,      **snake_case__   :     int     ):
		raise requests.ConnectionError('Offline mode is enabled.'	,      request=snake_case__     )

	if mode is OfflineSimulationMode.CONNECTION_FAILS:
		with patch('requests.Session.send'	,      snake_case__     ):
			yield
	elif mode is OfflineSimulationMode.CONNECTION_TIMES_OUT:
		# inspired from https://stackoverflow.com/a/904609
		with patch('requests.Session.request'	,      snake_case__     ):
			yield
	elif mode is OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1:
		with patch('datasets.config.HF_DATASETS_OFFLINE'	,      snake_case__     ):
			yield
	else:
		raise ValueError('Please use a value from the OfflineSimulationMode enum.'     )






@contextmanager
def       _snake_case				(		*snake_case__   :     str	,      **snake_case__   :     Tuple     ):
	A						   =   str(Path().resolve()     )
	with tempfile.TemporaryDirectory(*snake_case__	,      **snake_case__     ) as tmp_dir:
		try:
			os.chdir(snake_case__     )
			yield
		finally:
			os.chdir(snake_case__     )






@contextmanager
def       _snake_case				(		):
	import gc

	gc.collect()
	A						   =   pa.total_allocated_bytes()
	yield
	assert pa.total_allocated_bytes() - previous_allocated_memory > 0, "Arrow memory didn't increase."






@contextmanager
def       _snake_case				(		):
	import gc

	gc.collect()
	A						   =   pa.total_allocated_bytes()
	yield
	assert pa.total_allocated_bytes() - previous_allocated_memory <= 0, "Arrow memory wasn't expected to increase."






def       _snake_case				(		snake_case__   :     Union[str, Any]	,      snake_case__   :     Any     ):
	return deepcopy(snake_case__     ).integers(0	,      100	,      10     ).tolist() == deepcopy(snake_case__     ).integers(0	,      100	,      10     ).tolist()






def       _snake_case				(		snake_case__   :     Dict     ):
	import decorator
	from requests.exceptions import HTTPError

	def _wrapper(snake_case__   :     Optional[Any]	,      *snake_case__   :     List[Any]	,      **snake_case__   :     List[Any]     ):
		try:
			return func(*snake_case__	,      **snake_case__     )
		except HTTPError as err:
			if str(snake_case__     ).startswith('500'     ) or str(snake_case__     ).startswith('502'     ):
				pytest.xfail(str(snake_case__     )     )
			raise err

	return decorator.decorator(_wrapper	,      snake_case__     )







class 				lowerCAmelCase_				:



						'''simple docstring'''


						def __init__( self     :      Tuple  ,A_     :      Union[str, Any]  ,A_     :      int  ,A_     :      List[Any]      )     ->   Any:
							A						   =   returncode
							A						   =   stdout
							A						   =   stderr






async def       _snake_case				(		snake_case__   :     int	,      snake_case__   :     List[str]     ):
	while True:
		A						   =   await stream.readline()
		if line:
			callback(snake_case__     )
		else:
			break






async def       _snake_case				(		snake_case__   :     List[Any]	,      snake_case__   :     Dict=None	,      snake_case__   :     int=None	,      snake_case__   :     List[str]=None	,      snake_case__   :     List[Any]=False	,      snake_case__   :     str=False     ):
	if echo:
		print('\nRunning: '	,      ' '.join(snake_case__     )     )

	A						   =   await asyncio.create_subprocess_exec(
	    cmd[0]	,      *cmd[1:]	,      stdin=snake_case__	,      stdout=asyncio.subprocess.PIPE	,      stderr=asyncio.subprocess.PIPE	,      env=snake_case__	,      )

	# note: there is a warning for a possible deadlock when using `wait` with huge amounts of data in the pipe
	# https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process.wait
	#
	# If it starts hanging, will need to switch to the following code. The problem is that no data
	# will be seen until it's done and if it hangs for example there will be no debug info.
	# out, err = await p.communicate()
	# return _RunOutput(p.returncode, out, err)

	A						   =   []
	A						   =   []

	def tee(snake_case__   :     Tuple	,      snake_case__   :     Union[str, Any]	,      snake_case__   :     Optional[Any]	,      snake_case__   :     List[Any]=""     ):
		A						   =   line.decode('utf-8'     ).rstrip()
		sink.append(snake_case__     )
		if not quiet:
			print(snake_case__	,      snake_case__	,      file=snake_case__     )

    # XXX: the timeout doesn't seem to make any difference here
	await asyncio.wait(
	    [
	        _read_stream(p.stdout	,      lambda snake_case__     : tee(snake_case__	,      snake_case__	,      sys.stdout	,      label='stdout:'     )     ),
	        _read_stream(p.stderr	,      lambda snake_case__     : tee(snake_case__	,      snake_case__	,      sys.stderr	,      label='stderr:'     )     ),
	    ]	,      timeout=snake_case__	,      )
	return _RunOutput(await p.wait()	,      snake_case__	,      snake_case__     )






def       _snake_case				(		snake_case__   :     Union[str, Any]	,      snake_case__   :     Dict=None	,      snake_case__   :     Optional[int]=None	,      snake_case__   :     Union[str, Any]=180	,      snake_case__   :     Dict=False	,      snake_case__   :     List[str]=True     ):
	A						   =   asyncio.get_event_loop()
	A						   =   loop.run_until_complete(
	    _stream_subprocess(snake_case__	,      env=snake_case__	,      stdin=snake_case__	,      timeout=snake_case__	,      quiet=snake_case__	,      echo=snake_case__     )     )

	A						   =   ' '.join(snake_case__     )
	if result.returncode > 0:
		A						   =   '\n'.join(result.stderr     )
		raise RuntimeError(
		    F'\'{cmd_str}\' failed with returncode {result.returncode}\n\n'
		    F'The combined stderr from workers follows:\n{stderr}'     )

	# check that the subprocess actually did run and produced some output, should the test rely on
	# the remote side to do the testing
	if not result.stdout and not result.stderr:
		raise RuntimeError(F'\'{cmd_str}\' produced no output.'     )

	return result






def       _snake_case				(		):
	A						   =   os.environ.get('PYTEST_XDIST_WORKER'	,      'gw0'     )
	A						   =   re.sub(r'^gw'	,      ''	,      snake_case__	,      0	,      re.M     )
	return int(snake_case__     )






def       _snake_case				(		):
	A						   =   2_9500
	A						   =   pytest_xdist_worker_id()
	return port + uniq_delta

"""simple docstring"""


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



						'''simple docstring'''


						def __init__( self     :      List[Any]  ,A_     :      Optional[Any]  ,)     ->   Optional[int]:
							A						   =   parent
							A						   =   13
							A						   =   7
							A						   =   True
							A						   =   True
							A						   =   True
							A						   =   99
							A						   =   32
							A						   =   2
							A						   =   4
							A						   =   37
							A						   =   'gelu'
							A						   =   0.1
							A						   =   0.1
							A						   =   512
							A						   =   16
							A						   =   2
							A						   =   0.02
							A						   =   3
							A						   =   4
							A						   =   None


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   Union[str, Any]:
							A						   =   ids_tensor([self.batch_size, self.seq_length]  ,self.vocab_size      )

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

							A						   =   None
							A						   =   None
							A						   =   None
							if self.use_labels:
								A						   =   ids_tensor([self.batch_size]  ,self.type_sequence_label_size      )
								A						   =   ids_tensor([self.batch_size, self.seq_length]  ,self.num_labels      )
								A						   =   ids_tensor([self.batch_size]  ,self.num_choices      )

							A						   =   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 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   Dict:
							(
							    (
							    A
							)   ,      (
							    A
							)   ,      (
							    A
							)   ,      (
							    A
							)   ,      (
							    A
							)   ,      (
							    A
							)   ,      
							)						   =   self.prepare_config_and_inputs()

							A						   =   True
							A						   =   floats_tensor([self.batch_size, self.seq_length, self.hidden_size]      )
							A						   =   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 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]  ,A_     :      int  ,A_     :      List[str]  ,A_     :      Optional[int]  ,A_     :      List[Any]  ,A_     :      Any  ,A_     :      Any      )     ->   Dict:
							A						   =   TFEsmModel(config=A_      )
							A						   =   {'input_ids': input_ids, 'attention_mask': input_mask}
							A						   =   model(A_      )

							A						   =   [input_ids, input_mask]
							A						   =   model(A_      )

							A						   =   model(A_      )

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      Any  ,A_     :      Union[str, Any]  ,A_     :      Tuple  ,A_     :      int  ,A_     :      List[Any]  ,A_     :      Optional[int]  ,A_     :      Optional[Any]  ,A_     :      List[str]  ,)     ->   Optional[int]:
							A						   =   True

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

							A						   =   [input_ids, input_mask]
							A						   =   model(A_  ,encoder_hidden_states=A_      )

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str  ,A_     :      List[Any]  ,A_     :      List[Any]  ,A_     :      Optional[Any]  ,A_     :      Optional[int]  ,A_     :      Optional[Any]  ,A_     :      List[Any]      )     ->   Dict:
							A						   =   TFEsmForMaskedLM(config=A_      )
							A						   =   model([input_ids, input_mask]      )
							self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length, self.vocab_size)      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any  ,A_     :      Optional[Any]  ,A_     :      str  ,A_     :      List[Any]  ,A_     :      int  ,A_     :      Tuple  ,A_     :      Optional[int]      )     ->   Union[str, Any]:
							A						   =   self.num_labels
							A						   =   TFEsmForTokenClassification(config=A_      )
							A						   =   {'input_ids': input_ids, 'attention_mask': input_mask}
							A						   =   model(A_      )
							self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length, self.num_labels)      )




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   List[Any]:
							A						   =   self.prepare_config_and_inputs()
							(
							    (
							    A
							)   ,      (
							    A
							)   ,      (
							    A
							)   ,      (
							    A
							)   ,      (
							    A
							)   ,      (
							    A
							)   ,      
							)						   =   config_and_inputs
							A						   =   {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict







@require_tf
class 				lowerCAmelCase_				(      _lowercase		,					_lowercase		,					unittest.TestCase    ):



						'''simple docstring'''


						_lowerCamelCase:    Dict      =    (
						    (
						        TFEsmModel,
						        TFEsmForMaskedLM,
						        TFEsmForSequenceClassification,
						        TFEsmForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						_lowerCamelCase:    List[str]      =    (
						    {
						        '''feature-extraction''': TFEsmModel,
						        '''fill-mask''': TFEsmForMaskedLM,
						        '''text-classification''': TFEsmForSequenceClassification,
						        '''token-classification''': TFEsmForTokenClassification,
						        '''zero-shot''': TFEsmForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						_lowerCamelCase:    Union[str, Any]      =    False
						_lowerCamelCase:    List[Any]      =    False


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]      )     ->   int:
							A						   =   TFEsmModelTester(self      )
							A						   =   ConfigTester(self  ,config_class=A_  ,hidden_size=37      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   Optional[int]:
							self.config_tester.run_common_tests()


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   List[str]:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]      )     ->   List[Any]:
							A						   =   self.model_tester.prepare_config_and_inputs_for_decoder()
							self.model_tester.create_and_check_model_as_decoder(*A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   Dict:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]      )     ->   List[Any]:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*A_      )


						@slow
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Tuple      )     ->   Tuple:
							for model_name in TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								A						   =   TFEsmModel.from_pretrained(A_      )
								self.assertIsNotNone(A_      )


						@unittest.skip('Protein models do not support embedding resizing.'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]      )     ->   Optional[int]:
							pass


						@unittest.skip('Protein models do not support embedding resizing.'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Tuple      )     ->   Any:
							pass




						def 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   Dict:
							A   ,      A						   =   self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
								A						   =   model_class(A_      )
								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
									A						   =   model.get_bias()
									assert isinstance(A_  ,A_      )
									for k, v in name.items():
										assert isinstance(A_  ,tf.Variable      )
								else:
									A						   =   model.get_output_embeddings()
									assert x is None
									A						   =   model.get_bias()
									assert name is None







@require_tf
class 				lowerCAmelCase_				(      unittest.TestCase    ):



						'''simple docstring'''


						@slow
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Tuple:
							A						   =   TFEsmForMaskedLM.from_pretrained('facebook/esm2_t6_8M_UR50D'      )

							A						   =   tf.constant([[0, 1, 2, 3, 4, 5]]      )
							A						   =   model(A_      )[0]
							A						   =   [1, 6, 33]
							self.assertEqual(list(output.numpy().shape      )  ,A_      )
							# compare the actual values for a slice.
							A						   =   tf.constant(
							    [
							        [
							            [8.92_15_18, -10.58_98_14, -6.4_67_13_07],
							            [-6.3_96_71_56, -13.91_13_77, -1.1_21_19_15],
							            [-7.78_12_47, -13.95_15_57, -3.74_05_92],
							        ]
							    ]      )
							self.assertTrue(numpy.allclose(output[:, :3, :3].numpy()  ,expected_slice.numpy()  ,atol=1e-2      )      )




						@slow
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   int:
							A						   =   TFEsmModel.from_pretrained('facebook/esm2_t6_8M_UR50D'      )

							A						   =   tf.constant([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]      )
							A						   =   model(A_      )[0]
							# compare the actual values for a slice.
							A						   =   tf.constant(
							    [
							        [
							            [0.14_44_30_92, 0.54_12_53_27, 0.3_24_77_39],
							            [0.30_34_04_84, 0.00_52_66_76, 0.31_07_77_22],
							            [0.32_27_80_43, -0.24_98_70_96, 0.3_41_46_28],
							        ]
							    ]      )
							self.assertTrue(numpy.allclose(output[:, :3, :3].numpy()  ,expected_slice.numpy()  ,atol=1e-4      )      )