





import gc
import unittest

from diffusers import FlaxStableDiffusionInpaintPipeline
from diffusers.utils import is_flax_available, load_image, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
      import jax
      import jax.numpy as jnp
      from flax.jax_utils import replicate
      from flax.training.common_utils import shard

@slow
@require_flax
class 		UpperCamelCase__ (      unittest.TestCase   ):



     '''simple docstring'''

     def 				SCREAMING_SNAKE_CASE__  (							self						:    List[str]       )     ->		Dict:




           '''simple docstring'''


           super().tearDown()
           gc.collect()






     def 				SCREAMING_SNAKE_CASE__  (							self						:    str       )     ->		Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						load_image(
               """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
               """/sd2-inpaint/init_image.png"""       )
           SCREAMING_SNAKE_CASE		=						load_image(
               """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint/mask.png"""       )

           SCREAMING_SNAKE_CASE		=						"""xvjiarui/stable-diffusion-2-inpainting"""
           SCREAMING_SNAKE_CASE		=						FlaxStableDiffusionInpaintPipeline.from_pretrained(lowerCamelCase__						,safety_checker=lowerCamelCase__       )

           SCREAMING_SNAKE_CASE		=						"""Face of a yellow cat, high resolution, sitting on a park bench"""

           SCREAMING_SNAKE_CASE		=						jax.random.PRNGKey(0       )
           SCREAMING_SNAKE_CASE		=						50

           SCREAMING_SNAKE_CASE		=						jax.device_count()
           SCREAMING_SNAKE_CASE		=						num_samples * [prompt]
           SCREAMING_SNAKE_CASE		=						num_samples * [init_image]
           SCREAMING_SNAKE_CASE		=						num_samples * [mask_image]
           SCREAMING_SNAKE_CASE		=						pipeline.prepare_inputs(lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__       )

           # shard inputs and rng
           SCREAMING_SNAKE_CASE		=						replicate(lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						jax.random.split(lowerCamelCase__						,jax.device_count()       )
           SCREAMING_SNAKE_CASE		=						shard(lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						shard(lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						shard(lowerCamelCase__       )

           SCREAMING_SNAKE_CASE		=						pipeline(
               lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,jit=lowerCamelCase__       )

           SCREAMING_SNAKE_CASE		=						output.images.reshape(lowerCamelCase__						,512						,512						,3       )

           SCREAMING_SNAKE_CASE		=						images[0, 253:256, 253:256, -1]

           SCREAMING_SNAKE_CASE		=						jnp.asarray(jax.device_get(image_slice.flatten()       )       )
           SCREAMING_SNAKE_CASE		=						jnp.array(
               [0.3611307, 0.37649736, 0.3757408, 0.38213953, 0.39295167, 0.3841631, 0.41554978, 0.4137475, 0.4217084]       )
           print(F"""output_slice: {output_slice}"""       )
           assert jnp.abs(output_slice - expected_slice       ).max() < 1e-2




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):
      @slow
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Union[str, Any]							=      TFCamembertModel.from_pretrained("""jplu/tf-camembert-base"""      )

       lowerCamelCase		:	Any							=      tf.convert_to_tensor(
           [[5, 1_2_1, 1_1, 6_6_0, 1_6, 7_3_0, 2_5_5_4_3, 1_1_0, 8_3, 6]]    ,  dtype=tf.intaa    ,  )  # J'aime le camembert !"

       lowerCamelCase		:	str							=      model(__magic_name__      )["""last_hidden_state"""]
       lowerCamelCase		:	Union[str, Any]							=      tf.TensorShape((1, 1_0, 7_6_8)      )
       self.assertEqual(output.shape    ,  __magic_name__      )
       # compare the actual values for a slice.
       lowerCamelCase		:	Dict							=      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      )      )




