





"""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     SCREAMING_SNAKE_CASE       (unittest.TestCase				):


   @slow
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any	)->       Any:





     """simple docstring"""







     for model_name in ["bert-base-uncased"]:
       lowercase__           =  AutoConfig.from_pretrained(a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  TFAutoModel.from_pretrained(a      ,					from_pt=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  AutoModel.from_pretrained(a      ,					from_tf=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)


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





     """simple docstring"""







     for model_name in ["bert-base-uncased"]:
       lowercase__           =  AutoConfig.from_pretrained(a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  TFAutoModelForPreTraining.from_pretrained(a      ,					from_pt=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  AutoModelForPreTraining.from_pretrained(a      ,					from_tf=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)


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





     """simple docstring"""







     for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       lowercase__           =  AutoConfig.from_pretrained(a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  TFAutoModelForCausalLM.from_pretrained(a      ,					from_pt=a	)
       lowercase__      ,   lowercase__           =  TFAutoModelForCausalLM.from_pretrained(
           a      ,					output_loading_info=a      ,					from_pt=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  AutoModelForCausalLM.from_pretrained(a      ,					from_tf=a	)
       lowercase__      ,   lowercase__           =  AutoModelForCausalLM.from_pretrained(
           a      ,					output_loading_info=a      ,					from_tf=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)


   @slow
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       Optional[Any]:





     """simple docstring"""







     for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       lowercase__           =  AutoConfig.from_pretrained(a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  TFAutoModelWithLMHead.from_pretrained(a      ,					from_pt=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  AutoModelWithLMHead.from_pretrained(a      ,					from_tf=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)


   @slow
   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]	)->       str:





     """simple docstring"""







     for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       lowercase__           =  AutoConfig.from_pretrained(a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  TFAutoModelForMaskedLM.from_pretrained(a      ,					from_pt=a	)
       lowercase__      ,   lowercase__           =  TFAutoModelForMaskedLM.from_pretrained(
           a      ,					output_loading_info=a      ,					from_pt=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  AutoModelForMaskedLM.from_pretrained(a      ,					from_tf=a	)
       lowercase__      ,   lowercase__           =  AutoModelForMaskedLM.from_pretrained(
           a      ,					output_loading_info=a      ,					from_tf=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)


   @slow
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]	)->       Union[str, Any]:





     """simple docstring"""







     for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       lowercase__           =  AutoConfig.from_pretrained(a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  TFAutoModelForSeqaSeqLM.from_pretrained(a      ,					from_pt=a	)
       lowercase__      ,   lowercase__           =  TFAutoModelForSeqaSeqLM.from_pretrained(
           a      ,					output_loading_info=a      ,					from_pt=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  AutoModelForSeqaSeqLM.from_pretrained(a      ,					from_tf=a	)
       lowercase__      ,   lowercase__           =  AutoModelForSeqaSeqLM.from_pretrained(
           a      ,					output_loading_info=a      ,					from_tf=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)


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





     """simple docstring"""







     for model_name in ["bert-base-uncased"]:
       lowercase__           =  AutoConfig.from_pretrained(a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  TFAutoModelForSequenceClassification.from_pretrained(a      ,					from_pt=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  AutoModelForSequenceClassification.from_pretrained(a      ,					from_tf=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)


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





     """simple docstring"""







     for model_name in ["bert-base-uncased"]:
       lowercase__           =  AutoConfig.from_pretrained(a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  TFAutoModelForQuestionAnswering.from_pretrained(a      ,					from_pt=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)

       lowercase__           =  AutoModelForQuestionAnswering.from_pretrained(a      ,					from_tf=a	)
       self.assertIsNotNone(a	)
       self.assertIsInstance(a      ,					a	)


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





     """simple docstring"""







     lowercase__           =  TFAutoModelWithLMHead.from_pretrained(a      ,					from_pt=a	)
     self.assertIsInstance(a      ,					a	)
     self.assertEqual(model.num_parameters()      ,					14_410	)
     self.assertEqual(model.num_parameters(only_trainable=a	)      ,					14_410	)

     lowercase__           =  AutoModelWithLMHead.from_pretrained(a      ,					from_tf=a	)
     self.assertIsInstance(a      ,					a	)
     self.assertEqual(model.num_parameters()      ,					14_410	)
     self.assertEqual(model.num_parameters(only_trainable=a	)      ,					14_410	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple	)->       int:





     """simple docstring"""







     lowercase__           =  TFAutoModelWithLMHead.from_pretrained(a      ,					from_pt=a	)
     self.assertIsInstance(a      ,					a	)
     self.assertEqual(model.num_parameters()      ,					14_410	)
     self.assertEqual(model.num_parameters(only_trainable=a	)      ,					14_410	)

     lowercase__           =  AutoModelWithLMHead.from_pretrained(a      ,					from_tf=a	)
     self.assertIsInstance(a      ,					a	)
     self.assertEqual(model.num_parameters()      ,					14_410	)
     self.assertEqual(model.num_parameters(only_trainable=a	)      ,					14_410	)









from typing import Callable, Optional

from .. import Features
from ..packaged_modules.generator.generator import Generator
from .abc import AbstractDatasetInputStream
class     SCREAMING_SNAKE_CASE       (UpperCAmelCase				):


   def __init__(   self      :    List[str]      ,					a      :    Callable      ,					a      :    Optional[Features] = None      ,					a      :    str = None      ,					a      :    bool = False      ,					a      :    bool = False      ,					a      :    Optional[dict] = None      ,					a      :    Optional[int] = None      ,					**a      :    str      ,					)->       Tuple:





     """simple docstring"""







     super().__init__(
         features=a      ,					cache_dir=a      ,					keep_in_memory=a      ,					streaming=a      ,					num_proc=a      ,					**a      ,					)
     lowercase__           =  Generator(
         cache_dir=a      ,					features=a      ,					generator=a      ,					gen_kwargs=a      ,					**a      ,					)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any	)->       Dict:





     """simple docstring"""







     if self.streaming:
       lowercase__           =  self.builder.as_streaming_dataset(split='train'	)
     # Build regular (map-style) dataset
     else:
       lowercase__           =  None
       lowercase__           =  None
       lowercase__           =  None
       lowercase__           =  None

       self.builder.download_and_prepare(
           download_config=a      ,					download_mode=a      ,					verification_mode=a      ,					base_path=a      ,					num_proc=self.num_proc      ,					)
       lowercase__           =  self.builder.as_dataset(
           split='train'      ,					verification_mode=a      ,					in_memory=self.keep_in_memory	)
     return dataset


