


'''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 TFXLMRobertaModel
@require_tf
@require_sentencepiece
@require_tokenizers
class    lowercase	(							unittest.TestCase					):

		"""simple docstring"""

		@slow
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :List[str]												= TFXLMRobertaModel.from_pretrained('''jplu/tf-xlm-roberta-base'''							)

							UpperCamelCase__   :int												= {
							    '''input_ids''': tf.convert_to_tensor([[0, 2646, 10269, 83, 99942, 2]]    ,   dtype=tf.intaa							),  # "My dog is cute"
							    '''attention_mask''': tf.convert_to_tensor([[1, 1, 1, 1, 1, 1]]    ,   dtype=tf.intaa							),
							}

							UpperCamelCase__   :Any												= model(UpperCamelCase_							)['''last_hidden_state''']
							UpperCamelCase__   :Any												= tf.TensorShape((1, 6, 768)							)
							self.assertEqual(output.shape    ,   UpperCamelCase_							)
							# compare the actual values for a slice.
							UpperCamelCase__   :Any												= tf.convert_to_tensor(
							    [
							        [
							            [0.0681762, 0.10894451, 0.06772504],
							            [-0.06423668, 0.02366615, 0.04329344],
							            [-0.06057295, 0.09974135, -0.00070584],
							        ]
							    ]    ,   dtype=tf.floataa    ,   )

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



"""simple docstring"""







import unittest

import torch
from torch import nn

from diffusers.models.activations import get_activation


class       SCREAMING_SNAKE_CASE__				(		unittest.TestCase				):
       """simple docstring"""


       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     int								=							get_activation("swish"						)

         self.assertIsInstance(snake_case__		,     nn.SiLU						)

         self.assertEqual(act(torch.tensor(-100		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertNotEqual(act(torch.tensor(-1		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertEqual(act(torch.tensor(0		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertEqual(act(torch.tensor(20		,     dtype=torch.floataa						)						).item()		,     20						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							get_activation("silu"						)

         self.assertIsInstance(snake_case__		,     nn.SiLU						)

         self.assertEqual(act(torch.tensor(-100		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertNotEqual(act(torch.tensor(-1		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertEqual(act(torch.tensor(0		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertEqual(act(torch.tensor(20		,     dtype=torch.floataa						)						).item()		,     20						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Dict								=							get_activation("mish"						)

         self.assertIsInstance(snake_case__		,     nn.Mish						)

         self.assertEqual(act(torch.tensor(-200		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertNotEqual(act(torch.tensor(-1		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertEqual(act(torch.tensor(0		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertEqual(act(torch.tensor(20		,     dtype=torch.floataa						)						).item()		,     20						)







       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							get_activation("gelu"						)

         self.assertIsInstance(snake_case__		,     nn.GELU						)

         self.assertEqual(act(torch.tensor(-100		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertNotEqual(act(torch.tensor(-1		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertEqual(act(torch.tensor(0		,     dtype=torch.floataa						)						).item()		,     0						)
         self.assertEqual(act(torch.tensor(20		,     dtype=torch.floataa						)						).item()		,     20						)





