


"""simple docstring"""




import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
				import jax

				from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
				from transformers.models.bert.modeling_flax_bert import FlaxBertModel
				from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel
@require_flax
class 					__lowerCAmelCase					(   unittest.TestCase       ):


		'''simple docstring'''



		@slow
		def 			__UpperCAmelCase       (  self      ):
				for model_name in ["bert-base-cased", "bert-large-uncased"]:
						with self.subTest(_a      ):
								__a           =			AutoConfig.from_pretrained(_a      )
								self.assertIsNotNone(_a      )
								self.assertIsInstance(_a							, _a      )

								__a           =			FlaxAutoModel.from_pretrained(_a      )
								self.assertIsNotNone(_a      )
								self.assertIsInstance(_a							, _a      )

		@slow
		def 			__UpperCAmelCase       (  self      ):
				for model_name in ["roberta-base", "roberta-large"]:
						with self.subTest(_a      ):
								__a           =			AutoConfig.from_pretrained(_a      )
								self.assertIsNotNone(_a      )
								self.assertIsInstance(_a							, _a      )

								__a           =			FlaxAutoModel.from_pretrained(_a      )
								self.assertIsNotNone(_a      )
								self.assertIsInstance(_a							, _a      )

		@slow
		def 			__UpperCAmelCase       (  self      ):
				for model_name in ["bert-base-cased", "bert-large-uncased"]:
						__a           =			AutoTokenizer.from_pretrained(_a      )
						__a           =			FlaxBertModel.from_pretrained(_a      )
						__a           =			tokenizer('''Do you support jax jitted function?'''							, return_tensors=TensorType.JAX      )

						@jax.jit
						def eval(**_a      ):
								return model(**_a      )

						eval(**_a      ).block_until_ready()

		@slow
		def 			__UpperCAmelCase       (  self      ):
				for model_name in ["roberta-base", "roberta-large"]:
						__a           =			AutoTokenizer.from_pretrained(_a      )
						__a           =			FlaxRobertaModel.from_pretrained(_a      )
						__a           =			tokenizer('''Do you support jax jitted function?'''							, return_tensors=TensorType.JAX      )

						@jax.jit
						def eval(**_a      ):
								return model(**_a      )

						eval(**_a      ).block_until_ready()

		def 			__UpperCAmelCase       (  self      ):
				with self.assertRaisesRegex(
				    _a							, '''bert-base is not a local folder and is not a valid model identifier'''      ):
						__a           =			FlaxAutoModel.from_pretrained('''bert-base'''      )

		def 			__UpperCAmelCase       (  self      ):
				with self.assertRaisesRegex(
				    _a							, R'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''      ):
						__a           =			FlaxAutoModel.from_pretrained(_a							, revision='''aaaaaa'''      )

		def 			__UpperCAmelCase       (  self      ):
				with self.assertRaisesRegex(
				    _a							, '''hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack'''							, ):
						__a           =			FlaxAutoModel.from_pretrained('''hf-internal-testing/config-no-model'''      )





		def 			__UpperCAmelCase       (  self      ):
				with self.assertRaisesRegex(_a							, '''Use `from_pt=True` to load this model'''      ):
						__a           =			FlaxAutoModel.from_pretrained('''hf-internal-testing/tiny-bert-pt-only'''      )










"""simple docstring"""




import unittest

import torch
from torch import nn

from diffusers.models.activations import get_activation
class 					__lowerCAmelCase					(   unittest.TestCase       ):


		'''simple docstring'''



		def 			__UpperCAmelCase       (  self      ):
				__a           =			get_activation('''swish'''      )

				self.assertIsInstance(_a							, 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 			__UpperCAmelCase       (  self      ):
				__a           =			get_activation('''silu'''      )

				self.assertIsInstance(_a							, 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 			__UpperCAmelCase       (  self      ):
				__a           =			get_activation('''mish'''      )

				self.assertIsInstance(_a							, 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 			__UpperCAmelCase       (  self      ):
				__a           =			get_activation('''gelu'''      )

				self.assertIsInstance(_a							, 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      )






