




import unittest

import torch
from torch import nn

from diffusers.models.activations import get_activation


class        UpperCamelCase_					(				unittest.TestCase  ):

    '''simple docstring'''






    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->List[Any]:





           '''simple docstring'''

           A__   				=					get_activation('''swish''')

           self.assertIsInstance(UpperCAmelCase__      ,				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  SCREAMING_SNAKE_CASE							(    self   :			List[str])		->Dict:





           '''simple docstring'''

           A__   				=					get_activation('''silu''')

           self.assertIsInstance(UpperCAmelCase__      ,				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  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->int:





           '''simple docstring'''

           A__   				=					get_activation('''mish''')

           self.assertIsInstance(UpperCAmelCase__      ,				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  SCREAMING_SNAKE_CASE							(    self   :			List[str])		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					get_activation('''gelu''')

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








import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
  from transformers import AutoModelForSeqaSeqLM, AutoTokenizer


@require_torch
@require_sentencepiece
@require_tokenizers
class        UpperCamelCase_					(				unittest.TestCase  ):

    '''simple docstring'''






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





           '''simple docstring'''

           A__   				=					AutoModelForSeqaSeqLM.from_pretrained('''google/mt5-small'''      ,				return_dict=UpperCAmelCase__).to(UpperCAmelCase__)
           A__   				=					AutoTokenizer.from_pretrained('''google/mt5-small''')

           A__   				=					tokenizer('''Hello there'''      ,				return_tensors='''pt''').input_ids
           A__   				=					tokenizer('''Hi I am'''      ,				return_tensors='''pt''').input_ids

           A__   				=					model(input_ids.to(UpperCAmelCase__)      ,				labels=labels.to(UpperCAmelCase__)).loss
           A__   				=					-(labels.shape[-1] * loss.item())

           A__   				=					-84.9127
           self.assertTrue(abs(mtf_score - EXPECTED_SCORE) < 1e-4)


