'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import is_tf_available, is_torch_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, SMALL_MODEL_IDENTIFIER, is_pt_tf_cross_test, slow


if is_tf_available():
    from transformers import (
        AutoConfig,
        BertConfig,
        GPTaConfig,
        TaConfig,
        TFAutoModel,
        TFAutoModelForCausalLM,
        TFAutoModelForMaskedLM,
        TFAutoModelForPreTraining,
        TFAutoModelForQuestionAnswering,
        TFAutoModelForSeqaSeqLM,
        TFAutoModelForSequenceClassification,
        TFAutoModelWithLMHead,
        TFBertForMaskedLM,
        TFBertForPreTraining,
        TFBertForQuestionAnswering,
        TFBertForSequenceClassification,
        TFBertModel,
        TFGPTaLMHeadModel,
        TFRobertaForMaskedLM,
        TFTaForConditionalGeneration,
    )
    from transformers.models.bert.modeling_tf_bert import TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST
    from transformers.models.gpta.modeling_tf_gpta import TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST
    from transformers.models.ta.modeling_tf_ta import TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST

if is_torch_available():
    from transformers import (
        AutoModel,
        AutoModelForCausalLM,
        AutoModelForMaskedLM,
        AutoModelForPreTraining,
        AutoModelForQuestionAnswering,
        AutoModelForSeqaSeqLM,
        AutoModelForSequenceClassification,
        AutoModelWithLMHead,
        BertForMaskedLM,
        BertForPreTraining,
        BertForQuestionAnswering,
        BertForSequenceClassification,
        BertModel,
        GPTaLMHeadModel,
        RobertaForMaskedLM,
        TaForConditionalGeneration,
    )




@is_pt_tf_cross_test
class 	__A				(			unittest.TestCase     ):



    @slow
    def  _lowercase						(self   :   int			):
         # for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         for model_name in ["bert-base-uncased"]:
              UpperCAmelCase_	   =       AutoConfig.from_pretrained(__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       TFAutoModel.from_pretrained(__a       ,      from_pt=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       AutoModel.from_pretrained(__a       ,      from_tf=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)



    @slow
    def  _lowercase						(self   :   Any			):
         # for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         for model_name in ["bert-base-uncased"]:
              UpperCAmelCase_	   =       AutoConfig.from_pretrained(__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       TFAutoModelForPreTraining.from_pretrained(__a       ,      from_pt=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       AutoModelForPreTraining.from_pretrained(__a       ,      from_tf=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)



    @slow
    def  _lowercase						(self   :   Any			):
         for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase_	   =       AutoConfig.from_pretrained(__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       TFAutoModelForCausalLM.from_pretrained(__a       ,      from_pt=__a			)
              UpperCAmelCase_   ,			UpperCAmelCase_	   =       TFAutoModelForCausalLM.from_pretrained(
                  __a       ,      output_loading_info=__a       ,      from_pt=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       AutoModelForCausalLM.from_pretrained(__a       ,      from_tf=__a			)
              UpperCAmelCase_   ,			UpperCAmelCase_	   =       AutoModelForCausalLM.from_pretrained(
                  __a       ,      output_loading_info=__a       ,      from_tf=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)



    @slow
    def  _lowercase						(self   :   Tuple			):
         for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase_	   =       AutoConfig.from_pretrained(__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       TFAutoModelWithLMHead.from_pretrained(__a       ,      from_pt=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       AutoModelWithLMHead.from_pretrained(__a       ,      from_tf=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)



    @slow
    def  _lowercase						(self   :   Dict			):
         for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase_	   =       AutoConfig.from_pretrained(__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       TFAutoModelForMaskedLM.from_pretrained(__a       ,      from_pt=__a			)
              UpperCAmelCase_   ,			UpperCAmelCase_	   =       TFAutoModelForMaskedLM.from_pretrained(
                  __a       ,      output_loading_info=__a       ,      from_pt=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       AutoModelForMaskedLM.from_pretrained(__a       ,      from_tf=__a			)
              UpperCAmelCase_   ,			UpperCAmelCase_	   =       AutoModelForMaskedLM.from_pretrained(
                  __a       ,      output_loading_info=__a       ,      from_tf=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)



    @slow
    def  _lowercase						(self   :   str			):
         for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase_	   =       AutoConfig.from_pretrained(__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       TFAutoModelForSeqaSeqLM.from_pretrained(__a       ,      from_pt=__a			)
              UpperCAmelCase_   ,			UpperCAmelCase_	   =       TFAutoModelForSeqaSeqLM.from_pretrained(
                  __a       ,      output_loading_info=__a       ,      from_pt=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       AutoModelForSeqaSeqLM.from_pretrained(__a       ,      from_tf=__a			)
              UpperCAmelCase_   ,			UpperCAmelCase_	   =       AutoModelForSeqaSeqLM.from_pretrained(
                  __a       ,      output_loading_info=__a       ,      from_tf=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)



    @slow
    def  _lowercase						(self   :   Optional[Any]			):
         # for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         for model_name in ["bert-base-uncased"]:
              UpperCAmelCase_	   =       AutoConfig.from_pretrained(__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       TFAutoModelForSequenceClassification.from_pretrained(__a       ,      from_pt=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       AutoModelForSequenceClassification.from_pretrained(__a       ,      from_tf=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)



    @slow
    def  _lowercase						(self   :   Tuple			):
         # for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         for model_name in ["bert-base-uncased"]:
              UpperCAmelCase_	   =       AutoConfig.from_pretrained(__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       TFAutoModelForQuestionAnswering.from_pretrained(__a       ,      from_pt=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)

              UpperCAmelCase_	   =       AutoModelForQuestionAnswering.from_pretrained(__a       ,      from_tf=__a			)
              self.assertIsNotNone(__a			)
              self.assertIsInstance(__a       ,      __a			)



    def  _lowercase						(self   :   Optional[int]			):
         UpperCAmelCase_	   =       TFAutoModelWithLMHead.from_pretrained(__a       ,      from_pt=__a			)
         self.assertIsInstance(__a       ,      __a			)
         self.assertEqual(model.num_parameters()       ,      14410			)
         self.assertEqual(model.num_parameters(only_trainable=__a			)       ,      14410			)

         UpperCAmelCase_	   =       AutoModelWithLMHead.from_pretrained(__a       ,      from_tf=__a			)
         self.assertIsInstance(__a       ,      __a			)
         self.assertEqual(model.num_parameters()       ,      14410			)
         self.assertEqual(model.num_parameters(only_trainable=__a			)       ,      14410			)






    def  _lowercase						(self   :   Any			):
         UpperCAmelCase_	   =       TFAutoModelWithLMHead.from_pretrained(__a       ,      from_pt=__a			)
         self.assertIsInstance(__a       ,      __a			)
         self.assertEqual(model.num_parameters()       ,      14410			)
         self.assertEqual(model.num_parameters(only_trainable=__a			)       ,      14410			)

         UpperCAmelCase_	   =       AutoModelWithLMHead.from_pretrained(__a       ,      from_tf=__a			)
         self.assertIsInstance(__a       ,      __a			)
         self.assertEqual(model.num_parameters()       ,      14410			)
         self.assertEqual(model.num_parameters(only_trainable=__a			)       ,      14410			)





'''simple docstring'''





import unittest

from transformers import load_tool
from transformers.utils import is_torch_available


if is_torch_available():
    import torch

from transformers.testing_utils import require_torch

from .test_tools_common import ToolTesterMixin




@require_torch
class 	__A				(			unittest.TestCase		,     UpperCamelCase__     ):



    def  _lowercase						(self   :   Tuple			):
         UpperCAmelCase_	   =       load_tool("text-to-speech"			)
         self.tool.setup()



    def  _lowercase						(self   :   Union[str, Any]			):
         # SpeechT5 isn't deterministic
         torch.manual_seed(0			)
         UpperCAmelCase_	   =       self.tool("hey"			)
         UpperCAmelCase_	   =       result.to_raw()
         self.assertTrue(
             torch.allclose(
                 resulting_tensor[:3]       ,      torch.tensor([-0.0_00_59_66_66_88_32_11_58_29, -0.0_00_36_57_64_01_90_79_50_64, -0.00_01_34_39_50_27_99_88_34_85]			)       ,      )			)






    def  _lowercase						(self   :   List[str]			):
         # SpeechT5 isn't deterministic
         torch.manual_seed(0			)
         UpperCAmelCase_	   =       self.tool("hey"			)
         UpperCAmelCase_	   =       result.to_raw()
         self.assertTrue(
             torch.allclose(
                 resulting_tensor[:3]       ,      torch.tensor([-0.0_00_59_66_66_88_32_11_58_29, -0.0_00_36_57_64_01_90_79_50_64, -0.00_01_34_39_50_27_99_88_34_85]			)       ,      )			)




