

'''simple docstring'''

from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
    import tensorflow as tf

    from transformers import TF_MODEL_FOR_PRETRAINING_MAPPING
    from transformers.models.albert.modeling_tf_albert import (
        TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFAlbertForMaskedLM,
        TFAlbertForMultipleChoice,
        TFAlbertForPreTraining,
        TFAlbertForQuestionAnswering,
        TFAlbertForSequenceClassification,
        TFAlbertForTokenClassification,
        TFAlbertModel,
    )





class 							_snake_case	:
   def __init__(	self     : List[str]       ,SCREAMING_SNAKE_CASE__     : Optional[Any]       ,SCREAMING_SNAKE_CASE__     : List[str]=13       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]=7       ,SCREAMING_SNAKE_CASE__     : Optional[Any]=True       ,SCREAMING_SNAKE_CASE__     : Dict=True       ,SCREAMING_SNAKE_CASE__     : List[Any]=True       ,SCREAMING_SNAKE_CASE__     : Any=True       ,SCREAMING_SNAKE_CASE__     : List[str]=99       ,SCREAMING_SNAKE_CASE__     : Any=16       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]=32       ,SCREAMING_SNAKE_CASE__     : Tuple=2       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]=4       ,SCREAMING_SNAKE_CASE__     : Optional[int]=37       ,SCREAMING_SNAKE_CASE__     : List[str]="gelu"       ,SCREAMING_SNAKE_CASE__     : str=0.1       ,SCREAMING_SNAKE_CASE__     : Dict=0.1       ,SCREAMING_SNAKE_CASE__     : Dict=512       ,SCREAMING_SNAKE_CASE__     : str=16       ,SCREAMING_SNAKE_CASE__     : Optional[int]=2       ,SCREAMING_SNAKE_CASE__     : List[Any]=0.02       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]=3       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]=4       ,SCREAMING_SNAKE_CASE__     : Dict=None       ,):
     SCREAMING_SNAKE_CASE:Tuple   =   parent
     SCREAMING_SNAKE_CASE:Dict   =   13
     SCREAMING_SNAKE_CASE:List[Any]   =   7
     SCREAMING_SNAKE_CASE:str   =   True
     SCREAMING_SNAKE_CASE:Dict   =   True
     SCREAMING_SNAKE_CASE:Optional[Any]   =   True
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   True
     SCREAMING_SNAKE_CASE:Any   =   99
     SCREAMING_SNAKE_CASE:Any   =   16
     SCREAMING_SNAKE_CASE:str   =   32
     SCREAMING_SNAKE_CASE:Any   =   2
     SCREAMING_SNAKE_CASE:Optional[int]   =   4
     SCREAMING_SNAKE_CASE:Optional[int]   =   37
     SCREAMING_SNAKE_CASE:Optional[Any]   =   "gelu"
     SCREAMING_SNAKE_CASE:int   =   0.1
     SCREAMING_SNAKE_CASE:List[str]   =   0.1
     SCREAMING_SNAKE_CASE:Optional[int]   =   512
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   16
     SCREAMING_SNAKE_CASE:Optional[int]   =   2
     SCREAMING_SNAKE_CASE:Tuple   =   0.02
     SCREAMING_SNAKE_CASE:str   =   3
     SCREAMING_SNAKE_CASE:Any   =   4
     SCREAMING_SNAKE_CASE:int   =   None
   def       __UpperCamelCase  (	self     : List[str]							):
     SCREAMING_SNAKE_CASE:Tuple   =   ids_tensor([self.batch_size, self.seq_length]       ,self.vocab_size							)

     SCREAMING_SNAKE_CASE:Tuple   =   None
     if self.use_input_mask:
       SCREAMING_SNAKE_CASE:List[str]   =   random_attention_mask([self.batch_size, self.seq_length]							)

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

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

     SCREAMING_SNAKE_CASE:Optional[Any]   =   AlbertConfig(
         vocab_size=self.vocab_size       ,hidden_size=self.hidden_size       ,embedding_size=self.embedding_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       ,)

     return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
   def       __UpperCamelCase  (	self     : Any       ,SCREAMING_SNAKE_CASE__     : int       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]       ,SCREAMING_SNAKE_CASE__     : Optional[Any]       ,SCREAMING_SNAKE_CASE__     : List[Any]       ,SCREAMING_SNAKE_CASE__     : List[Any]       ,SCREAMING_SNAKE_CASE__     : List[str]       ,SCREAMING_SNAKE_CASE__     : str							):
     SCREAMING_SNAKE_CASE:Dict   =   TFAlbertModel(config=SCREAMING_SNAKE_CASE__							)
     # inputs = {'input_ids': input_ids,
     #           'attention_mask': input_mask,
     #           'token_type_ids': token_type_ids}
     # sequence_output, pooled_output = model(**inputs)
     SCREAMING_SNAKE_CASE:int   =   {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     SCREAMING_SNAKE_CASE:str   =   model(SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Any   =   [input_ids, input_mask]
     SCREAMING_SNAKE_CASE:Tuple   =   model(SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:str   =   model(SCREAMING_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       __UpperCamelCase  (	self     : Tuple       ,SCREAMING_SNAKE_CASE__     : List[Any]       ,SCREAMING_SNAKE_CASE__     : int       ,SCREAMING_SNAKE_CASE__     : List[str]       ,SCREAMING_SNAKE_CASE__     : Tuple       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]       ,SCREAMING_SNAKE_CASE__     : Optional[int]       ,SCREAMING_SNAKE_CASE__     : List[Any]							):
     SCREAMING_SNAKE_CASE:Any   =   self.num_labels
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   TFAlbertForPreTraining(config=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Dict   =   {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     SCREAMING_SNAKE_CASE:Tuple   =   model(SCREAMING_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, self.num_labels)							)
   def       __UpperCamelCase  (	self     : Any       ,SCREAMING_SNAKE_CASE__     : List[Any]       ,SCREAMING_SNAKE_CASE__     : str       ,SCREAMING_SNAKE_CASE__     : List[str]       ,SCREAMING_SNAKE_CASE__     : Any       ,SCREAMING_SNAKE_CASE__     : Optional[int]       ,SCREAMING_SNAKE_CASE__     : str       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]							):
     SCREAMING_SNAKE_CASE:Dict   =   TFAlbertForMaskedLM(config=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:List[str]   =   {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   model(SCREAMING_SNAKE_CASE__							)
     self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.seq_length, self.vocab_size)							)
   def       __UpperCamelCase  (	self     : Union[str, Any]       ,SCREAMING_SNAKE_CASE__     : Tuple       ,SCREAMING_SNAKE_CASE__     : Any       ,SCREAMING_SNAKE_CASE__     : Optional[Any]       ,SCREAMING_SNAKE_CASE__     : List[Any]       ,SCREAMING_SNAKE_CASE__     : str       ,SCREAMING_SNAKE_CASE__     : str       ,SCREAMING_SNAKE_CASE__     : Optional[int]							):
     SCREAMING_SNAKE_CASE:Optional[int]   =   self.num_labels
     SCREAMING_SNAKE_CASE:Optional[int]   =   TFAlbertForSequenceClassification(config=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     SCREAMING_SNAKE_CASE:int   =   model(SCREAMING_SNAKE_CASE__							)
     self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.num_labels)							)
   def       __UpperCamelCase  (	self     : Union[str, Any]       ,SCREAMING_SNAKE_CASE__     : List[Any]       ,SCREAMING_SNAKE_CASE__     : Dict       ,SCREAMING_SNAKE_CASE__     : Dict       ,SCREAMING_SNAKE_CASE__     : List[Any]       ,SCREAMING_SNAKE_CASE__     : Optional[int]       ,SCREAMING_SNAKE_CASE__     : List[Any]       ,SCREAMING_SNAKE_CASE__     : Optional[Any]							):
     SCREAMING_SNAKE_CASE:Optional[int]   =   TFAlbertForQuestionAnswering(config=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
     SCREAMING_SNAKE_CASE:List[Any]   =   model(SCREAMING_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       __UpperCamelCase  (	self     : Optional[Any]       ,SCREAMING_SNAKE_CASE__     : Any       ,SCREAMING_SNAKE_CASE__     : Optional[int]       ,SCREAMING_SNAKE_CASE__     : Any       ,SCREAMING_SNAKE_CASE__     : Optional[Any]       ,SCREAMING_SNAKE_CASE__     : Any       ,SCREAMING_SNAKE_CASE__     : int       ,SCREAMING_SNAKE_CASE__     : Any							):
     SCREAMING_SNAKE_CASE:Any   =   self.num_choices
     SCREAMING_SNAKE_CASE:Dict   =   TFAlbertForMultipleChoice(config=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Optional[int]   =   tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__       ,1							)       ,(1, self.num_choices, 1)							)
     SCREAMING_SNAKE_CASE:int   =   tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__       ,1							)       ,(1, self.num_choices, 1)							)
     SCREAMING_SNAKE_CASE:Union[str, Any]   =   tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__       ,1							)       ,(1, self.num_choices, 1)							)
     SCREAMING_SNAKE_CASE:int   =   {
         "input_ids": multiple_choice_inputs_ids,
         "attention_mask": multiple_choice_input_mask,
         "token_type_ids": multiple_choice_token_type_ids,
     }
     SCREAMING_SNAKE_CASE:Optional[Any]   =   model(SCREAMING_SNAKE_CASE__							)
     self.parent.assertListEqual(list(result["logits"].shape							)       ,[self.batch_size, self.num_choices]							)
   def       __UpperCamelCase  (	self     : Union[str, Any]       ,SCREAMING_SNAKE_CASE__     : Tuple       ,SCREAMING_SNAKE_CASE__     : Dict       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]       ,SCREAMING_SNAKE_CASE__     : Tuple       ,SCREAMING_SNAKE_CASE__     : Union[str, Any]       ,SCREAMING_SNAKE_CASE__     : Optional[Any]       ,SCREAMING_SNAKE_CASE__     : str							):
     SCREAMING_SNAKE_CASE:List[str]   =   self.num_labels
     SCREAMING_SNAKE_CASE:str   =   TFAlbertForTokenClassification(config=SCREAMING_SNAKE_CASE__							)
     SCREAMING_SNAKE_CASE:Tuple   =   {
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }
     SCREAMING_SNAKE_CASE:int   =   model(SCREAMING_SNAKE_CASE__							)
     self.parent.assertListEqual(list(result["logits"].shape							)       ,[self.batch_size, self.seq_length, self.num_labels]							)







   def       __UpperCamelCase  (	self     : Dict							):
     SCREAMING_SNAKE_CASE:List[str]   =   self.prepare_config_and_inputs()
     (
         SCREAMING_SNAKE_CASE      
     ):Optional[int]   =   config_and_inputs
     SCREAMING_SNAKE_CASE:Any   =   {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
     return config, inputs_dict





@require_tf
class 							_snake_case	(    _a		,					_a		,					unittest.TestCase  ):
   _A    :       Tuple      				=   (
       (
           TFAlbertModel,
           TFAlbertForPreTraining,
           TFAlbertForMaskedLM,
           TFAlbertForSequenceClassification,
           TFAlbertForQuestionAnswering,
           TFAlbertForTokenClassification,
           TFAlbertForMultipleChoice,
       )
       if is_tf_available()
       else ()
   )
   _A    :       Optional[Any]      				=   (
       {
           '''feature-extraction''': TFAlbertModel,
           '''fill-mask''': TFAlbertForMaskedLM,
           '''question-answering''': TFAlbertForQuestionAnswering,
           '''text-classification''': TFAlbertForSequenceClassification,
           '''token-classification''': TFAlbertForTokenClassification,
           '''zero-shot''': TFAlbertForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   _A    :       List[Any]      				=   False
   _A    :       str      				=   False
   def       __UpperCamelCase  (	self     : int       ,SCREAMING_SNAKE_CASE__     : List[Any]       ,SCREAMING_SNAKE_CASE__     : List[str]       ,SCREAMING_SNAKE_CASE__     : List[Any]=False							):
     SCREAMING_SNAKE_CASE:Any   =   super()._prepare_for_class(SCREAMING_SNAKE_CASE__       ,SCREAMING_SNAKE_CASE__       ,return_labels=SCREAMING_SNAKE_CASE__							)

     if return_labels:
       if model_class in get_values(SCREAMING_SNAKE_CASE__							):
         SCREAMING_SNAKE_CASE:str   =   tf.zeros(self.model_tester.batch_size       ,dtype=tf.intaa							)

     return inputs_dict
   def       __UpperCamelCase  (	self     : int							):
     SCREAMING_SNAKE_CASE:int   =   TFAlbertModelTester(self							)
     SCREAMING_SNAKE_CASE:Dict   =   ConfigTester(self       ,config_class=SCREAMING_SNAKE_CASE__       ,hidden_size=37							)
   def       __UpperCamelCase  (	self     : Dict							):
     self.config_tester.run_common_tests()
   def       __UpperCamelCase  (	self     : int							):
     SCREAMING_SNAKE_CASE:int   =   self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_model(*SCREAMING_SNAKE_CASE__							)
   def       __UpperCamelCase  (	self     : Union[str, Any]							):
     SCREAMING_SNAKE_CASE:int   =   self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_pretraining(*SCREAMING_SNAKE_CASE__							)
   def       __UpperCamelCase  (	self     : int							):
     SCREAMING_SNAKE_CASE:List[Any]   =   self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_masked_lm(*SCREAMING_SNAKE_CASE__							)
   def       __UpperCamelCase  (	self     : List[Any]							):
     SCREAMING_SNAKE_CASE:Any   =   self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_multiple_choice(*SCREAMING_SNAKE_CASE__							)
   def       __UpperCamelCase  (	self     : Tuple							):
     SCREAMING_SNAKE_CASE:str   =   self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_sequence_classification(*SCREAMING_SNAKE_CASE__							)
   def       __UpperCamelCase  (	self     : Any							):
     SCREAMING_SNAKE_CASE:Optional[int]   =   self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_albert_for_question_answering(*SCREAMING_SNAKE_CASE__							)







   @slow
   def       __UpperCamelCase  (	self     : List[Any]							):
     for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       SCREAMING_SNAKE_CASE:Tuple   =   TFAlbertModel.from_pretrained(SCREAMING_SNAKE_CASE__							)
       self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)





@require_tf
class 							_snake_case	(    unittest.TestCase  ):
   @slow
   def       __UpperCamelCase  (	self     : Union[str, Any]							):
     SCREAMING_SNAKE_CASE:List[str]   =   TFAlbertForPreTraining.from_pretrained("albert-base-v2"							)
     SCREAMING_SNAKE_CASE:int   =   tf.constant([[0, 1, 2, 3, 4, 5]]							)
     SCREAMING_SNAKE_CASE:List[str]   =   model(SCREAMING_SNAKE_CASE__							)[0]

     SCREAMING_SNAKE_CASE:Any   =   [1, 6, 30_000]
     self.assertEqual(output.shape       ,SCREAMING_SNAKE_CASE__							)

     SCREAMING_SNAKE_CASE:Optional[int]   =   tf.constant(
         [
             [
                 [4.595_668, 0.74_462_754, -1.818_147],
                 [4.5_954_347, 0.7_454_184, -1.8_188_258],
                 [4.5_954_905, 0.7_448_235, -1.8_182_316],
             ]
         ]							)
     tf.debugging.assert_near(output[:, :3, :3]       ,SCREAMING_SNAKE_CASE__       ,atol=1e-4							)









'''simple docstring'''

import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import Mock, patch

import diffusers.utils.hub_utils





class 							_snake_case	(    unittest.TestCase  ):
   @patch("diffusers.utils.hub_utils.get_full_repo_name"							)
   def       __UpperCamelCase  (	self     : List[str]       ,SCREAMING_SNAKE_CASE__     : Mock							):
     SCREAMING_SNAKE_CASE:Optional[Any]   =   "full_repo_name"
     with TemporaryDirectory() as tmpdir:
       # Dummy args values
       SCREAMING_SNAKE_CASE:int   =   Mock()
       SCREAMING_SNAKE_CASE:int   =   tmpdir
       SCREAMING_SNAKE_CASE:Optional[Any]   =   0
       SCREAMING_SNAKE_CASE:Union[str, Any]   =   "hub_token"
       SCREAMING_SNAKE_CASE:str   =   "dataset_name"
       SCREAMING_SNAKE_CASE:Tuple   =   0.01
       SCREAMING_SNAKE_CASE:str   =   100_000
       SCREAMING_SNAKE_CASE:Optional[Any]   =   10_000
       SCREAMING_SNAKE_CASE:List[Any]   =   0.01
       SCREAMING_SNAKE_CASE:Union[str, Any]   =   0.02
       SCREAMING_SNAKE_CASE:Optional[Any]   =   0.03
       SCREAMING_SNAKE_CASE:Tuple   =   0.0_005
       SCREAMING_SNAKE_CASE:List[str]   =   0.000_001
       SCREAMING_SNAKE_CASE:Optional[int]   =   1
       SCREAMING_SNAKE_CASE:Optional[int]   =   10
       SCREAMING_SNAKE_CASE:Any   =   0.001
       SCREAMING_SNAKE_CASE:Optional[int]   =   0.1
       SCREAMING_SNAKE_CASE:Union[str, Any]   =   0.2
       SCREAMING_SNAKE_CASE:Optional[Any]   =   True

       # Model card mush be rendered and saved
       diffusers.utils.hub_utils.create_model_card(SCREAMING_SNAKE_CASE__       ,model_name="model_name"							)
       self.assertTrue((Path(SCREAMING_SNAKE_CASE__							) / "README.md").is_file()							)






