





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



      '''simple docstring'''

      @slow
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        for model_name in ["bert-base-uncased"]:
          A_  :       List[Any]										=  AutoConfig.from_pretrained(snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       int										=  TFAutoModel.from_pretrained(snake_case_					,      from_pt=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Union[str, Any]										=  AutoModel.from_pretrained(snake_case_					,      from_tf=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

      @slow
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        for model_name in ["bert-base-uncased"]:
          A_  :       List[str]										=  AutoConfig.from_pretrained(snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Union[str, Any]										=  TFAutoModelForPreTraining.from_pretrained(snake_case_					,      from_pt=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Optional[Any]										=  AutoModelForPreTraining.from_pretrained(snake_case_					,      from_tf=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

      @slow
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          A_  :       Tuple										=  AutoConfig.from_pretrained(snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       List[str]										=  TFAutoModelForCausalLM.from_pretrained(snake_case_					,      from_pt=snake_case_  )
          A_						,       A_  :       List[str]										=  TFAutoModelForCausalLM.from_pretrained(
              snake_case_					,      output_loading_info=snake_case_					,      from_pt=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Optional[Any]										=  AutoModelForCausalLM.from_pretrained(snake_case_					,      from_tf=snake_case_  )
          A_						,       A_  :       int										=  AutoModelForCausalLM.from_pretrained(
              snake_case_					,      output_loading_info=snake_case_					,      from_tf=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

      @slow
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          A_  :       List[Any]										=  AutoConfig.from_pretrained(snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Tuple										=  TFAutoModelWithLMHead.from_pretrained(snake_case_					,      from_pt=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Optional[int]										=  AutoModelWithLMHead.from_pretrained(snake_case_					,      from_tf=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

      @slow
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          A_  :       Optional[int]										=  AutoConfig.from_pretrained(snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       str										=  TFAutoModelForMaskedLM.from_pretrained(snake_case_					,      from_pt=snake_case_  )
          A_						,       A_  :       Dict										=  TFAutoModelForMaskedLM.from_pretrained(
              snake_case_					,      output_loading_info=snake_case_					,      from_pt=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       List[Any]										=  AutoModelForMaskedLM.from_pretrained(snake_case_					,      from_tf=snake_case_  )
          A_						,       A_  :       str										=  AutoModelForMaskedLM.from_pretrained(
              snake_case_					,      output_loading_info=snake_case_					,      from_tf=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

      @slow
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          A_  :       List[str]										=  AutoConfig.from_pretrained(snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Optional[Any]										=  TFAutoModelForSeqaSeqLM.from_pretrained(snake_case_					,      from_pt=snake_case_  )
          A_						,       A_  :       Union[str, Any]										=  TFAutoModelForSeqaSeqLM.from_pretrained(
              snake_case_					,      output_loading_info=snake_case_					,      from_pt=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Any										=  AutoModelForSeqaSeqLM.from_pretrained(snake_case_					,      from_tf=snake_case_  )
          A_						,       A_  :       Union[str, Any]										=  AutoModelForSeqaSeqLM.from_pretrained(
              snake_case_					,      output_loading_info=snake_case_					,      from_tf=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

      @slow
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

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

          A_  :       Optional[int]										=  TFAutoModelForSequenceClassification.from_pretrained(snake_case_					,      from_pt=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       List[Any]										=  AutoModelForSequenceClassification.from_pretrained(snake_case_					,      from_tf=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

      @slow
      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        for model_name in ["bert-base-uncased"]:
          A_  :       List[str]										=  AutoConfig.from_pretrained(snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Optional[Any]										=  TFAutoModelForQuestionAnswering.from_pretrained(snake_case_					,      from_pt=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

          A_  :       Tuple										=  AutoModelForQuestionAnswering.from_pretrained(snake_case_					,      from_tf=snake_case_  )
          self.assertIsNotNone(snake_case_  )
          self.assertIsInstance(snake_case_					,      snake_case_  )

      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        A_  :       List[str]										=  TFAutoModelWithLMHead.from_pretrained(snake_case_					,      from_pt=snake_case_  )
        self.assertIsInstance(snake_case_					,      snake_case_  )
        self.assertEqual(model.num_parameters()					,      1_4_4_1_0  )
        self.assertEqual(model.num_parameters(only_trainable=snake_case_  )					,      1_4_4_1_0  )

        A_  :       int										=  AutoModelWithLMHead.from_pretrained(snake_case_					,      from_tf=snake_case_  )
        self.assertIsInstance(snake_case_					,      snake_case_  )
        self.assertEqual(model.num_parameters()					,      1_4_4_1_0  )
        self.assertEqual(model.num_parameters(only_trainable=snake_case_  )					,      1_4_4_1_0  )

      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        A_  :       Any										=  TFAutoModelWithLMHead.from_pretrained(snake_case_					,      from_pt=snake_case_  )
        self.assertIsInstance(snake_case_					,      snake_case_  )
        self.assertEqual(model.num_parameters()					,      1_4_4_1_0  )
        self.assertEqual(model.num_parameters(only_trainable=snake_case_  )					,      1_4_4_1_0  )

        A_  :       int										=  AutoModelWithLMHead.from_pretrained(snake_case_					,      from_tf=snake_case_  )
        self.assertIsInstance(snake_case_					,      snake_case_  )
        self.assertEqual(model.num_parameters()					,      1_4_4_1_0  )
        self.assertEqual(model.num_parameters(only_trainable=snake_case_  )					,      1_4_4_1_0  )






"""simple docstring"""




import torch

from diffusers import DiffusionPipeline

class  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def __init__(     self					,      snake_case_					,      snake_case_  ):

        """simple docstring"""

        super().__init__()

        self.register_modules(unet=snake_case_					,      scheduler=snake_case_  )

      def __call__(     self  ):

        """simple docstring"""

        A_  :       Optional[Any]										=  torch.randn(
            (1, self.unet.config.in_channels, self.unet.config.sample_size, self.unet.config.sample_size)					,      )
        A_  :       List[str]										=  1

        A_  :       List[str]										=  self.unet(snake_case_					,      snake_case_  ).sample
        A_  :       Optional[int]										=  self.scheduler.step(snake_case_					,      snake_case_					,      snake_case_  ).prev_sample

        A_  :       List[Any]										=  scheduler_output - scheduler_output + torch.ones_like(snake_case_  )

        return result