


"""simple docstring"""







import pickle
import shutil
import tempfile
import unittest

from transformers import SPIECE_UNDERLINE, XGLMTokenizer, XGLMTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin


__lowercase    					=      get_tests_dir("""fixtures/test_sentencepiece.model""")






@require_sentencepiece
@require_tokenizers
class 						_A  (  _a    ,unittest.TestCase  ):







    """simple docstring"""




    UpperCAmelCase       :							str	=       XGLMTokenizer
    UpperCAmelCase       :							Dict	=       XGLMTokenizerFast
    UpperCAmelCase       :							Optional[Any]	=       True
    UpperCAmelCase       :							Any	=       True






    def 	__snake_case							(					self				:    int):
      super().setUp()

      # We have a SentencePiece fixture for testing
      a						:		Optional[int]      							=			XGLMTokenizer(__UpperCAmelCase				, keep_accents=__UpperCAmelCase)
      tokenizer.save_pretrained(self.tmpdirname)






    def 	__snake_case							(					self				:    str):
      a						:		str      							=			"<pad>"
      a						:		str      							=			1

      self.assertEqual(self.get_tokenizer()._convert_token_to_id(__UpperCAmelCase)				, __UpperCAmelCase)
      self.assertEqual(self.get_tokenizer()._convert_id_to_token(__UpperCAmelCase)				, __UpperCAmelCase)






    def 	__snake_case							(					self				:    List[str]):
      a						:		int      							=			list(self.get_tokenizer().get_vocab().keys())

      self.assertEqual(vocab_keys[0]				, "<s>")
      self.assertEqual(vocab_keys[1]				, "<pad>")
      self.assertEqual(len(__UpperCAmelCase)				, 1008)






    def 	__snake_case							(					self				:    int):
      self.assertEqual(self.get_tokenizer().vocab_size				, 1008)






    def 	__snake_case							(					self				:    Union[str, Any]):
      a						:		Optional[int]      							=			XGLMTokenizer(__UpperCAmelCase				, keep_accents=__UpperCAmelCase)

      a						:		Optional[int]      							=			tokenizer.tokenize("This is a test")
      self.assertListEqual(__UpperCAmelCase				, ["▁This", "▁is", "▁a", "▁t", "est"])

      self.assertListEqual(
          tokenizer.convert_tokens_to_ids(__UpperCAmelCase)				, [value + tokenizer.fairseq_offset for value in [285, 46, 10, 170, 382]]				, )

      a						:		str      							=			tokenizer.tokenize("I was born in 92000, and this is falsé.")
      self.assertListEqual(
          __UpperCAmelCase				, [
              SPIECE_UNDERLINE + "I",
              SPIECE_UNDERLINE + "was",
              SPIECE_UNDERLINE + "b",
              "or",
              "n",
              SPIECE_UNDERLINE + "in",
              SPIECE_UNDERLINE + "",
              "9",
              "2",
              "0",
              "0",
              "0",
              ",",
              SPIECE_UNDERLINE + "and",
              SPIECE_UNDERLINE + "this",
              SPIECE_UNDERLINE + "is",
              SPIECE_UNDERLINE + "f",
              "al",
              "s",
              "é",
              ".",
          ]				, )
      a						:		int      							=			tokenizer.convert_tokens_to_ids(__UpperCAmelCase)
      self.assertListEqual(
          __UpperCAmelCase				, [
              value + tokenizer.fairseq_offset
              for value in [8, 21, 84, 55, 24, 19, 7, 2, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 2, 4]
          ]				, )

      a						:		int      							=			tokenizer.convert_ids_to_tokens(__UpperCAmelCase)
      self.assertListEqual(
          __UpperCAmelCase				, [
              SPIECE_UNDERLINE + "I",
              SPIECE_UNDERLINE + "was",
              SPIECE_UNDERLINE + "b",
              "or",
              "n",
              SPIECE_UNDERLINE + "in",
              SPIECE_UNDERLINE + "",
              "<unk>",
              "2",
              "0",
              "0",
              "0",
              ",",
              SPIECE_UNDERLINE + "and",
              SPIECE_UNDERLINE + "this",
              SPIECE_UNDERLINE + "is",
              SPIECE_UNDERLINE + "f",
              "al",
              "s",
              "<unk>",
              ".",
          ]				, )






    @cached_property
    def 	__snake_case							(					self				:    str):
      return XGLMTokenizer.from_pretrained("facebook/xglm-564M")






    def 	__snake_case							(					self				:    Optional[Any]):
      with tempfile.NamedTemporaryFile() as f:
        shutil.copyfile(__UpperCAmelCase				, f.name)
        a						:		List[str]      							=			XGLMTokenizer(f.name				, keep_accents=__UpperCAmelCase)
        a						:		str      							=			pickle.dumps(__UpperCAmelCase)
      pickle.loads(__UpperCAmelCase)






    def 	__snake_case							(					self				:    List[str]):
      if not self.test_rust_tokenizer:
        return

      a						:		Dict      							=			self.get_tokenizer()
      a						:		Any      							=			self.get_rust_tokenizer()

      a						:		Optional[Any]      							=			"I was born in 92000, and this is falsé."

      a						:		Any      							=			tokenizer.tokenize(__UpperCAmelCase)
      a						:		Optional[Any]      							=			rust_tokenizer.tokenize(__UpperCAmelCase)
      self.assertListEqual(__UpperCAmelCase				, __UpperCAmelCase)

      a						:		Optional[int]      							=			tokenizer.encode(__UpperCAmelCase				, add_special_tokens=__UpperCAmelCase)
      a						:		Optional[Any]      							=			rust_tokenizer.encode(__UpperCAmelCase				, add_special_tokens=__UpperCAmelCase)
      self.assertListEqual(__UpperCAmelCase				, __UpperCAmelCase)

      a						:		str      							=			self.get_rust_tokenizer()
      a						:		int      							=			tokenizer.encode(__UpperCAmelCase)
      a						:		str      							=			rust_tokenizer.encode(__UpperCAmelCase)
      self.assertListEqual(__UpperCAmelCase				, __UpperCAmelCase)






    @slow
    def 	__snake_case							(					self				:    Optional[int]):
      a						:		Tuple      							=			"Hello World!"
      a						:		Union[str, Any]      							=			[2, 31227, 4447, 35]

      self.assertListEqual(__UpperCAmelCase				, self.big_tokenizer.encode(__UpperCAmelCase))






    @slow
    def 	__snake_case							(					self				:    Any):
      a						:		Optional[Any]      							=			(
          "This is a very long text with a lot of weird characters, such as: . , ~ ? ( ) \" [ ] ! : - . Also we will"
          " add words that should not exsist and be tokenized to unk, such as saoneuhaoesuth"
      )
      # fmt: off
      a						:		str      							=			[2, 1018, 67, 11, 1988, 2617, 5631, 278, 11, 3407, 48, 71630, 28085, 4, 3234, 157, 13, 6, 5, 6, 4, 3526, 768, 15, 659, 57, 298, 3983, 864, 129, 21, 6, 5, 13675, 377, 652, 7580, 10341, 155, 2817, 422, 1666, 7, 1674, 53, 113, 202277, 17892, 33, 60, 87, 4, 3234, 157, 61, 2667, 52376, 19, 88, 23, 735]
      # fmt: on

      self.assertListEqual(__UpperCAmelCase				, self.big_tokenizer.encode(__UpperCAmelCase))






    @slow
    def 	__snake_case							(					self				:    Optional[Any]):
      # fmt: off
      a						:		List[Any]      							=			{
          "input_ids": [[2, 108825, 1163, 15, 88010, 473, 15898, 157, 13672, 1857, 312, 8, 238021, 1163, 53, 13672, 1857, 312, 8, 53283, 182396, 8, 18566, 16, 36733, 4101, 8, 230, 244017, 122553, 7, 15, 132597, 4, 293, 12511, 7610, 4, 3414, 132597, 9, 4, 32361, 362, 4, 734, 28512, 32569, 18, 4, 32361, 26096, 14982, 73, 18715, 21433, 235261, 15, 492, 12427, 16, 53, 18715, 21433, 65454, 15, 23659, 563, 16, 278, 597, 2843, 595, 7931, 182396, 64186, 22, 886, 595, 132981, 53, 25540, 3449, 43982, 39901, 5951, 878, 330, 4, 27694, 80269, 312, 53, 6517, 11780, 611, 20408, 5], [2, 6, 132597, 67, 42897, 33, 592, 8, 163729, 25540, 361, 136997, 109514, 173230, 7, 501, 60, 102913, 196, 5631, 235, 63243, 473, 6, 231757, 74, 5277, 7905, 53, 3095, 37317, 22, 454, 183874, 5], [2, 268, 31298, 46530, 6, 132935, 43831, 7, 597, 32, 24, 3688, 9865, 5]],
          "attention_mask": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
      }  # noqa: E501
      # fmt: on

      self.tokenizer_integration_test_util(
          expected_encoding=__UpperCAmelCase				, model_name="facebook/xglm-564M"				, padding=__UpperCAmelCase				, )








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


  '''simple docstring'''







  def __init__( self			: Optional[Any]			,							UpperCamelCase__			: Optional[Any]			,							UpperCamelCase__			: int=13			,							UpperCamelCase__			: Optional[int]=7			,							UpperCamelCase__			: Any=True			,							UpperCamelCase__			: Optional[int]=True			,							UpperCamelCase__			: int=True			,							UpperCamelCase__			: Optional[Any]=True			,							UpperCamelCase__			: int=99			,							UpperCamelCase__			: Any=16			,							UpperCamelCase__			: str=36			,							UpperCamelCase__			: List[str]=6			,							UpperCamelCase__			: List[str]=6			,							UpperCamelCase__			: Union[str, Any]=6			,							UpperCamelCase__			: int=37			,							UpperCamelCase__			: Optional[int]="gelu"			,							UpperCamelCase__			: List[Any]=0.1			,							UpperCamelCase__			: Optional[int]=0.1			,							UpperCamelCase__			: int=512			,							UpperCamelCase__			: str=16			,							UpperCamelCase__			: int=2			,							UpperCamelCase__			: List[Any]=0.02			,							UpperCamelCase__			: Optional[int]=3			,							UpperCamelCase__			: Optional[Any]=4			,							UpperCamelCase__			: Dict=None			,							)			->	Any:







    """simple docstring"""






    __magic_name__				     =       parent
    __magic_name__				     =       batch_size
    __magic_name__				     =       seq_length
    __magic_name__				     =       is_training
    __magic_name__				     =       use_input_mask
    __magic_name__				     =       use_token_type_ids
    __magic_name__				     =       use_labels
    __magic_name__				     =       vocab_size
    __magic_name__				     =       embedding_size
    __magic_name__				     =       hidden_size
    __magic_name__				     =       num_hidden_layers
    __magic_name__				     =       num_hidden_groups
    __magic_name__				     =       num_attention_heads
    __magic_name__				     =       intermediate_size
    __magic_name__				     =       hidden_act
    __magic_name__				     =       hidden_dropout_prob
    __magic_name__				     =       attention_probs_dropout_prob
    __magic_name__				     =       max_position_embeddings
    __magic_name__				     =       type_vocab_size
    __magic_name__				     =       type_sequence_label_size
    __magic_name__				     =       initializer_range
    __magic_name__				     =       num_labels
    __magic_name__				     =       num_choices
    __magic_name__				     =       scope
  def 							_lowercase							( self			: Tuple    )			->	Dict:







    """simple docstring"""






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

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

    __magic_name__				     =       None
    if self.use_token_type_ids:
      __magic_name__				     =       ids_tensor([self.batch_size, self.seq_length]			,							self.type_vocab_size    )

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

    __magic_name__				     =       self.get_config()

    return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
  def 							_lowercase							( self			: Any    )			->	List[Any]:







    """simple docstring"""






    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 							_lowercase							( self			: int			,							UpperCamelCase__			: Any			,							UpperCamelCase__			: Tuple			,							UpperCamelCase__			: int			,							UpperCamelCase__			: Dict			,							UpperCamelCase__			: List[Any]			,							UpperCamelCase__			: Optional[Any]			,							UpperCamelCase__			: Optional[Any]    )			->	Tuple:







    """simple docstring"""






    __magic_name__				     =       AlbertModel(config=UpperCamelCase__    )
    model.to(UpperCamelCase__    )
    model.eval()
    __magic_name__				     =       model(UpperCamelCase__			,							attention_mask=UpperCamelCase__			,							token_type_ids=UpperCamelCase__    )
    __magic_name__				     =       model(UpperCamelCase__			,							token_type_ids=UpperCamelCase__    )
    __magic_name__				     =       model(UpperCamelCase__    )
    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 							_lowercase							( self			: Optional[int]			,							UpperCamelCase__			: int			,							UpperCamelCase__			: Optional[int]			,							UpperCamelCase__			: Dict			,							UpperCamelCase__			: int			,							UpperCamelCase__			: Union[str, Any]			,							UpperCamelCase__			: Union[str, Any]			,							UpperCamelCase__			: Union[str, Any]    )			->	str:







    """simple docstring"""






    __magic_name__				     =       AlbertForPreTraining(config=UpperCamelCase__    )
    model.to(UpperCamelCase__    )
    model.eval()
    __magic_name__				     =       model(
        UpperCamelCase__			,							attention_mask=UpperCamelCase__			,							token_type_ids=UpperCamelCase__			,							labels=UpperCamelCase__			,							sentence_order_label=UpperCamelCase__			,							)
    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 							_lowercase							( self			: Union[str, Any]			,							UpperCamelCase__			: Union[str, Any]			,							UpperCamelCase__			: int			,							UpperCamelCase__			: List[Any]			,							UpperCamelCase__			: Tuple			,							UpperCamelCase__			: Any			,							UpperCamelCase__			: List[str]			,							UpperCamelCase__			: Tuple    )			->	Dict:







    """simple docstring"""






    __magic_name__				     =       AlbertForMaskedLM(config=UpperCamelCase__    )
    model.to(UpperCamelCase__    )
    model.eval()
    __magic_name__				     =       model(UpperCamelCase__			,							attention_mask=UpperCamelCase__			,							token_type_ids=UpperCamelCase__			,							labels=UpperCamelCase__    )
    self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.seq_length, self.vocab_size)    )
  def 							_lowercase							( self			: Union[str, Any]			,							UpperCamelCase__			: int			,							UpperCamelCase__			: Union[str, Any]			,							UpperCamelCase__			: str			,							UpperCamelCase__			: str			,							UpperCamelCase__			: Union[str, Any]			,							UpperCamelCase__			: Optional[int]			,							UpperCamelCase__			: Tuple    )			->	List[Any]:







    """simple docstring"""






    __magic_name__				     =       AlbertForQuestionAnswering(config=UpperCamelCase__    )
    model.to(UpperCamelCase__    )
    model.eval()
    __magic_name__				     =       model(
        UpperCamelCase__			,							attention_mask=UpperCamelCase__			,							token_type_ids=UpperCamelCase__			,							start_positions=UpperCamelCase__			,							end_positions=UpperCamelCase__			,							)
    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 							_lowercase							( self			: Union[str, Any]			,							UpperCamelCase__			: Union[str, Any]			,							UpperCamelCase__			: str			,							UpperCamelCase__			: Optional[Any]			,							UpperCamelCase__			: List[str]			,							UpperCamelCase__			: Tuple			,							UpperCamelCase__			: Tuple			,							UpperCamelCase__			: int    )			->	Tuple:







    """simple docstring"""






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







    """simple docstring"""






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







    """simple docstring"""






    __magic_name__				     =       self.num_choices
    __magic_name__				     =       AlbertForMultipleChoice(config=UpperCamelCase__    )
    model.to(UpperCamelCase__    )
    model.eval()
    __magic_name__				     =       input_ids.unsqueeze(1    ).expand(-1			,							self.num_choices			,							-1    ).contiguous()
    __magic_name__				     =       token_type_ids.unsqueeze(1    ).expand(-1			,							self.num_choices			,							-1    ).contiguous()
    __magic_name__				     =       input_mask.unsqueeze(1    ).expand(-1			,							self.num_choices			,							-1    ).contiguous()
    __magic_name__				     =       model(
        UpperCamelCase__			,							attention_mask=UpperCamelCase__			,							token_type_ids=UpperCamelCase__			,							labels=UpperCamelCase__			,							)
    self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.num_choices)    )





  def 							_lowercase							( self			: int    )			->	Optional[int]:







    """simple docstring"""






    __magic_name__				     =       self.prepare_config_and_inputs()
    (
        (
        __magic_name__
    )     ,    (
        __magic_name__
    )     ,    (
        __magic_name__
    )     ,    (
        __magic_name__
    )     ,    (
        __magic_name__
    )     ,    (
        __magic_name__
    )     ,    (
        __magic_name__
    )     ,    
    )				     =       config_and_inputs
    __magic_name__				     =       {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
    return config, inputs_dict







@require_torch
class        UpperCAmelCase_			( _A  ,       _A  ,       unittest.TestCase     ):


  '''simple docstring'''







  a__           =		(
      (
          AlbertModel,
          AlbertForPreTraining,
          AlbertForMaskedLM,
          AlbertForMultipleChoice,
          AlbertForSequenceClassification,
          AlbertForTokenClassification,
          AlbertForQuestionAnswering,
      )
      if is_torch_available()
      else ()
  )
  a__           =		(
      {
          """feature-extraction""": AlbertModel,
          """fill-mask""": AlbertForMaskedLM,
          """question-answering""": AlbertForQuestionAnswering,
          """text-classification""": AlbertForSequenceClassification,
          """token-classification""": AlbertForTokenClassification,
          """zero-shot""": AlbertForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  a__           =		True
  def 							_lowercase							( self			: str			,							UpperCamelCase__			: Any			,							UpperCamelCase__			: Dict			,							UpperCamelCase__			: Union[str, Any]=False    )			->	Union[str, Any]:







    """simple docstring"""






    __magic_name__				     =       super()._prepare_for_class(UpperCamelCase__			,							UpperCamelCase__			,							return_labels=UpperCamelCase__    )

    if return_labels:
      if model_class in get_values(UpperCamelCase__    ):
        __magic_name__				     =       torch.zeros(
            (self.model_tester.batch_size, self.model_tester.seq_length)			,							dtype=torch.long			,							device=UpperCamelCase__    )
        __magic_name__				     =       torch.zeros(
            self.model_tester.batch_size			,							dtype=torch.long			,							device=UpperCamelCase__    )
    return inputs_dict
  def 							_lowercase							( self			: int    )			->	int:







    """simple docstring"""






    __magic_name__				     =       AlbertModelTester(self    )
    __magic_name__				     =       ConfigTester(self			,							config_class=UpperCamelCase__			,							hidden_size=37    )
  def 							_lowercase							( self			: Optional[int]    )			->	Optional[Any]:







    """simple docstring"""






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







    """simple docstring"""






    __magic_name__				     =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*UpperCamelCase__    )
  def 							_lowercase							( self			: int    )			->	List[str]:







    """simple docstring"""






    __magic_name__				     =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_pretraining(*UpperCamelCase__    )
  def 							_lowercase							( self			: List[Any]    )			->	Any:







    """simple docstring"""






    __magic_name__				     =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__    )
  def 							_lowercase							( self			: Dict    )			->	Tuple:







    """simple docstring"""






    __magic_name__				     =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase__    )
  def 							_lowercase							( self			: Dict    )			->	List[Any]:







    """simple docstring"""






    __magic_name__				     =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__    )
  def 							_lowercase							( self			: Union[str, Any]    )			->	Any:







    """simple docstring"""






    __magic_name__				     =       self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__    )
  def 							_lowercase							( self			: Tuple    )			->	Optional[Any]:







    """simple docstring"""






    __magic_name__				     =       self.model_tester.prepare_config_and_inputs()
    for type in ["absolute", "relative_key", "relative_key_query"]:
      __magic_name__				     =       type
      self.model_tester.create_and_check_model(*UpperCamelCase__    )





  @slow
  def 							_lowercase							( self			: Optional[int]    )			->	Optional[int]:







    """simple docstring"""






    for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      __magic_name__				     =       AlbertModel.from_pretrained(UpperCamelCase__    )
      self.assertIsNotNone(UpperCamelCase__    )







@require_torch
class        UpperCAmelCase_			( unittest.TestCase     ):


  '''simple docstring'''







  @slow
  def 							_lowercase							( self			: Dict    )			->	Union[str, Any]:







    """simple docstring"""






    __magic_name__				     =       AlbertModel.from_pretrained("""albert-base-v2"""    )
    __magic_name__				     =       torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]    )
    __magic_name__				     =       torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]    )
    with torch.no_grad():
      __magic_name__				     =       model(UpperCamelCase__			,							attention_mask=UpperCamelCase__    )[0]
    __magic_name__				     =       torch.Size((1, 11, 768)    )
    self.assertEqual(output.shape			,							UpperCamelCase__    )
    __magic_name__				     =       torch.tensor(
        [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]    )

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

