






'''simple docstring'''


import importlib.metadata
import warnings
from copy import deepcopy

from packaging import version

from ..utils import logging
from .import_utils import is_accelerate_available, is_bitsandbytes_available


if is_bitsandbytes_available():
     import bitsandbytes as bnb
     import torch
     import torch.nn as nn

     from ..pytorch_utils import ConvaD

if is_accelerate_available():
     from accelerate import init_empty_weights
     from accelerate.utils import find_tied_parameters

lowerCamelCase_				: int    	=							logging.get_logger(__name__)







def 	__magic_name__( _A						,      _A						,      _A						,      _A=None						,      _A=None					):
      '''simple docstring'''





      if "." in tensor_name:
            UpperCamelCase__         = tensor_name.split("""."""					)
            for split in splits[:-1]:
                  UpperCamelCase__         = getattr(_lowercase						,      _lowercase					)
                  if new_module is None:
                        raise ValueError(f"{module} has no attribute {split}."					)
                  UpperCamelCase__         = new_module
            UpperCamelCase__         = splits[-1]

      if tensor_name not in module._parameters and tensor_name not in module._buffers:
            raise ValueError(f"{module} does not have a parameter or a buffer named {tensor_name}."					)
      UpperCamelCase__         = tensor_name in module._buffers
      UpperCamelCase__         = getattr(_lowercase						,      _lowercase					)

      if old_value.device == torch.device("""meta"""					) and device not in ["meta", torch.device("""meta"""					)] and value is None:
            raise ValueError(f"{tensor_name} is on the meta device, we need a `value` to put in on {device}."					)

      UpperCamelCase__         = False
      UpperCamelCase__         = False
      if is_buffer or not is_bitsandbytes_available():
            UpperCamelCase__         = False
            UpperCamelCase__         = False
      else:
            UpperCamelCase__         = hasattr(bnb.nn						,      """Params4bit"""					) and isinstance(module._parameters[tensor_name]						,      bnb.nn.Paramsabit					)
            UpperCamelCase__         = isinstance(module._parameters[tensor_name]						,      bnb.nn.IntaParams					)

      if is_abit or is_abit:
            UpperCamelCase__         = module._parameters[tensor_name]
            if param.device.type != "cuda":
                  if value is None:
                        UpperCamelCase__         = old_value.to(_lowercase					)
                  elif isinstance(_lowercase						,      torch.Tensor					):
                        UpperCamelCase__         = value.to("""cpu"""					)
                        if value.dtype == torch.inta:
                              UpperCamelCase__         = version.parse(importlib.metadata.version("""bitsandbytes"""					)					) > version.parse(
                                  """0.37.2"""					)
                              if not is_abit_serializable:
                                    raise ValueError(
                                        """Detected int8 weights but the version of bitsandbytes is not compatible with int8 serialization. """
                                        """Make sure to download the latest `bitsandbytes` version. `pip install --upgrade bitsandbytes`."""					)
                  else:
                        UpperCamelCase__         = torch.tensor(_lowercase						,      device="""cpu"""					)

                  # Support models using `Conv1D` in place of `nn.Linear` (e.g. gpt2) by transposing the weight matrix prior to quantization.
                  # Since weights are saved in the correct "orientation", we skip transposing when loading.
                  if issubclass(module.source_cls						,      _lowercase					) and fpaa_statistics is None:
                        UpperCamelCase__         = new_value.T

                  UpperCamelCase__         = old_value.__dict__
                  if is_abit:
                        UpperCamelCase__         = bnb.nn.IntaParams(_lowercase						,      requires_grad=_lowercase						,      **_lowercase					).to(_lowercase					)
                  elif is_abit:
                        UpperCamelCase__         = bnb.nn.Paramsabit(_lowercase						,      requires_grad=_lowercase						,      **_lowercase					).to(_lowercase					)

                  UpperCamelCase__         = new_value
                  if fpaa_statistics is not None:
                        setattr(module.weight						,      """SCB"""						,      fpaa_statistics.to(_lowercase					)					)

      else:
            if value is None:
                  UpperCamelCase__         = old_value.to(_lowercase					)
            elif isinstance(_lowercase						,      torch.Tensor					):
                  UpperCamelCase__         = value.to(_lowercase					)
            else:
                  UpperCamelCase__         = torch.tensor(_lowercase						,      device=_lowercase					)

            if is_buffer:
                  UpperCamelCase__         = new_value
            else:
                  UpperCamelCase__         = nn.Parameter(_lowercase						,      requires_grad=old_value.requires_grad					)
                  UpperCamelCase__         = new_value







def 	__magic_name__( _A						,      _A=None						,      _A=None						,      _A=None						,      _A=False					):
      '''simple docstring'''





      for name, module in model.named_children():
            if current_key_name is None:
                  UpperCamelCase__         = []
            current_key_name.append(_lowercase					)

            if (isinstance(_lowercase						,      nn.Linear					) or isinstance(_lowercase						,      _lowercase					)) and name not in modules_to_not_convert:
                  # Check if the current key is not in the `modules_to_not_convert`
                  if not any(key in """.""".join(_lowercase					) for key in modules_to_not_convert					):
                        with init_empty_weights():
                              if isinstance(_lowercase						,      _lowercase					):
                                    UpperCamelCase__         = module.weight.shape
                              else:
                                    UpperCamelCase__         = module.in_features
                                    UpperCamelCase__         = module.out_features

                              if quantization_config.quantization_method() == "llm_int8":
                                    UpperCamelCase__         = bnb.nn.LinearabitLt(
                                        _lowercase						,      _lowercase						,      module.bias is not None						,      has_fpaa_weights=quantization_config.llm_inta_has_fpaa_weight						,      threshold=quantization_config.llm_inta_threshold						,      )
                                    UpperCamelCase__         = True
                              else:
                                    if (
                                        quantization_config.llm_inta_skip_modules is not None
                                        and name in quantization_config.llm_inta_skip_modules
                                    ):
                                          pass
                                    else:
                                          UpperCamelCase__         = bnb.nn.Linearabit(
                                              _lowercase						,      _lowercase						,      module.bias is not None						,      quantization_config.bnb_abit_compute_dtype						,      compress_statistics=quantization_config.bnb_abit_use_double_quant						,      quant_type=quantization_config.bnb_abit_quant_type						,      )
                                          UpperCamelCase__         = True
                    # Store the module class in case we need to transpose the weight later
                              UpperCamelCase__         = type(_lowercase					)
                              # Force requires grad to False to avoid unexpected errors
                              model._modules[name].requires_grad_(_lowercase					)
            if len(list(module.children()					)					) > 0:
                  UpperCamelCase__         = _replace_with_bnb_linear(
                      _lowercase						,      _lowercase						,      _lowercase						,      _lowercase						,      has_been_replaced=_lowercase						,      )
            # Remove the last key for recursion
            current_key_name.pop(-1					)
      return model, has_been_replaced







def 	__magic_name__( _A						,      _A=None						,      _A=None						,      _A=None					):
      '''simple docstring'''





      UpperCamelCase__         = ['''lm_head'''] if modules_to_not_convert is None else modules_to_not_convert
      UpperCamelCase__         = _replace_with_bnb_linear(
          _lowercase						,      _lowercase						,      _lowercase						,      _lowercase					)

      if not has_been_replaced:
            logger.warning(
                """You are loading your model in 8bit or 4bit but no linear modules were found in your model."""
                """ Please double check your model architecture, or submit an issue on github if you think this is"""
                """ a bug."""					)

      return model







def 	__magic_name__( *_A						,      **_A					):
      '''simple docstring'''





      warnings.warn(
          """`replace_8bit_linear` will be deprecated in a future version, please use `replace_with_bnb_linear` instead"""						,      _lowercase						,      )
      return replace_with_bnb_linear(*_lowercase						,      **_lowercase					)







def 	__magic_name__( *_A						,      **_A					):
      '''simple docstring'''





      warnings.warn(
          """`set_module_8bit_tensor_to_device` will be deprecated in a future version, please use `set_module_quantized_tensor_to_device` instead"""						,      _lowercase						,      )
      return set_module_quantized_tensor_to_device(*_lowercase						,      **_lowercase					)







def 	__magic_name__( _A					):
      '''simple docstring'''





      UpperCamelCase__         = deepcopy(_lowercase					)  # this has 0 cost since it is done inside `init_empty_weights` context manager`
      tied_model.tie_weights()

      UpperCamelCase__         = find_tied_parameters(_lowercase					)
      # For compatibility with Accelerate < 0.18
      if isinstance(_lowercase						,      _lowercase					):
            UpperCamelCase__         = sum(list(tied_params.values()					)						,      []					) + list(tied_params.keys()					)
      else:
            UpperCamelCase__         = sum(_lowercase						,      []					)
      UpperCamelCase__         = len(_lowercase					) > 0

      # Check if it is a base model
      UpperCamelCase__         = not hasattr(_lowercase						,      model.base_model_prefix					)

      # Ignore this for base models (BertModel, GPT2Model, etc.)
      if (not has_tied_params) and is_base_model:
            return []

      # otherwise they have an attached head
      UpperCamelCase__         = list(model.named_children()					)
      UpperCamelCase__         = [list_modules[-1][0]]

      # add last module together with tied weights
      UpperCamelCase__         = set(_lowercase					) - set(_lowercase					)
      UpperCamelCase__         = list(set(_lowercase					)					) + list(_lowercase					)

      # remove ".weight" from the keys
      UpperCamelCase__         = ['''.weight''', '''.bias''']
      UpperCamelCase__         = []
      for name in list_untouched:
            for name_to_remove in names_to_remove:
                  if name_to_remove in name:
                        UpperCamelCase__         = name.replace(_lowercase						,      """"""					)
            filtered_module_names.append(_lowercase					)

      return filtered_module_names








'''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    _SCREAMING_SNAKE_CASE							:


			'''simple docstring'''





			def __init__(   self							:						Optional[int] ,      lowercase							:						List[str] ,      lowercase							:						List[Any]=1_3 ,      lowercase							:						Union[str, Any]=7 ,      lowercase							:						Dict=True ,      lowercase							:						Optional[int]=True ,      lowercase							:						List[Any]=True ,      lowercase							:						Dict=True ,      lowercase							:						List[str]=9_9 ,      lowercase							:						Dict=1_6 ,      lowercase							:						Dict=3_6 ,      lowercase							:						str=6 ,      lowercase							:						List[Any]=6 ,      lowercase							:						int=6 ,      lowercase							:						Union[str, Any]=3_7 ,      lowercase							:						Union[str, Any]="gelu" ,      lowercase							:						List[Any]=0.1 ,      lowercase							:						List[str]=0.1 ,      lowercase							:						str=5_1_2 ,      lowercase							:						Any=1_6 ,      lowercase							:						str=2 ,      lowercase							:						List[Any]=0.0_2 ,      lowercase							:						Tuple=3 ,      lowercase							:						Dict=4 ,      lowercase							:						Dict=None ,      )							->    List[Any]:

									'''simple docstring'''







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






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

									'''simple docstring'''







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

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

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

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

									UpperCamelCase__         = self.get_config()

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






			def 				A      (   self							:						Optional[int]			)							->    str:

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

									'''simple docstring'''







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

									'''simple docstring'''







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

									'''simple docstring'''







									UpperCamelCase__         = AlbertForMaskedLM(config=lowercase			)
									model.to(lowercase			)
									model.eval()
									UpperCamelCase__         = model(lowercase ,      attention_mask=lowercase ,      token_type_ids=lowercase ,      labels=lowercase			)
									self.parent.assertEqual(result.logits.shape ,      (self.batch_size, self.seq_length, self.vocab_size)			)






			def 				A      (   self							:						Optional[Any] ,      lowercase							:						Any ,      lowercase							:						Union[str, Any] ,      lowercase							:						List[Any] ,      lowercase							:						List[Any] ,      lowercase							:						List[str] ,      lowercase							:						Optional[Any] ,      lowercase							:						Optional[Any]			)							->    List[Any]:

									'''simple docstring'''







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

									'''simple docstring'''







									UpperCamelCase__         = self.num_labels
									UpperCamelCase__         = AlbertForSequenceClassification(lowercase			)
									model.to(lowercase			)
									model.eval()
									UpperCamelCase__         = model(lowercase ,      attention_mask=lowercase ,      token_type_ids=lowercase ,      labels=lowercase			)
									self.parent.assertEqual(result.logits.shape ,      (self.batch_size, self.num_labels)			)






			def 				A      (   self							:						List[str] ,      lowercase							:						int ,      lowercase							:						Any ,      lowercase							:						Tuple ,      lowercase							:						List[str] ,      lowercase							:						Optional[int] ,      lowercase							:						List[Any] ,      lowercase							:						Dict			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = self.num_labels
									UpperCamelCase__         = AlbertForTokenClassification(config=lowercase			)
									model.to(lowercase			)
									model.eval()
									UpperCamelCase__         = model(lowercase ,      attention_mask=lowercase ,      token_type_ids=lowercase ,      labels=lowercase			)
									self.parent.assertEqual(result.logits.shape ,      (self.batch_size, self.seq_length, self.num_labels)			)






			def 				A      (   self							:						List[Any] ,      lowercase							:						Union[str, Any] ,      lowercase							:						List[Any] ,      lowercase							:						Any ,      lowercase							:						List[str] ,      lowercase							:						Optional[Any] ,      lowercase							:						List[str] ,      lowercase							:						List[Any]			)							->    str:

									'''simple docstring'''







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







			def 				A      (   self							:						Optional[int]			)							->    List[str]:

									'''simple docstring'''







									UpperCamelCase__         = self.prepare_config_and_inputs()
									(
									    (
									    UpperCamelCase__
									)    ,   (
									    UpperCamelCase__
									)    ,   (
									    UpperCamelCase__
									)    ,   (
									    UpperCamelCase__
									)    ,   (
									    UpperCamelCase__
									)    ,   (
									    UpperCamelCase__
									)    ,   (
									    UpperCamelCase__
									)    ,   
									)         = config_and_inputs
									UpperCamelCase__         = {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
									return config, inputs_dict
@require_torch
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE       ,SCREAMING_SNAKE_CASE       ,unittest.TestCase	):


			'''simple docstring'''





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






			def 				A      (   self							:						Any ,      lowercase							:						int ,      lowercase							:						Dict ,      lowercase							:						Optional[Any]=False			)							->    Tuple:

									'''simple docstring'''







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

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






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

									'''simple docstring'''







									UpperCamelCase__         = AlbertModelTester(self			)
									UpperCamelCase__         = ConfigTester(self ,      config_class=lowercase ,      hidden_size=3_7			)






			def 				A      (   self							:						int			)							->    List[str]:

									'''simple docstring'''







									self.config_tester.run_common_tests()






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

									'''simple docstring'''







									UpperCamelCase__         = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*lowercase			)






			def 				A      (   self							:						int			)							->    Dict:

									'''simple docstring'''







									UpperCamelCase__         = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*lowercase			)






			def 				A      (   self							:						Tuple			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*lowercase			)






			def 				A      (   self							:						Any			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*lowercase			)






			def 				A      (   self							:						List[str]			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*lowercase			)






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

									'''simple docstring'''







									UpperCamelCase__         = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*lowercase			)






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

									'''simple docstring'''







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







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

									'''simple docstring'''







									for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															UpperCamelCase__         = AlbertModel.from_pretrained(lowercase			)
															self.assertIsNotNone(lowercase			)
@require_torch
class    _SCREAMING_SNAKE_CASE							(		unittest.TestCase	):


			'''simple docstring'''





			@slow
			def 				A      (   self							:						List[Any]			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = AlbertModel.from_pretrained("""albert-base-v2"""			)
									UpperCamelCase__         = torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]			)
									UpperCamelCase__         = torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
									with torch.no_grad():
															UpperCamelCase__         = model(lowercase ,      attention_mask=lowercase			)[0]
									UpperCamelCase__         = torch.Size((1, 1_1, 7_6_8)			)
									self.assertEqual(output.shape ,      lowercase			)
									UpperCamelCase__         = torch.tensor(
									    [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]]			)

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