


"""simple docstring"""


import itertools
import os
import random
import tempfile
import unittest

import numpy as np
from datasets import load_dataset

from transformers import is_speech_available
from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_speech_available():
    from transformers import WhisperFeatureExtractor

if is_torch_available():
    import torch

__lowerCamelCase      :Optional[Any]	    =		random.Random()




def   snake_case		(     UpperCamelCase__       :						Optional[Any]			,				UpperCamelCase__       :						List[Any]=1.0			,				UpperCamelCase__       :						Optional[int]=None			,				UpperCamelCase__       :						str=None    )   ->      List[str]:
      if rng is None:
            lowerCamelCase					:					Union[str, Any]        =	global_rng

      lowerCamelCase					:					List[Any]        =	[]
      for batch_idx in range(shape[0]    ):
            values.append([]    )
            for _ in range(shape[1]    ):
                  values[-1].append(rng.random() * scale    )

      return values


@require_torch
@require_torchaudio
class 			A__	(						unittest.TestCase):


     """simple docstring"""

     def __init__(	self:						int     ,		__a:						Optional[Any]     ,		__a:						List[Any]=7     ,		__a:						Optional[int]=400     ,		__a:						str=2_000     ,		__a:						Dict=10     ,		__a:						Optional[int]=160     ,		__a:						Union[str, Any]=8     ,		__a:						List[str]=0.0     ,		__a:						Union[str, Any]=4_000     ,		__a:						Optional[int]=False     ,		__a:						List[str]=True     ,		)->    List[Any]:
           lowerCamelCase					:					Tuple        =	parent
           lowerCamelCase					:					Dict        =	batch_size
           lowerCamelCase					:					Union[str, Any]        =	min_seq_length
           lowerCamelCase					:					Union[str, Any]        =	max_seq_length
           lowerCamelCase					:					Tuple        =	(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
           lowerCamelCase					:					List[str]        =	padding_value
           lowerCamelCase					:					List[Any]        =	sampling_rate
           lowerCamelCase					:					Tuple        =	return_attention_mask
           lowerCamelCase					:					List[str]        =	do_normalize
           lowerCamelCase					:					str        =	feature_size
           lowerCamelCase					:					Union[str, Any]        =	chunk_length
           lowerCamelCase					:					int        =	hop_length

     def 		a__						(	self:						List[str]	)->    Tuple:
           return {
               "feature_size": self.feature_size,
               "hop_length": self.hop_length,
               "chunk_length": self.chunk_length,
               "padding_value": self.padding_value,
               "sampling_rate": self.sampling_rate,
               "return_attention_mask": self.return_attention_mask,
               "do_normalize": self.do_normalize,
           }







     def 		a__						(	self:						Dict     ,		__a:						str=False     ,		__a:						str=False	)->    List[Any]:
           def _flatten(__a:						Optional[Any]	):
                 return list(itertools.chain(*__a	)	)

           if equal_length:
                 lowerCamelCase					:					Optional[int]        =	[floats_list((self.max_seq_length, self.feature_size)	) for _ in range(self.batch_size	)]
           else:
                 # make sure that inputs increase in size
                 lowerCamelCase					:					Dict        =	[
                     floats_list((x, self.feature_size)	)
                     for x in range(self.min_seq_length     ,		self.max_seq_length     ,		self.seq_length_diff	)
                 ]
           if numpify:
                 lowerCamelCase					:					Union[str, Any]        =	[np.asarray(__a	) for x in speech_inputs]
           return speech_inputs


@require_torch
@require_torchaudio
class 			A__	(						__lowercase ,     unittest.TestCase):


     """simple docstring"""
     snake_case__	:					List[str]													=WhisperFeatureExtractor if is_speech_available() else None

     def 		a__						(	self:						Optional[Any]	)->    List[Any]:
           lowerCamelCase					:					List[str]        =	WhisperFeatureExtractionTester(self	)

     def 		a__						(	self:						List[Any]	)->    Union[str, Any]:
           lowerCamelCase					:					List[Any]        =	self.feature_extraction_class(**self.feat_extract_dict	)

           with tempfile.TemporaryDirectory() as tmpdirname:
                 lowerCamelCase					:					int        =	feat_extract_first.save_pretrained(__a	)[0]
                 check_json_file_has_correct_format(__a	)
                 lowerCamelCase					:					int        =	self.feature_extraction_class.from_pretrained(__a	)

           lowerCamelCase					:					str        =	feat_extract_first.to_dict()
           lowerCamelCase					:					List[str]        =	feat_extract_second.to_dict()
           lowerCamelCase					:					Optional[Any]        =	feat_extract_first.mel_filters
           lowerCamelCase					:					str        =	feat_extract_second.mel_filters
           self.assertTrue(np.allclose(__a     ,		__a	)	)
           self.assertEqual(__a     ,		__a	)

     def 		a__						(	self:						Optional[Any]	)->    List[str]:
           lowerCamelCase					:					str        =	self.feature_extraction_class(**self.feat_extract_dict	)

           with tempfile.TemporaryDirectory() as tmpdirname:
                 lowerCamelCase					:					Optional[int]        =	os.path.join(__a     ,		"""feat_extract.json"""	)
                 feat_extract_first.to_json_file(__a	)
                 lowerCamelCase					:					Optional[int]        =	self.feature_extraction_class.from_json_file(__a	)

           lowerCamelCase					:					int        =	feat_extract_first.to_dict()
           lowerCamelCase					:					Union[str, Any]        =	feat_extract_second.to_dict()
           lowerCamelCase					:					str        =	feat_extract_first.mel_filters
           lowerCamelCase					:					Any        =	feat_extract_second.mel_filters
           self.assertTrue(np.allclose(__a     ,		__a	)	)
           self.assertEqual(__a     ,		__a	)

     def 		a__						(	self:						List[Any]	)->    Optional[int]:
           # Tests that all call wrap to encode_plus and batch_encode_plus
           lowerCamelCase					:					int        =	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
           # create three inputs of length 800, 1000, and 1200
           lowerCamelCase					:					List[str]        =	[floats_list((1, x)	)[0] for x in range(800     ,		1_400     ,		200	)]
           lowerCamelCase					:					int        =	[np.asarray(__a	) for speech_input in speech_inputs]

           # Test feature size
           lowerCamelCase					:					Dict        =	feature_extractor(__a     ,		padding="""max_length"""     ,		return_tensors="""np"""	).input_features
           self.assertTrue(input_features.ndim == 3	)
           self.assertTrue(input_features.shape[-1] == feature_extractor.nb_max_frames	)
           self.assertTrue(input_features.shape[-2] == feature_extractor.feature_size	)

           # Test not batched input
           lowerCamelCase					:					Optional[int]        =	feature_extractor(speech_inputs[0]     ,		return_tensors="""np"""	).input_features
           lowerCamelCase					:					Tuple        =	feature_extractor(np_speech_inputs[0]     ,		return_tensors="""np"""	).input_features
           self.assertTrue(np.allclose(__a     ,		__a     ,		atol=1e-3	)	)

           # Test batched
           lowerCamelCase					:					Any        =	feature_extractor(__a     ,		return_tensors="""np"""	).input_features
           lowerCamelCase					:					List[str]        =	feature_extractor(__a     ,		return_tensors="""np"""	).input_features
           for enc_seq_a, enc_seq_a in zip(__a     ,		__a	):
                 self.assertTrue(np.allclose(__a     ,		__a     ,		atol=1e-3	)	)

           # Test 2-D numpy arrays are batched.
           lowerCamelCase					:					List[Any]        =	[floats_list((1, x)	)[0] for x in (800, 800, 800)]
           lowerCamelCase					:					Tuple        =	np.asarray(__a	)
           lowerCamelCase					:					Optional[Any]        =	feature_extractor(__a     ,		return_tensors="""np"""	).input_features
           lowerCamelCase					:					Union[str, Any]        =	feature_extractor(__a     ,		return_tensors="""np"""	).input_features
           for enc_seq_a, enc_seq_a in zip(__a     ,		__a	):
                 self.assertTrue(np.allclose(__a     ,		__a     ,		atol=1e-3	)	)

           # Test truncation required
           lowerCamelCase					:					Tuple        =	[floats_list((1, x)	)[0] for x in range(200     ,		(feature_extractor.n_samples + 500)     ,		200	)]
           lowerCamelCase					:					Union[str, Any]        =	[np.asarray(__a	) for speech_input in speech_inputs]

           lowerCamelCase					:					Dict        =	[x[: feature_extractor.n_samples] for x in speech_inputs]
           lowerCamelCase					:					int        =	[np.asarray(__a	) for speech_input in speech_inputs_truncated]

           lowerCamelCase					:					Optional[int]        =	feature_extractor(__a     ,		return_tensors="""np"""	).input_features
           lowerCamelCase					:					Optional[Any]        =	feature_extractor(__a     ,		return_tensors="""np"""	).input_features
           for enc_seq_a, enc_seq_a in zip(__a     ,		__a	):
                 self.assertTrue(np.allclose(__a     ,		__a     ,		atol=1e-3	)	)

     def 		a__						(	self:						Union[str, Any]	)->    str:
           import torch

           lowerCamelCase					:					List[str]        =	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
           lowerCamelCase					:					Any        =	np.random.rand(100     ,		32	).astype(np.floataa	)
           lowerCamelCase					:					List[str]        =	np_speech_inputs.tolist()

           for inputs in [py_speech_inputs, np_speech_inputs]:
                 lowerCamelCase					:					Dict        =	feature_extractor.pad([{"""input_features""": inputs}]     ,		return_tensors="""np"""	)
                 self.assertTrue(np_processed.input_features.dtype == np.floataa	)
                 lowerCamelCase					:					Tuple        =	feature_extractor.pad([{"""input_features""": inputs}]     ,		return_tensors="""pt"""	)
                 self.assertTrue(pt_processed.input_features.dtype == torch.floataa	)

     def 		a__						(	self:						List[Any]     ,		__a:						Union[str, Any]	)->    Tuple:
           lowerCamelCase					:					List[str]        =	load_dataset("""hf-internal-testing/librispeech_asr_dummy"""     ,		"""clean"""     ,		split="""validation"""	)
           # automatic decoding with librispeech
           lowerCamelCase					:					Optional[int]        =	ds.sort("""id"""	).select(range(__a	)	)[:num_samples]["""audio"""]

           return [x["array"] for x in speech_samples]

     def 		a__						(	self:						Optional[int]	)->    Tuple:
           # fmt: off
           lowerCamelCase					:					List[str]        =	torch.tensor(
               [
                   0.11_93, -0.09_46, -0.10_98, -0.01_96, 0.02_25, -0.06_90, -0.17_36, 0.09_51,
                   0.09_71, -0.08_17, -0.07_02, 0.01_62, 0.02_60, 0.00_17, -0.01_92, -0.16_78,
                   0.07_09, -0.18_67, -0.06_55, -0.02_74, -0.02_34, -0.18_84, -0.05_16, -0.05_54,
                   -0.02_74, -0.14_25, -0.14_23, 0.08_37, 0.03_77, -0.08_54
               ]	)
           # fmt: on

           lowerCamelCase					:					int        =	self._load_datasamples(1	)
           lowerCamelCase					:					Union[str, Any]        =	WhisperFeatureExtractor()
           lowerCamelCase					:					List[Any]        =	feature_extractor(__a     ,		return_tensors="""pt"""	).input_features
           self.assertEqual(input_features.shape     ,		(1, 80, 3_000)	)
           self.assertTrue(torch.allclose(input_features[0, 0, :30]     ,		__a     ,		atol=1e-4	)	)







     def 		a__						(	self:						Optional[int]	)->    Optional[Any]:
           lowerCamelCase					:					int        =	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
           lowerCamelCase					:					List[str]        =	self._load_datasamples(1	)[0]
           lowerCamelCase					:					Union[str, Any]        =	((audio - audio.min()) / (audio.max() - audio.min())) * 65_535  # Rescale to [0, 65535] to show issue
           lowerCamelCase					:					List[str]        =	feat_extract.zero_mean_unit_var_norm([audio]     ,		attention_mask=__a	)[0]

           self.assertTrue(np.all(np.mean(__a	) < 1e-3	)	)
           self.assertTrue(np.all(np.abs(np.var(__a	) - 1	) < 1e-3	)	)








"""simple docstring"""


import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import EsmForMaskedLM, EsmForSequenceClassification, EsmForTokenClassification, EsmModel
    from transformers.models.esm.modeling_esm import (
        ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
        EsmEmbeddings,
        create_position_ids_from_input_ids,
    )


class 			A__	:


     """simple docstring"""

     def __init__(	self:						List[str]     ,		__a:						List[str]     ,		__a:						Dict=13     ,		__a:						Tuple=7     ,		__a:						Dict=False     ,		__a:						str=True     ,		__a:						List[Any]=False     ,		__a:						Dict=True     ,		__a:						Any=33     ,		__a:						Optional[Any]=32     ,		__a:						List[Any]=5     ,		__a:						Any=4     ,		__a:						Dict=37     ,		__a:						str="gelu"     ,		__a:						str=0.1     ,		__a:						int=0.1     ,		__a:						Optional[int]=512     ,		__a:						List[Any]=16     ,		__a:						int=2     ,		__a:						int=0.02     ,		__a:						Optional[int]=3     ,		__a:						str=4     ,		__a:						Tuple=None     ,		)->    Tuple:
           lowerCamelCase					:					Union[str, Any]        =	parent
           lowerCamelCase					:					Tuple        =	batch_size
           lowerCamelCase					:					Any        =	seq_length
           lowerCamelCase					:					Any        =	is_training
           lowerCamelCase					:					Tuple        =	use_input_mask
           lowerCamelCase					:					int        =	use_token_type_ids
           lowerCamelCase					:					List[str]        =	use_labels
           lowerCamelCase					:					Optional[int]        =	vocab_size
           lowerCamelCase					:					Tuple        =	hidden_size
           lowerCamelCase					:					List[str]        =	num_hidden_layers
           lowerCamelCase					:					Optional[int]        =	num_attention_heads
           lowerCamelCase					:					Optional[Any]        =	intermediate_size
           lowerCamelCase					:					Optional[Any]        =	hidden_act
           lowerCamelCase					:					Union[str, Any]        =	hidden_dropout_prob
           lowerCamelCase					:					Optional[Any]        =	attention_probs_dropout_prob
           lowerCamelCase					:					Any        =	max_position_embeddings
           lowerCamelCase					:					str        =	type_vocab_size
           lowerCamelCase					:					List[Any]        =	type_sequence_label_size
           lowerCamelCase					:					Optional[Any]        =	initializer_range
           lowerCamelCase					:					Union[str, Any]        =	num_labels
           lowerCamelCase					:					Optional[Any]        =	num_choices
           lowerCamelCase					:					Any        =	scope

     def 		a__						(	self:						Optional[int]	)->    List[Any]:
           lowerCamelCase					:					List[Any]        =	ids_tensor([self.batch_size, self.seq_length]     ,		self.vocab_size	)

           lowerCamelCase					:					Dict        =	None
           if self.use_input_mask:
                 lowerCamelCase					:					Tuple        =	random_attention_mask([self.batch_size, self.seq_length]	)

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

           lowerCamelCase					:					List[str]        =	self.get_config()

           return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

     def 		a__						(	self:						Tuple	)->    Union[str, Any]:
           return EsmConfig(
               vocab_size=self.vocab_size     ,		hidden_size=self.hidden_size     ,		pad_token_id=1     ,		num_hidden_layers=self.num_hidden_layers     ,		num_attention_heads=self.num_attention_heads     ,		intermediate_size=self.intermediate_size     ,		hidden_act=self.hidden_act     ,		hidden_dropout_prob=self.hidden_dropout_prob     ,		attention_probs_dropout_prob=self.attention_probs_dropout_prob     ,		max_position_embeddings=self.max_position_embeddings     ,		type_vocab_size=self.type_vocab_size     ,		initializer_range=self.initializer_range     ,		)

     def 		a__						(	self:						List[Any]     ,		__a:						List[str]     ,		__a:						str     ,		__a:						Tuple     ,		__a:						List[str]     ,		__a:						List[str]     ,		__a:						str	)->    int:
           lowerCamelCase					:					Optional[int]        =	EsmModel(config=__a	)
           model.to(__a	)
           model.eval()
           lowerCamelCase					:					int        =	model(__a     ,		attention_mask=__a	)
           lowerCamelCase					:					str        =	model(__a	)
           lowerCamelCase					:					Optional[Any]        =	model(__a	)

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

     def 		a__						(	self:						int     ,		__a:						Union[str, Any]     ,		__a:						Optional[int]     ,		__a:						List[str]     ,		__a:						str     ,		__a:						List[str]     ,		__a:						Tuple	)->    int:
           lowerCamelCase					:					str        =	EsmForMaskedLM(config=__a	)
           model.to(__a	)
           model.eval()
           lowerCamelCase					:					List[Any]        =	model(__a     ,		attention_mask=__a     ,		labels=__a	)
           self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.vocab_size)	)

     def 		a__						(	self:						List[str]     ,		__a:						List[Any]     ,		__a:						List[str]     ,		__a:						int     ,		__a:						Union[str, Any]     ,		__a:						List[Any]     ,		__a:						Tuple	)->    List[str]:
           lowerCamelCase					:					Tuple        =	self.num_labels
           lowerCamelCase					:					Dict        =	EsmForTokenClassification(config=__a	)
           model.to(__a	)
           model.eval()
           lowerCamelCase					:					int        =	model(__a     ,		attention_mask=__a     ,		labels=__a	)
           self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.num_labels)	)







     def 		a__						(	self:						Optional[int]	)->    Optional[int]:
           lowerCamelCase					:					Any        =	self.prepare_config_and_inputs()
           (
               (
               lowerCamelCase
           )     ,			(
               lowerCamelCase
           )     ,			(
               lowerCamelCase
           )     ,			(
               lowerCamelCase
           )     ,			(
               lowerCamelCase
           )     ,			(
               lowerCamelCase
           )     ,			
           )					:					Tuple        =	config_and_inputs
           lowerCamelCase					:					List[Any]        =	{"""input_ids""": input_ids, """attention_mask""": input_mask}
           return config, inputs_dict


@require_torch
class 			A__	(						__lowercase ,     __lowercase ,     unittest.TestCase):


     """simple docstring"""
     snake_case__	:					Any													=False

     snake_case__	:					Dict													=(
         (
             EsmForMaskedLM,
             EsmModel,
             EsmForSequenceClassification,
             EsmForTokenClassification,
         )
         if is_torch_available()
         else ()
     )
     snake_case__	:					Dict													=()
     snake_case__	:					Optional[int]													=(
         {
             '''feature-extraction''': EsmModel,
             '''fill-mask''': EsmForMaskedLM,
             '''text-classification''': EsmForSequenceClassification,
             '''token-classification''': EsmForTokenClassification,
             '''zero-shot''': EsmForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     snake_case__	:					Any													=True

     def 		a__						(	self:						Optional[int]	)->    Optional[int]:
           lowerCamelCase					:					Optional[Any]        =	EsmModelTester(self	)
           lowerCamelCase					:					Any        =	ConfigTester(self     ,		config_class=__a     ,		hidden_size=37	)

     def 		a__						(	self:						List[Any]	)->    Optional[Any]:
           self.config_tester.run_common_tests()

     def 		a__						(	self:						int	)->    Optional[Any]:
           lowerCamelCase					:					Union[str, Any]        =	self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*__a	)

     def 		a__						(	self:						Tuple	)->    Any:
           lowerCamelCase					:					List[str]        =	self.model_tester.prepare_config_and_inputs()
           for type in ["absolute", "relative_key", "relative_key_query"]:
                 lowerCamelCase					:					Tuple        =	type
                 self.model_tester.create_and_check_model(*__a	)

     def 		a__						(	self:						List[str]	)->    Tuple:
           lowerCamelCase					:					Optional[int]        =	self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*__a	)

     def 		a__						(	self:						int	)->    Optional[Any]:
           lowerCamelCase					:					List[Any]        =	self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*__a	)

     @slow
     def 		a__						(	self:						Any	)->    List[Any]:
           for model_name in ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 lowerCamelCase					:					int        =	EsmModel.from_pretrained(__a	)
                 self.assertIsNotNone(__a	)

     def 		a__						(	self:						str	)->    List[str]:
           lowerCamelCase					:					Union[str, Any]        =	self.model_tester.prepare_config_and_inputs()[0]
           lowerCamelCase					:					Union[str, Any]        =	EsmEmbeddings(config=__a	)

           lowerCamelCase					:					List[str]        =	torch.as_tensor([[12, 31, 13, model.padding_idx]]	)
           lowerCamelCase					:					Union[str, Any]        =	torch.as_tensor(
               [
                   [
                       0 + model.padding_idx + 1,
                       1 + model.padding_idx + 1,
                       2 + model.padding_idx + 1,
                       model.padding_idx,
                   ]
               ]	)
           lowerCamelCase					:					Optional[Any]        =	create_position_ids_from_input_ids(__a     ,		model.padding_idx	)
           self.assertEqual(position_ids.shape     ,		expected_positions.shape	)
           self.assertTrue(torch.all(torch.eq(__a     ,		__a	)	)	)

     def 		a__						(	self:						Optional[int]	)->    int:
           lowerCamelCase					:					List[str]        =	self.model_tester.prepare_config_and_inputs()[0]
           lowerCamelCase					:					Any        =	EsmEmbeddings(config=__a	)

           lowerCamelCase					:					Dict        =	torch.empty(2     ,		4     ,		30	)
           lowerCamelCase					:					List[Any]        =	[
               0 + embeddings.padding_idx + 1,
               1 + embeddings.padding_idx + 1,
               2 + embeddings.padding_idx + 1,
               3 + embeddings.padding_idx + 1,
           ]
           lowerCamelCase					:					Any        =	torch.as_tensor([expected_single_positions, expected_single_positions]	)
           lowerCamelCase					:					List[str]        =	embeddings.create_position_ids_from_inputs_embeds(__a	)
           self.assertEqual(position_ids.shape     ,		expected_positions.shape	)
           self.assertTrue(torch.all(torch.eq(__a     ,		__a	)	)	)

     @unittest.skip("""Esm does not support embedding resizing"""	)
     def 		a__						(	self:						Any	)->    Optional[Any]:
           pass

     @unittest.skip("""Esm does not support embedding resizing"""	)
     def 		a__						(	self:						Dict	)->    Dict:
           pass







     @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""	)
     def 		a__						(	self:						List[str]	)->    Dict:
           pass


@require_torch
class 			A__	(						__lowercase):


     """simple docstring"""

     @slow
     def 		a__						(	self:						Any	)->    Union[str, Any]:
           with torch.no_grad():
                 lowerCamelCase					:					Union[str, Any]        =	EsmForMaskedLM.from_pretrained("""facebook/esm2_t6_8M_UR50D"""	)
                 model.eval()
                 lowerCamelCase					:					List[str]        =	torch.tensor([[0, 1, 2, 3, 4, 5]]	)
                 lowerCamelCase					:					Tuple        =	model(__a	)[0]

                 lowerCamelCase					:					Dict        =	33

                 lowerCamelCase					:					List[str]        =	torch.Size((1, 6, vocab_size)	)
                 self.assertEqual(output.shape     ,		__a	)

                 lowerCamelCase					:					Tuple        =	torch.tensor(
                     [[[8.92_15, -10.58_98, -6.46_71], [-6.39_67, -13.91_14, -1.12_12], [-7.78_12, -13.95_16, -3.74_06]]]	)
                 self.assertTrue(torch.allclose(output[:, :3, :3]     ,		__a     ,		atol=1e-4	)	)







     @slow
     def 		a__						(	self:						Dict	)->    str:
           with torch.no_grad():
                 lowerCamelCase					:					Any        =	EsmModel.from_pretrained("""facebook/esm2_t6_8M_UR50D"""	)
                 model.eval()

                 lowerCamelCase					:					Optional[Any]        =	torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]	)
                 lowerCamelCase					:					Any        =	model(__a	)[0]
                 # compare the actual values for a slice.
                 lowerCamelCase					:					Tuple        =	torch.tensor(
                     [[[0.14_44, 0.54_13, 0.32_48], [0.30_34, 0.00_53, 0.31_08], [0.32_28, -0.24_99, 0.34_15]]]	)
                 self.assertTrue(torch.allclose(output[:, :3, :3]     ,		__a     ,		atol=1e-4	)	)




