





import os
import sys
import unittest


lowercase				:	List[Any]      						=  os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, """utils"""))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
lowercase				:	str      						=  os.path.join(git_repo_path, """src""", """diffusers""")





class 			A__   (							unittest.TestCase     ):




			"""simple docstring"""



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







										'''simple docstring'''

										a__						:     List[str]			=    find_backend('    if not is_torch_available():')
										self.assertEqual(lowercase__ ,  'torch')

										# backend_with_underscore = find_backend("    if not is_tensorflow_text_available():")
										# self.assertEqual(backend_with_underscore, "tensorflow_text")

										a__						:     Union[str, Any]			=    find_backend('    if not (is_torch_available() and is_transformers_available()):')
										self.assertEqual(lowercase__ ,  'torch_and_transformers')

										# double_backend_with_underscore = find_backend(
										#    "    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"
										# )
										# self.assertEqual(double_backend_with_underscore, "sentencepiece_and_tensorflow_text")

										a__						:     Dict			=    find_backend(
										    '    if not (is_torch_available() and is_transformers_available() and is_onnx_available()):')
										self.assertEqual(lowercase__ ,  'torch_and_transformers_and_onnx')

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







										'''simple docstring'''

										a__						:     List[str]			=    read_init()
										# We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
										self.assertIn('torch' ,  lowercase__)
										self.assertIn('torch_and_transformers' ,  lowercase__)
										self.assertIn('flax_and_transformers' ,  lowercase__)
										self.assertIn('torch_and_transformers_and_onnx' ,  lowercase__)

										# Likewise, we can't assert on the exact content of a key
										self.assertIn('UNet2DModel' ,  objects['torch'])
										self.assertIn('FlaxUNet2DConditionModel' ,  objects['flax'])
										self.assertIn('StableDiffusionPipeline' ,  objects['torch_and_transformers'])
										self.assertIn('FlaxStableDiffusionPipeline' ,  objects['flax_and_transformers'])
										self.assertIn('LMSDiscreteScheduler' ,  objects['torch_and_scipy'])
										self.assertIn('OnnxStableDiffusionPipeline' ,  objects['torch_and_transformers_and_onnx'])

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







										'''simple docstring'''

										a__						:     str			=    create_dummy_object('CONSTANT' ,  '\'torch\'')
										self.assertEqual(lowercase__ ,  '\nCONSTANT = None\n')

										a__						:     int			=    create_dummy_object('function' ,  '\'torch\'')
										self.assertEqual(
										    lowercase__ ,  '\ndef function(*args, **kwargs):\n    requires_backends(function, \'torch\')\n')

										a__						:     Optional[Any]			=    '\nclass FakeClass(metaclass=DummyObject):\n    _backends = \'torch\'\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, \'torch\')\n\n    @classmethod\n    def from_config(cls, *args, **kwargs):\n        requires_backends(cls, \'torch\')\n\n    @classmethod\n    def from_pretrained(cls, *args, **kwargs):\n        requires_backends(cls, \'torch\')\n'
										a__						:     Optional[Any]			=    create_dummy_object('FakeClass' ,  '\'torch\'')
										self.assertEqual(lowercase__ ,  lowercase__)

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







										'''simple docstring'''

										a__						:     List[Any]			=    '# This file is autogenerated by the command `make fix-copies`, do not edit.\nfrom ..utils import DummyObject, requires_backends\n\n\nCONSTANT = None\n\n\ndef function(*args, **kwargs):\n    requires_backends(function, ["torch"])\n\n\nclass FakeClass(metaclass=DummyObject):\n    _backends = ["torch"]\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, ["torch"])\n\n    @classmethod\n    def from_config(cls, *args, **kwargs):\n        requires_backends(cls, ["torch"])\n\n    @classmethod\n    def from_pretrained(cls, *args, **kwargs):\n        requires_backends(cls, ["torch"])\n'
										a__						:     Optional[int]			=    create_dummy_files({'torch': ['CONSTANT', 'function', 'FakeClass']})
										self.assertEqual(dummy_files['torch'] ,  lowercase__)









import unittest

import numpy as np

from transformers import BertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
    from transformers.models.bert.modeling_flax_bert import (
        FlaxBertForMaskedLM,
        FlaxBertForMultipleChoice,
        FlaxBertForNextSentencePrediction,
        FlaxBertForPreTraining,
        FlaxBertForQuestionAnswering,
        FlaxBertForSequenceClassification,
        FlaxBertForTokenClassification,
        FlaxBertModel,
    )





class 			A__   (							unittest.TestCase     ):




   """simple docstring"""



   def __init__( self ,  lowercase ,  lowercase=13 ,  lowercase=7 ,  lowercase=True ,  lowercase=True ,  lowercase=True ,  lowercase=True ,  lowercase=99 ,  lowercase=32 ,  lowercase=5 ,  lowercase=4 ,  lowercase=37 ,  lowercase="gelu" ,  lowercase=0.1 ,  lowercase=0.1 ,  lowercase=512 ,  lowercase=16 ,  lowercase=2 ,  lowercase=0.02 ,  lowercase=4 ,  )      ->						Tuple:







          '''simple docstring'''

          a__						:     str			=    parent
          a__						:     Optional[Any]			=    batch_size
          a__						:     str			=    seq_length
          a__						:     int			=    is_training
          a__						:     str			=    use_attention_mask
          a__						:     List[str]			=    use_token_type_ids
          a__						:     Optional[Any]			=    use_labels
          a__						:     List[Any]			=    vocab_size
          a__						:     Tuple			=    hidden_size
          a__						:     Dict			=    num_hidden_layers
          a__						:     List[str]			=    num_attention_heads
          a__						:     int			=    intermediate_size
          a__						:     Any			=    hidden_act
          a__						:     Optional[int]			=    hidden_dropout_prob
          a__						:     Tuple			=    attention_probs_dropout_prob
          a__						:     Tuple			=    max_position_embeddings
          a__						:     Optional[int]			=    type_vocab_size
          a__						:     List[Any]			=    type_sequence_label_size
          a__						:     Union[str, Any]			=    initializer_range
          a__						:     str			=    num_choices

   def 							__lowercase		( self)      ->						Optional[Any]:







          '''simple docstring'''

          a__						:     str			=    ids_tensor([self.batch_size, self.seq_length] ,  self.vocab_size)

          a__						:     Dict			=    None
          if self.use_attention_mask:
                 a__						:     Optional[int]			=    random_attention_mask([self.batch_size, self.seq_length])

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

          a__						:     Dict			=    BertConfig(
              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 ,  is_decoder=lowercase ,  initializer_range=self.initializer_range ,  )

          return config, input_ids, token_type_ids, attention_mask

   def 							__lowercase		( self)      ->						Optional[Any]:







          '''simple docstring'''

          a__						:     Tuple			=    self.prepare_config_and_inputs()
          a__			,							a__			,							a__			,							a__						:     Optional[int]			=    config_and_inputs
          a__						:     str			=    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
          return config, inputs_dict

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







          '''simple docstring'''

          a__						:     Union[str, Any]			=    self.prepare_config_and_inputs()
          a__			,							a__			,							a__			,							a__						:     int			=    config_and_inputs

          a__						:     str			=    True
          a__						:     Any			=    floats_tensor([self.batch_size, self.seq_length, self.hidden_size])
          a__						:     List[str]			=    ids_tensor([self.batch_size, self.seq_length] ,  vocab_size=2)

          return (
              config,
              input_ids,
              attention_mask,
              encoder_hidden_states,
              encoder_attention_mask,
          )





@require_flax
class 			A__   (							__UpperCAmelCase			,  unittest.TestCase     ):




   """simple docstring"""



   __A       :    Optional[Any]	  =  True

   __A       :    Tuple	  =  (
       (
           FlaxBertModel,
           FlaxBertForPreTraining,
           FlaxBertForMaskedLM,
           FlaxBertForMultipleChoice,
           FlaxBertForQuestionAnswering,
           FlaxBertForNextSentencePrediction,
           FlaxBertForSequenceClassification,
           FlaxBertForTokenClassification,
           FlaxBertForQuestionAnswering,
       )
       if is_flax_available()
       else ()
   )

   def 							__lowercase		( self)      ->						Tuple:







          '''simple docstring'''

          a__						:     Optional[Any]			=    FlaxBertModelTester(self)

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







          '''simple docstring'''

          a__						:     Union[str, Any]			=    FlaxBertModel.from_pretrained('bert-base-cased')
          a__						:     Optional[Any]			=    model(np.ones((1, 1)))
          self.assertIsNotNone(lowercase)


