


'''simple docstring'''



import itertools
import random
import unittest

import numpy as np

from transformers import WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST, WavaVecaConfig, WavaVecaFeatureExtractor
from transformers.testing_utils import require_torch, slow

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


__UpperCAmelCase      :Any			    =       random.Random()




def      _a     (						_lowercase :     Tuple      , _lowercase :     Optional[Any]=1.0      , _lowercase :     List[str]=None      , _lowercase :     Tuple=None  ):





     '''simple docstring'''






     if rng is None:
          __UpperCAmelCase     :			int  							=      global_rng

     __UpperCAmelCase     :			Union[str, Any]  							=      []
     for batch_idx in range(shape[0]  ):
          values.append([]  )
          for _ in range(shape[1]  ):
               values[-1].append(rng.random() * scale  )

     return values



class      a    (		unittest.TestCase	):


     """simple docstring"""






     def __init__(    self					:		Optional[Any]							,			snake_case					:		Optional[int]							,			snake_case					:		List[Any]=7							,			snake_case					:		int=400							,			snake_case					:		Optional[Any]=2000							,			snake_case					:		Union[str, Any]=1							,			snake_case					:		Any=0.0							,			snake_case					:		Tuple=1_6000							,			snake_case					:		Tuple=True							,			snake_case					:		Dict=True							,			)						->							List[Any]:
          __UpperCAmelCase     :			Any  							=      parent
          __UpperCAmelCase     :			Dict  							=      batch_size
          __UpperCAmelCase     :			str  							=      min_seq_length
          __UpperCAmelCase     :			str  							=      max_seq_length
          __UpperCAmelCase     :			Dict  							=      (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
          __UpperCAmelCase     :			Optional[int]  							=      feature_size
          __UpperCAmelCase     :			Any  							=      padding_value
          __UpperCAmelCase     :			List[str]  							=      sampling_rate
          __UpperCAmelCase     :			Optional[Any]  							=      return_attention_mask
          __UpperCAmelCase     :			Any  							=      do_normalize

     def 			lowerCamelCase__			(    self					:		Tuple      )						->							Optional[Any]:
          return {
              "feature_size": self.feature_size,
              "padding_value": self.padding_value,
              "sampling_rate": self.sampling_rate,
              "return_attention_mask": self.return_attention_mask,
              "do_normalize": self.do_normalize,
          }






     def 			lowerCamelCase__			(    self					:		int							,			snake_case					:		Dict=False							,			snake_case					:		List[str]=False      )						->							List[str]:
          def _flatten(snake_case					:		int      ):
               return list(itertools.chain(*snake_case      )      )

          if equal_length:
               __UpperCAmelCase     :			Dict  							=      floats_list((self.batch_size, self.max_seq_length)      )
          else:
               # make sure that inputs increase in size
               __UpperCAmelCase     :			Any  							=      [
                   _flatten(floats_list((x, self.feature_size)      )      )
                   for x in range(self.min_seq_length							,			self.max_seq_length							,			self.seq_length_diff      )
               ]

          if numpify:
               __UpperCAmelCase     :			Any  							=      [np.asarray(snake_case      ) for x in speech_inputs]

          return speech_inputs



class      a    (		_a     ,  unittest.TestCase	):


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			int							       =       WavaVecaFeatureExtractor

     def 			lowerCamelCase__			(    self					:		Tuple      )						->							Optional[int]:
          __UpperCAmelCase     :			Dict  							=      WavaVecaFeatureExtractionTester(self      )

     def 			lowerCamelCase__			(    self					:		Any							,			snake_case					:		Tuple      )						->							Optional[Any]:
          self.assertTrue(np.all(np.mean(snake_case							,			axis=0      ) < 1E-3      )      )
          self.assertTrue(np.all(np.abs(np.var(snake_case							,			axis=0      ) - 1      ) < 1E-3      )      )

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

          # Test not batched input
          __UpperCAmelCase     :			int  							=      feat_extract(speech_inputs[0]							,			return_tensors='''np'''      ).input_values
          __UpperCAmelCase     :			List[Any]  							=      feat_extract(np_speech_inputs[0]							,			return_tensors='''np'''      ).input_values
          self.assertTrue(np.allclose(snake_case							,			snake_case							,			atol=1E-3      )      )

          # Test batched
          __UpperCAmelCase     :			Tuple  							=      feat_extract(snake_case							,			return_tensors='''np'''      ).input_values
          __UpperCAmelCase     :			Dict  							=      feat_extract(snake_case							,			return_tensors='''np'''      ).input_values
          for enc_seq_a, enc_seq_a in zip(snake_case							,			snake_case      ):
               self.assertTrue(np.allclose(snake_case							,			snake_case							,			atol=1E-3      )      )

          # Test 2-D numpy arrays are batched.
          __UpperCAmelCase     :			Optional[Any]  							=      [floats_list((1, x)      )[0] for x in (800, 800, 800)]
          __UpperCAmelCase     :			Union[str, Any]  							=      np.asarray(snake_case      )
          __UpperCAmelCase     :			List[str]  							=      feat_extract(snake_case							,			return_tensors='''np'''      ).input_values
          __UpperCAmelCase     :			Dict  							=      feat_extract(snake_case							,			return_tensors='''np'''      ).input_values
          for enc_seq_a, enc_seq_a in zip(snake_case							,			snake_case      ):
               self.assertTrue(np.allclose(snake_case							,			snake_case							,			atol=1E-3      )      )

     def 			lowerCamelCase__			(    self					:		List[Any]      )						->							int:
          __UpperCAmelCase     :			int  							=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()      )
          __UpperCAmelCase     :			str  							=      [floats_list((1, x)      )[0] for x in range(800							,			1400							,			200      )]

          __UpperCAmelCase     :			Union[str, Any]  							=      ['''longest''', '''max_length''', '''do_not_pad''']
          __UpperCAmelCase     :			str  							=      [None, 1600, None]
          for max_length, padding in zip(snake_case							,			snake_case      ):
               __UpperCAmelCase     :			Any  							=      feat_extract(snake_case							,			padding=snake_case							,			max_length=snake_case							,			return_tensors='''np'''      )
               __UpperCAmelCase     :			List[str]  							=      processed.input_values

               self._check_zero_mean_unit_variance(input_values[0][:800]      )
               self.assertTrue(input_values[0][800:].sum() < 1E-6      )
               self._check_zero_mean_unit_variance(input_values[1][:1000]      )
               self.assertTrue(input_values[0][1000:].sum() < 1E-6      )
               self._check_zero_mean_unit_variance(input_values[2][:1200]      )

     def 			lowerCamelCase__			(    self					:		List[str]      )						->							Tuple:
          __UpperCAmelCase     :			Any  							=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()      )
          __UpperCAmelCase     :			Any  							=      range(800							,			1400							,			200      )
          __UpperCAmelCase     :			Union[str, Any]  							=      [floats_list((1, x)      )[0] for x in lengths]

          __UpperCAmelCase     :			List[Any]  							=      ['''longest''', '''max_length''', '''do_not_pad''']
          __UpperCAmelCase     :			Tuple  							=      [None, 1600, None]

          for max_length, padding in zip(snake_case							,			snake_case      ):
               __UpperCAmelCase     :			Any  							=      feat_extract(snake_case							,			max_length=snake_case							,			padding=snake_case      )
               __UpperCAmelCase     :			Optional[int]  							=      processed.input_values

               self._check_zero_mean_unit_variance(input_values[0][:800]      )
               self._check_zero_mean_unit_variance(input_values[1][:1000]      )
               self._check_zero_mean_unit_variance(input_values[2][:1200]      )

     def 			lowerCamelCase__			(    self					:		int      )						->							Any:
          __UpperCAmelCase     :			Dict  							=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()      )
          __UpperCAmelCase     :			List[str]  							=      [floats_list((1, x)      )[0] for x in range(800							,			1400							,			200      )]
          __UpperCAmelCase     :			Optional[int]  							=      feat_extract(
              snake_case							,			truncation=snake_case							,			max_length=1000							,			padding='''max_length'''							,			return_tensors='''np'''      )
          __UpperCAmelCase     :			Dict  							=      processed.input_values

          self._check_zero_mean_unit_variance(input_values[0, :800]      )
          self._check_zero_mean_unit_variance(input_values[1]      )
          self._check_zero_mean_unit_variance(input_values[2]      )

     def 			lowerCamelCase__			(    self					:		Optional[Any]      )						->							Optional[int]:
          __UpperCAmelCase     :			Tuple  							=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()      )
          __UpperCAmelCase     :			Optional[int]  							=      [floats_list((1, x)      )[0] for x in range(800							,			1400							,			200      )]
          __UpperCAmelCase     :			Any  							=      feat_extract(
              snake_case							,			truncation=snake_case							,			max_length=1000							,			padding='''longest'''							,			return_tensors='''np'''      )
          __UpperCAmelCase     :			List[Any]  							=      processed.input_values

          self._check_zero_mean_unit_variance(input_values[0, :800]      )
          self._check_zero_mean_unit_variance(input_values[1, :1000]      )
          self._check_zero_mean_unit_variance(input_values[2]      )

          # make sure that if max_length < longest -> then pad to max_length
          self.assertTrue(input_values.shape == (3, 1000)      )

          __UpperCAmelCase     :			List[Any]  							=      [floats_list((1, x)      )[0] for x in range(800							,			1400							,			200      )]
          __UpperCAmelCase     :			List[str]  							=      feat_extract(
              snake_case							,			truncation=snake_case							,			max_length=2000							,			padding='''longest'''							,			return_tensors='''np'''      )
          __UpperCAmelCase     :			Optional[Any]  							=      processed.input_values

          self._check_zero_mean_unit_variance(input_values[0, :800]      )
          self._check_zero_mean_unit_variance(input_values[1, :1000]      )
          self._check_zero_mean_unit_variance(input_values[2]      )

          # make sure that if max_length > longest -> then pad to longest
          self.assertTrue(input_values.shape == (3, 1200)      )

     @require_torch
     def 			lowerCamelCase__			(    self					:		List[Any]      )						->							Optional[int]:
          import torch

          __UpperCAmelCase     :			str  							=      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()      )
          __UpperCAmelCase     :			Dict  							=      np.random.rand(100      ).astype(np.floataa      )
          __UpperCAmelCase     :			Dict  							=      np_speech_inputs.tolist()

          for inputs in [py_speech_inputs, np_speech_inputs]:
               __UpperCAmelCase     :			Optional[int]  							=      feature_extractor.pad([{'''input_values''': inputs}]							,			return_tensors='''np'''      )
               self.assertTrue(np_processed.input_values.dtype == np.floataa      )
               __UpperCAmelCase     :			List[str]  							=      feature_extractor.pad([{'''input_values''': inputs}]							,			return_tensors='''pt'''      )
               self.assertTrue(pt_processed.input_values.dtype == torch.floataa      )






     @slow
     @require_torch
     def 			lowerCamelCase__			(    self					:		str      )						->							Dict:
          # this test makes sure that models that are using
          # group norm don't have their feature extractor return the
          # attention_mask
          for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
               __UpperCAmelCase     :			Any  							=      WavaVecaConfig.from_pretrained(snake_case      )
               __UpperCAmelCase     :			List[str]  							=      WavaVecaFeatureExtractor.from_pretrained(snake_case      )

               # only "layer" feature extraction norm should make use of
               # attention_mask
               self.assertEqual(feat_extract.return_attention_mask							,			config.feat_extract_norm == '''layer'''      )



'''simple docstring'''



import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import 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 (
          MODEL_FOR_PRETRAINING_MAPPING,
          AlbertForMaskedLM,
          AlbertForMultipleChoice,
          AlbertForPreTraining,
          AlbertForQuestionAnswering,
          AlbertForSequenceClassification,
          AlbertForTokenClassification,
          AlbertModel,
      )
      from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST



class      a    :


     """simple docstring"""






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

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

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

          __UpperCAmelCase     :			Dict  							=      None
          if self.use_token_type_ids:
               __UpperCAmelCase     :			Optional[Any]  							=      ids_tensor([self.batch_size, self.seq_length]							,			self.type_vocab_size      )

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

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

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

     def 			lowerCamelCase__			(    self					:		List[str]      )						->							Optional[Any]:
          return AlbertConfig(
              vocab_size=self.vocab_size							,			hidden_size=self.hidden_size							,			num_hidden_layers=self.num_hidden_layers							,			num_attention_heads=self.num_attention_heads							,			intermediate_size=self.intermediate_size							,			hidden_act=self.hidden_act							,			hidden_dropout_prob=self.hidden_dropout_prob							,			attention_probs_dropout_prob=self.attention_probs_dropout_prob							,			max_position_embeddings=self.max_position_embeddings							,			type_vocab_size=self.type_vocab_size							,			initializer_range=self.initializer_range							,			num_hidden_groups=self.num_hidden_groups							,			)

     def 			lowerCamelCase__			(    self					:		Tuple							,			snake_case					:		Optional[Any]							,			snake_case					:		Optional[int]							,			snake_case					:		List[Any]							,			snake_case					:		Optional[Any]							,			snake_case					:		Optional[int]							,			snake_case					:		Union[str, Any]							,			snake_case					:		int      )						->							Optional[int]:
          __UpperCAmelCase     :			List[Any]  							=      AlbertModel(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			Tuple  							=      model(snake_case							,			attention_mask=snake_case							,			token_type_ids=snake_case      )
          __UpperCAmelCase     :			List[str]  							=      model(snake_case							,			token_type_ids=snake_case      )
          __UpperCAmelCase     :			str  							=      model(snake_case      )
          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 			lowerCamelCase__			(    self					:		List[str]							,			snake_case					:		str							,			snake_case					:		Optional[int]							,			snake_case					:		List[Any]							,			snake_case					:		Any							,			snake_case					:		Dict							,			snake_case					:		Dict							,			snake_case					:		Optional[int]      )						->							Optional[int]:
          __UpperCAmelCase     :			str  							=      AlbertForPreTraining(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			Union[str, Any]  							=      model(
              snake_case							,			attention_mask=snake_case							,			token_type_ids=snake_case							,			labels=snake_case							,			sentence_order_label=snake_case							,			)
          self.parent.assertEqual(result.prediction_logits.shape							,			(self.batch_size, self.seq_length, self.vocab_size)      )
          self.parent.assertEqual(result.sop_logits.shape							,			(self.batch_size, config.num_labels)      )

     def 			lowerCamelCase__			(    self					:		Dict							,			snake_case					:		Union[str, Any]							,			snake_case					:		Dict							,			snake_case					:		Any							,			snake_case					:		Tuple							,			snake_case					:		Union[str, Any]							,			snake_case					:		Any							,			snake_case					:		Tuple      )						->							Union[str, Any]:
          __UpperCAmelCase     :			Dict  							=      AlbertForMaskedLM(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			str  							=      model(snake_case							,			attention_mask=snake_case							,			token_type_ids=snake_case							,			labels=snake_case      )
          self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.seq_length, self.vocab_size)      )

     def 			lowerCamelCase__			(    self					:		str							,			snake_case					:		Tuple							,			snake_case					:		List[str]							,			snake_case					:		Union[str, Any]							,			snake_case					:		List[str]							,			snake_case					:		Tuple							,			snake_case					:		Optional[Any]							,			snake_case					:		Tuple      )						->							int:
          __UpperCAmelCase     :			Optional[Any]  							=      AlbertForQuestionAnswering(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			Optional[Any]  							=      model(
              snake_case							,			attention_mask=snake_case							,			token_type_ids=snake_case							,			start_positions=snake_case							,			end_positions=snake_case							,			)
          self.parent.assertEqual(result.start_logits.shape							,			(self.batch_size, self.seq_length)      )
          self.parent.assertEqual(result.end_logits.shape							,			(self.batch_size, self.seq_length)      )

     def 			lowerCamelCase__			(    self					:		Tuple							,			snake_case					:		List[str]							,			snake_case					:		Dict							,			snake_case					:		Optional[int]							,			snake_case					:		Dict							,			snake_case					:		int							,			snake_case					:		Optional[int]							,			snake_case					:		Optional[Any]      )						->							Any:
          __UpperCAmelCase     :			Optional[int]  							=      self.num_labels
          __UpperCAmelCase     :			Any  							=      AlbertForSequenceClassification(snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			str  							=      model(snake_case							,			attention_mask=snake_case							,			token_type_ids=snake_case							,			labels=snake_case      )
          self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.num_labels)      )

     def 			lowerCamelCase__			(    self					:		Tuple							,			snake_case					:		Tuple							,			snake_case					:		List[Any]							,			snake_case					:		Optional[int]							,			snake_case					:		str							,			snake_case					:		Dict							,			snake_case					:		Union[str, Any]							,			snake_case					:		List[str]      )						->							int:
          __UpperCAmelCase     :			Optional[int]  							=      self.num_labels
          __UpperCAmelCase     :			Optional[int]  							=      AlbertForTokenClassification(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			str  							=      model(snake_case							,			attention_mask=snake_case							,			token_type_ids=snake_case							,			labels=snake_case      )
          self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.seq_length, self.num_labels)      )

     def 			lowerCamelCase__			(    self					:		Tuple							,			snake_case					:		Tuple							,			snake_case					:		List[Any]							,			snake_case					:		Dict							,			snake_case					:		int							,			snake_case					:		List[Any]							,			snake_case					:		List[Any]							,			snake_case					:		Optional[Any]      )						->							Tuple:
          __UpperCAmelCase     :			Optional[int]  							=      self.num_choices
          __UpperCAmelCase     :			List[Any]  							=      AlbertForMultipleChoice(config=snake_case      )
          model.to(snake_case      )
          model.eval()
          __UpperCAmelCase     :			Dict  							=      input_ids.unsqueeze(1      ).expand(-1							,			self.num_choices							,			-1      ).contiguous()
          __UpperCAmelCase     :			List[Any]  							=      token_type_ids.unsqueeze(1      ).expand(-1							,			self.num_choices							,			-1      ).contiguous()
          __UpperCAmelCase     :			List[Any]  							=      input_mask.unsqueeze(1      ).expand(-1							,			self.num_choices							,			-1      ).contiguous()
          __UpperCAmelCase     :			List[str]  							=      model(
              snake_case							,			attention_mask=snake_case							,			token_type_ids=snake_case							,			labels=snake_case							,			)
          self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.num_choices)      )






     def 			lowerCamelCase__			(    self					:		Union[str, Any]      )						->							Any:
          __UpperCAmelCase     :			List[Any]  							=      self.prepare_config_and_inputs()
          (
              (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       (
              __UpperCAmelCase
          )							,       
          )     :			List[Any]  							=      config_and_inputs
          __UpperCAmelCase     :			List[str]  							=      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
          return config, inputs_dict



@require_torch
class      a    (		_a     ,  _a     ,  unittest.TestCase	):


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			Tuple							       =       (
         (
             AlbertModel,
             AlbertForPreTraining,
             AlbertForMaskedLM,
             AlbertForMultipleChoice,
             AlbertForSequenceClassification,
             AlbertForTokenClassification,
             AlbertForQuestionAnswering,
         )
         if is_torch_available()
         else ()
     )
     SCREAMING_SNAKE_CASE	:			Any							       =       (
         {
             "feature-extraction": AlbertModel,
             "fill-mask": AlbertForMaskedLM,
             "question-answering": AlbertForQuestionAnswering,
             "text-classification": AlbertForSequenceClassification,
             "token-classification": AlbertForTokenClassification,
             "zero-shot": AlbertForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     SCREAMING_SNAKE_CASE	:			Any							       =       True

     def 			lowerCamelCase__			(    self					:		Optional[int]							,			snake_case					:		Any							,			snake_case					:		Dict							,			snake_case					:		Tuple=False      )						->							Optional[Any]:
          __UpperCAmelCase     :			Any  							=      super()._prepare_for_class(snake_case							,			snake_case							,			return_labels=snake_case      )

          if return_labels:
               if model_class in get_values(snake_case      ):
                    __UpperCAmelCase     :			Dict  							=      torch.zeros(
                        (self.model_tester.batch_size, self.model_tester.seq_length)							,			dtype=torch.long							,			device=snake_case      )
                    __UpperCAmelCase     :			Union[str, Any]  							=      torch.zeros(
                        self.model_tester.batch_size							,			dtype=torch.long							,			device=snake_case      )
          return inputs_dict

     def 			lowerCamelCase__			(    self					:		Dict      )						->							int:
          __UpperCAmelCase     :			List[Any]  							=      AlbertModelTester(self      )
          __UpperCAmelCase     :			Any  							=      ConfigTester(self							,			config_class=snake_case							,			hidden_size=37      )

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

     def 			lowerCamelCase__			(    self					:		Any      )						->							Any:
          __UpperCAmelCase     :			Union[str, Any]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case      )

     def 			lowerCamelCase__			(    self					:		Any      )						->							Optional[Any]:
          __UpperCAmelCase     :			Optional[int]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_pretraining(*snake_case      )

     def 			lowerCamelCase__			(    self					:		Optional[int]      )						->							Optional[Any]:
          __UpperCAmelCase     :			Optional[int]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*snake_case      )

     def 			lowerCamelCase__			(    self					:		Union[str, Any]      )						->							Tuple:
          __UpperCAmelCase     :			Dict  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_multiple_choice(*snake_case      )

     def 			lowerCamelCase__			(    self					:		Dict      )						->							str:
          __UpperCAmelCase     :			Union[str, Any]  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*snake_case      )

     def 			lowerCamelCase__			(    self					:		List[str]      )						->							Tuple:
          __UpperCAmelCase     :			Any  							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*snake_case      )

     def 			lowerCamelCase__			(    self					:		str      )						->							Any:
          __UpperCAmelCase     :			int  							=      self.model_tester.prepare_config_and_inputs()
          for type in ["absolute", "relative_key", "relative_key_query"]:
               __UpperCAmelCase     :			Tuple  							=      type
               self.model_tester.create_and_check_model(*snake_case      )






     @slow
     def 			lowerCamelCase__			(    self					:		Tuple      )						->							Optional[int]:
          for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __UpperCAmelCase     :			List[Any]  							=      AlbertModel.from_pretrained(snake_case      )
               self.assertIsNotNone(snake_case      )



@require_torch
class      a    (		unittest.TestCase	):


     """simple docstring"""






     @slow
     def 			lowerCamelCase__			(    self					:		Optional[Any]      )						->							Union[str, Any]:
          __UpperCAmelCase     :			Optional[int]  							=      AlbertModel.from_pretrained('''albert-base-v2'''      )
          __UpperCAmelCase     :			str  							=      torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]      )
          __UpperCAmelCase     :			List[Any]  							=      torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
          with torch.no_grad():
               __UpperCAmelCase     :			Optional[int]  							=      model(snake_case							,			attention_mask=snake_case      )[0]
          __UpperCAmelCase     :			Any  							=      torch.Size((1, 11, 768)      )
          self.assertEqual(output.shape							,			snake_case      )
          __UpperCAmelCase     :			int  							=      torch.tensor(
              [[[-0.6_513, 1.5_035, -0.2_766], [-0.6_515, 1.5_046, -0.2_780], [-0.6_512, 1.5_049, -0.2_784]]]      )

          self.assertTrue(torch.allclose(output[:, 1:4, 1:4]							,			snake_case							,			atol=1E-4      )      )