




"""simple docstring"""



import json
import os
import re
import unittest

from transformers import CodeGenTokenizer, CodeGenTokenizerFast
from transformers.models.codegen.tokenization_codegen import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin




@require_tokenizers
class      UpperCAmelCase_  (						A_,       unittest.TestCase							):
    lowercase__						 =				CodeGenTokenizer
    lowercase__						 =				CodeGenTokenizerFast
    lowercase__						 =				True
    lowercase__						 =				{'''add_prefix_space''': True}
    lowercase__						 =				False




    def 							__magic_name__							(   self						:	Optional[Any]				)				->							Optional[int]:




     '''simple docstring'''

     super().setUp()

     # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
     A__	=    [
         "l",
         "o",
         "w",
         "e",
         "r",
         "s",
         "t",
         "i",
         "d",
         "n",
         "\u0120",
         "\u0120l",
         "\u0120n",
         "\u0120lo",
         "\u0120low",
         "er",
         "\u0120lowest",
         "\u0120newer",
         "\u0120wider",
         "<unk>",
         "<|endoftext|>",
     ]
     A__	=    dict(zip(snake_case_     ,			range(len(snake_case_				)				)				)				)
     A__	=    ["#version: 0.2", "\u0120 l", "\u0120l o", "\u0120lo w", "e r", ""]
     A__	=    {"unk_token": "<unk>"}

     A__	=    os.path.join(self.tmpdirname     ,			VOCAB_FILES_NAMES["vocab_file"]				)
     A__	=    os.path.join(self.tmpdirname     ,			VOCAB_FILES_NAMES["merges_file"]				)
     with open(self.vocab_file     ,			"w"     ,			encoding="utf-8"				) as fp:
      fp.write(json.dumps(snake_case_				) + "\n"				)
     with open(self.merges_file     ,			"w"     ,			encoding="utf-8"				) as fp:
      fp.write("\n".join(snake_case_				)				)




    def 							__magic_name__							(   self						:	Dict     ,			**snake_case_						:	Union[str, Any]				)				->							Union[str, Any]:




     '''simple docstring'''

     kwargs.update(self.special_tokens_map				)
     return CodeGenTokenizer.from_pretrained(self.tmpdirname     ,			**snake_case_				)




    def 							__magic_name__							(   self						:	List[str]     ,			**snake_case_						:	List[str]				)				->							Optional[int]:




     '''simple docstring'''

     kwargs.update(self.special_tokens_map				)
     return CodeGenTokenizerFast.from_pretrained(self.tmpdirname     ,			**snake_case_				)




    def 							__magic_name__							(   self						:	int     ,			snake_case_						:	Any				)				->							int:




     '''simple docstring'''

     A__	=    "lower newer"
     A__	=    "lower newer"
     return input_text, output_text




    def 							__magic_name__							(   self						:	Union[str, Any]				)				->							Tuple:




     '''simple docstring'''

     A__	=    CodeGenTokenizer(self.vocab_file     ,			self.merges_file     ,			**self.special_tokens_map				)
     A__	=    "lower newer"
     A__	=    ["\u0120low", "er", "\u0120", "n", "e", "w", "er"]
     A__	=    tokenizer.tokenize(snake_case_     ,			add_prefix_space=snake_case_				)
     self.assertListEqual(snake_case_     ,			snake_case_				)

     A__	=    tokens + [tokenizer.unk_token]
     A__	=    [14, 15, 10, 9, 3, 2, 15, 19]
     self.assertListEqual(tokenizer.convert_tokens_to_ids(snake_case_				)     ,			snake_case_				)




    def 							__magic_name__							(   self						:	Dict				)				->							Dict:




     '''simple docstring'''

     if not self.test_rust_tokenizer:
      return

     A__	=    self.get_tokenizer()
     A__	=    self.get_rust_tokenizer(add_prefix_space=snake_case_				)

     A__	=    "lower newer"

     # Testing tokenization
     A__	=    tokenizer.tokenize(snake_case_     ,			add_prefix_space=snake_case_				)
     A__	=    rust_tokenizer.tokenize(snake_case_				)
     self.assertListEqual(snake_case_     ,			snake_case_				)

     # Testing conversion to ids without special tokens
     A__	=    tokenizer.encode(snake_case_     ,			add_special_tokens=snake_case_     ,			add_prefix_space=snake_case_				)
     A__	=    rust_tokenizer.encode(snake_case_     ,			add_special_tokens=snake_case_				)
     self.assertListEqual(snake_case_     ,			snake_case_				)

     # Testing conversion to ids with special tokens
     A__	=    self.get_rust_tokenizer(add_prefix_space=snake_case_				)
     A__	=    tokenizer.encode(snake_case_     ,			add_prefix_space=snake_case_				)
     A__	=    rust_tokenizer.encode(snake_case_				)
     self.assertListEqual(snake_case_     ,			snake_case_				)

     # Testing the unknown token
     A__	=    tokens + [rust_tokenizer.unk_token]
     A__	=    [14, 15, 10, 9, 3, 2, 15, 19]
     self.assertListEqual(rust_tokenizer.convert_tokens_to_ids(snake_case_				)     ,			snake_case_				)




    def 							__magic_name__							(   self						:	List[Any]     ,			*snake_case_						:	Optional[int]     ,			**snake_case_						:	str				)				->							List[Any]:




     '''simple docstring'''

     pass




    def 							__magic_name__							(   self						:	List[str]     ,			snake_case_						:	Optional[int]=15				)				->							Any:




     '''simple docstring'''

     for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
      with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""				):
       A__	=    self.rust_tokenizer_class.from_pretrained(snake_case_     ,			**snake_case_				)

       # Simple input
       A__	=    "This is a simple input"
       A__	=    ["This is a simple input 1", "This is a simple input 2"]
       A__	=    ("This is a simple input", "This is a pair")
       A__	=    [
           ("This is a simple input 1", "This is a simple input 2"),
           ("This is a simple pair 1", "This is a simple pair 2"),
       ]

       # Simple input tests
       self.assertRaises(snake_case_     ,			tokenizer_r.encode     ,			snake_case_     ,			max_length=snake_case_     ,			padding="max_length"				)

       # Simple input
       self.assertRaises(snake_case_     ,			tokenizer_r.encode_plus     ,			snake_case_     ,			max_length=snake_case_     ,			padding="max_length"				)

       # Simple input
       self.assertRaises(
           snake_case_     ,			tokenizer_r.batch_encode_plus     ,			snake_case_     ,			max_length=snake_case_     ,			padding="max_length"     ,			)

       # Pair input
       self.assertRaises(snake_case_     ,			tokenizer_r.encode     ,			snake_case_     ,			max_length=snake_case_     ,			padding="max_length"				)

       # Pair input
       self.assertRaises(snake_case_     ,			tokenizer_r.encode_plus     ,			snake_case_     ,			max_length=snake_case_     ,			padding="max_length"				)

       # Pair input
       self.assertRaises(
           snake_case_     ,			tokenizer_r.batch_encode_plus     ,			snake_case_     ,			max_length=snake_case_     ,			padding="max_length"     ,			)




    def 							__magic_name__							(   self						:	List[str]				)				->							List[str]:




     '''simple docstring'''

     A__	=    CodeGenTokenizer.from_pretrained(self.tmpdirname     ,			pad_token="<pad>"				)

     # Simple input
     A__	=    "This is a simple input"
     A__	=    ["This is a simple input looooooooong", "This is a simple input"]
     A__	=    ("This is a simple input", "This is a pair")
     A__	=    [
         ("This is a simple input loooooong", "This is a simple input"),
         ("This is a simple pair loooooong", "This is a simple pair"),
     ]

     A__	=    tokenizer.pad_token_id

     A__	=    tokenizer(snake_case_     ,			padding="max_length"     ,			max_length=30     ,			return_tensors="np"				)
     A__	=    tokenizer(snake_case_     ,			padding=snake_case_     ,			truncate=snake_case_     ,			return_tensors="np"				)
     A__	=    tokenizer(*snake_case_     ,			padding="max_length"     ,			max_length=60     ,			return_tensors="np"				)
     A__	=    tokenizer(snake_case_     ,			padding=snake_case_     ,			truncate=snake_case_     ,			return_tensors="np"				)

     # s
     # test single string max_length padding
     self.assertEqual(out_s["input_ids"].shape[-1]     ,			30				)
     self.assertTrue(pad_token_id in out_s["input_ids"]				)
     self.assertTrue(0 in out_s["attention_mask"]				)

     # s2
     # test automatic padding
     self.assertEqual(out_sa["input_ids"].shape[-1]     ,			33				)
     # long slice doesn't have padding
     self.assertFalse(pad_token_id in out_sa["input_ids"][0]				)
     self.assertFalse(0 in out_sa["attention_mask"][0]				)
     # short slice does have padding
     self.assertTrue(pad_token_id in out_sa["input_ids"][1]				)
     self.assertTrue(0 in out_sa["attention_mask"][1]				)

     # p
     # test single pair max_length padding
     self.assertEqual(out_p["input_ids"].shape[-1]     ,			60				)
     self.assertTrue(pad_token_id in out_p["input_ids"]				)
     self.assertTrue(0 in out_p["attention_mask"]				)

     # p2
     # test automatic padding pair
     self.assertEqual(out_pa["input_ids"].shape[-1]     ,			52				)
     # long slice pair doesn't have padding
     self.assertFalse(pad_token_id in out_pa["input_ids"][0]				)
     self.assertFalse(0 in out_pa["attention_mask"][0]				)
     # short slice pair does have padding
     self.assertTrue(pad_token_id in out_pa["input_ids"][1]				)
     self.assertTrue(0 in out_pa["attention_mask"][1]				)




    def 							__magic_name__							(   self						:	str				)				->							Tuple:




     '''simple docstring'''

     A__	=    "$$$"
     A__	=    CodeGenTokenizer.from_pretrained(self.tmpdirname     ,			bos_token=snake_case_     ,			add_bos_token=snake_case_				)

     A__	=    "This is a simple input"
     A__	=    ["This is a simple input 1", "This is a simple input 2"]

     A__	=    tokenizer.bos_token_id

     A__	=    tokenizer(snake_case_				)
     A__	=    tokenizer(snake_case_				)

     self.assertEqual(out_s.input_ids[0]     ,			snake_case_				)
     self.assertTrue(all(o[0] == bos_token_id for o in out_sa.input_ids				)				)

     A__	=    tokenizer.decode(out_s.input_ids				)
     A__	=    tokenizer.batch_decode(out_sa.input_ids				)

     self.assertEqual(decode_s.split()[0]     ,			snake_case_				)
     self.assertTrue(all(d.split()[0] == bos_token for d in decode_sa				)				)




    @slow
    def 							__magic_name__							(   self						:	int				)				->							Dict:




     '''simple docstring'''

     A__	=    CodeGenTokenizer.from_pretrained("Salesforce/codegen-350M-mono"				)

     A__	=    "\nif len_a > len_b:\n    result = a\nelse:\n    result = b\n\n\n\n#"
     A__	=    "\nif len_a > len_b:      result = a\nelse:      result = b"

     A__	=    tokenizer.encode(snake_case_				)
     A__	=    ["^#", re.escape("<|endoftext|>"				), "^'''", "^\"\"\"", "\n\n\n"]
     A__	=    tokenizer.decode(snake_case_     ,			truncate_before_pattern=snake_case_				)
     self.assertEqual(snake_case_     ,			snake_case_				)




    def 							__magic_name__							(   self						:	Dict				)				->							Tuple:




     '''simple docstring'''

     pass











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




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




     '''simple docstring'''

     A__	=    parent
     A__	=    batch_size
     A__	=    seq_length
     A__	=    is_training
     A__	=    use_input_mask
     A__	=    use_token_type_ids
     A__	=    use_labels
     A__	=    vocab_size
     A__	=    embedding_size
     A__	=    hidden_size
     A__	=    num_hidden_layers
     A__	=    num_hidden_groups
     A__	=    num_attention_heads
     A__	=    intermediate_size
     A__	=    hidden_act
     A__	=    hidden_dropout_prob
     A__	=    attention_probs_dropout_prob
     A__	=    max_position_embeddings
     A__	=    type_vocab_size
     A__	=    type_sequence_label_size
     A__	=    initializer_range
     A__	=    num_labels
     A__	=    num_choices
     A__	=    scope




    def 							__magic_name__							(   self						:	Tuple				)				->							List[str]:




     '''simple docstring'''

     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
     if self.use_token_type_ids:
      A__	=    ids_tensor([self.batch_size, self.seq_length]     ,			self.type_vocab_size				)

     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__	=    self.get_config()

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




    def 							__magic_name__							(   self						:	int				)				->							Dict:




     '''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 							__magic_name__							(   self						:	Optional[int]     ,			snake_case_						:	Optional[Any]     ,			snake_case_						:	List[str]     ,			snake_case_						:	List[str]     ,			snake_case_						:	Any     ,			snake_case_						:	List[Any]     ,			snake_case_						:	Optional[Any]     ,			snake_case_						:	Union[str, Any]				)				->							Union[str, Any]:




     '''simple docstring'''

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




     '''simple docstring'''

     A__	=    AlbertForPreTraining(config=snake_case_				)
     model.to(snake_case_				)
     model.eval()
     A__	=    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 							__magic_name__							(   self						:	str     ,			snake_case_						:	Union[str, Any]     ,			snake_case_						:	List[Any]     ,			snake_case_						:	Dict     ,			snake_case_						:	Optional[int]     ,			snake_case_						:	Optional[int]     ,			snake_case_						:	Optional[Any]     ,			snake_case_						:	List[str]				)				->							Dict:




     '''simple docstring'''

     A__	=    AlbertForMaskedLM(config=snake_case_				)
     model.to(snake_case_				)
     model.eval()
     A__	=    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 							__magic_name__							(   self						:	int     ,			snake_case_						:	Optional[Any]     ,			snake_case_						:	Optional[int]     ,			snake_case_						:	Optional[int]     ,			snake_case_						:	Any     ,			snake_case_						:	Tuple     ,			snake_case_						:	List[str]     ,			snake_case_						:	List[str]				)				->							Tuple:




     '''simple docstring'''

     A__	=    AlbertForQuestionAnswering(config=snake_case_				)
     model.to(snake_case_				)
     model.eval()
     A__	=    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 							__magic_name__							(   self						:	Any     ,			snake_case_						:	Optional[Any]     ,			snake_case_						:	Tuple     ,			snake_case_						:	List[Any]     ,			snake_case_						:	Union[str, Any]     ,			snake_case_						:	Optional[int]     ,			snake_case_						:	str     ,			snake_case_						:	Any				)				->							Any:




     '''simple docstring'''

     A__	=    self.num_labels
     A__	=    AlbertForSequenceClassification(snake_case_				)
     model.to(snake_case_				)
     model.eval()
     A__	=    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 							__magic_name__							(   self						:	Tuple     ,			snake_case_						:	Dict     ,			snake_case_						:	int     ,			snake_case_						:	Union[str, Any]     ,			snake_case_						:	int     ,			snake_case_						:	str     ,			snake_case_						:	Optional[Any]     ,			snake_case_						:	Optional[Any]				)				->							List[str]:




     '''simple docstring'''

     A__	=    self.num_labels
     A__	=    AlbertForTokenClassification(config=snake_case_				)
     model.to(snake_case_				)
     model.eval()
     A__	=    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 							__magic_name__							(   self						:	Any     ,			snake_case_						:	Tuple     ,			snake_case_						:	Any     ,			snake_case_						:	Any     ,			snake_case_						:	Tuple     ,			snake_case_						:	Any     ,			snake_case_						:	Tuple     ,			snake_case_						:	Any				)				->							Optional[Any]:




     '''simple docstring'''

     A__	=    self.num_choices
     A__	=    AlbertForMultipleChoice(config=snake_case_				)
     model.to(snake_case_				)
     model.eval()
     A__	=    input_ids.unsqueeze(1				).expand(-1     ,			self.num_choices     ,			-1				).contiguous()
     A__	=    token_type_ids.unsqueeze(1				).expand(-1     ,			self.num_choices     ,			-1				).contiguous()
     A__	=    input_mask.unsqueeze(1				).expand(-1     ,			self.num_choices     ,			-1				).contiguous()
     A__	=    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 							__magic_name__							(   self						:	Any				)				->							List[str]:




     '''simple docstring'''

     A__	=    self.prepare_config_and_inputs()
     (
         (
         A__
     ),				(
         A__
     ),				(
         A__
     ),				(
         A__
     ),				(
         A__
     ),				(
         A__
     ),				(
         A__
     ),				
     )	=    config_and_inputs
     A__	=    {"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							):
    lowercase__						 =				(
        (
            AlbertModel,
            AlbertForPreTraining,
            AlbertForMaskedLM,
            AlbertForMultipleChoice,
            AlbertForSequenceClassification,
            AlbertForTokenClassification,
            AlbertForQuestionAnswering,
        )
        if is_torch_available()
        else ()
    )
    lowercase__						 =				(
        {
            '''feature-extraction''': AlbertModel,
            '''fill-mask''': AlbertForMaskedLM,
            '''question-answering''': AlbertForQuestionAnswering,
            '''text-classification''': AlbertForSequenceClassification,
            '''token-classification''': AlbertForTokenClassification,
            '''zero-shot''': AlbertForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    lowercase__						 =				True




    def 							__magic_name__							(   self						:	Tuple     ,			snake_case_						:	Dict     ,			snake_case_						:	Optional[Any]     ,			snake_case_						:	List[Any]=False				)				->							Optional[int]:




     '''simple docstring'''

     A__	=    super()._prepare_for_class(snake_case_     ,			snake_case_     ,			return_labels=snake_case_				)

     if return_labels:
      if model_class in get_values(snake_case_				):
       A__	=    torch.zeros(
           (self.model_tester.batch_size, self.model_tester.seq_length)     ,			dtype=torch.long     ,			device=snake_case_				)
       A__	=    torch.zeros(
           self.model_tester.batch_size     ,			dtype=torch.long     ,			device=snake_case_				)
     return inputs_dict




    def 							__magic_name__							(   self						:	Dict				)				->							List[Any]:




     '''simple docstring'''

     A__	=    AlbertModelTester(self				)
     A__	=    ConfigTester(self     ,			config_class=snake_case_     ,			hidden_size=37				)




    def 							__magic_name__							(   self						:	Union[str, Any]				)				->							Optional[int]:




     '''simple docstring'''

     self.config_tester.run_common_tests()




    def 							__magic_name__							(   self						:	Any				)				->							List[str]:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*snake_case_				)




    def 							__magic_name__							(   self						:	Optional[int]				)				->							Union[str, Any]:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_pretraining(*snake_case_				)




    def 							__magic_name__							(   self						:	int				)				->							str:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*snake_case_				)




    def 							__magic_name__							(   self						:	Any				)				->							str:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_multiple_choice(*snake_case_				)




    def 							__magic_name__							(   self						:	Optional[Any]				)				->							Any:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*snake_case_				)




    def 							__magic_name__							(   self						:	Optional[int]				)				->							Optional[Any]:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*snake_case_				)




    def 							__magic_name__							(   self						:	List[str]				)				->							Optional[Any]:




     '''simple docstring'''

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




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




     '''simple docstring'''

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






@require_torch
class      UpperCAmelCase_  (						unittest.TestCase							):




    @slow
    def 							__magic_name__							(   self						:	int				)				->							Tuple:




     '''simple docstring'''

     A__	=    AlbertModel.from_pretrained("albert-base-v2"				)
     A__	=    torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]				)
     A__	=    torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
     with torch.no_grad():
      A__	=    model(snake_case_     ,			attention_mask=snake_case_				)[0]
     A__	=    torch.Size((1, 11, 768)				)
     self.assertEqual(output.shape     ,			snake_case_				)
     A__	=    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]     ,			snake_case_     ,			atol=1e-4				)				)





