

"""simple docstring"""


import os
import sys
import unittest


a					:str    = 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
a					:int    = os.path.join(git_repo_path, "src", "diffusers")

class      __a							(unittest.TestCase):






     '''simple docstring'''

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


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	find_backend("""    if not is_torch_available():"""  )
           self.assertEqual(_a	,    """torch"""  )

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

           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	find_backend("""    if not (is_torch_available() and is_transformers_available()):"""  )
           self.assertEqual(_a	,    """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")

           SCREAMING_SNAKE_CASE__   :      Dict      		=	find_backend(
               """    if not (is_torch_available() and is_transformers_available() and is_onnx_available()):"""  )
           self.assertEqual(_a	,    """torch_and_transformers_and_onnx"""  )

     def 					_a			(						self  )  ->      int:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Any      		=	read_init()
           # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
           self.assertIn("""torch"""	,    _a  )
           self.assertIn("""torch_and_transformers"""	,    _a  )
           self.assertIn("""flax_and_transformers"""	,    _a  )
           self.assertIn("""torch_and_transformers_and_onnx"""	,    _a  )

           # 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 					_a			(						self  )  ->      Tuple:


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	create_dummy_object("""CONSTANT"""	,    """'torch'"""  )
           self.assertEqual(_a	,    """\nCONSTANT = None\n"""  )

           SCREAMING_SNAKE_CASE__   :      str      		=	create_dummy_object("""function"""	,    """'torch'"""  )
           self.assertEqual(
               _a	,    """\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"""  )

           SCREAMING_SNAKE_CASE__   :      Any      		=	"""
class FakeClass(metaclass=DummyObject):
    _backends = 'torch'

    def __init__(self, *args, **kwargs):
        requires_backends(self, 'torch')

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, 'torch')

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, 'torch')
"""
           SCREAMING_SNAKE_CASE__   :      Dict      		=	create_dummy_object("""FakeClass"""	,    """'torch'"""  )
           self.assertEqual(_a	,    _a  )





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


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	"""# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, [\"torch\"])


class FakeClass(metaclass=DummyObject):
    _backends = [\"torch\"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, [\"torch\"])

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, [\"torch\"])

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, [\"torch\"])
"""
           SCREAMING_SNAKE_CASE__   :      Any      		=	create_dummy_files({"""torch""": ["""CONSTANT""", """function""", """FakeClass"""]}  )
           self.assertEqual(dummy_files["""torch"""]	,    _a  )







"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow


if is_tf_available():
  import numpy as np
  import tensorflow as tf

  from transformers import TFCamembertModel

@require_tf
@require_sentencepiece
@require_tokenizers
class      __a							(unittest.TestCase):






     '''simple docstring'''

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


           """simple docstring"""


           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	TFCamembertModel.from_pretrained("""jplu/tf-camembert-base"""  )

           SCREAMING_SNAKE_CASE__   :      Any      		=	tf.convert_to_tensor(
               [[5, 121, 11, 660, 16, 730, 25_543, 110, 83, 6]]	,    dtype=tf.intaa	,    )  # J'aime le camembert !"

           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	model(_a  )["""last_hidden_state"""]
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	tf.TensorShape((1, 10, 768)  )
           self.assertEqual(output.shape	,    _a  )
           # compare the actual values for a slice.
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	tf.convert_to_tensor(
               [[[-0.0_254, 0.0_235, 0.1_027], [0.0_606, -0.1_811, -0.0_418], [-0.1_561, -0.1_127, 0.2_687]]]	,    dtype=tf.floataa	,    )
           # camembert = torch.hub.load('pytorch/fairseq', 'camembert.v0')
           # camembert.eval()
           # expected_slice = roberta.model.forward(input_ids)[0][:, :3, :3].detach()

           self.assertTrue(np.allclose(output[:, :3, :3].numpy()	,    expected_slice.numpy()	,    atol=1E-4  )  )




