





'''simple docstring'''






import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
      import torch

      from transformers.activations import gelu_new, gelu_python, get_activation




@require_torch
class 			UpperCAmelCase					(      unittest.TestCase       ):




      def     lowercase__   (      self      :			Optional[Any]  )    ->				Tuple:
            _lowerCAmelCase												=							torch.tensor([-1_00, -1, -0.1, 0, 0.1, 1.0, 1_00]  )
            _lowerCAmelCase												=							get_activation("""gelu"""  )
            self.assertTrue(torch.allclose(gelu_python(__snake_case  )      ,      torch_builtin(__snake_case  )  )  )
            self.assertFalse(torch.allclose(gelu_python(__snake_case  )      ,      gelu_new(__snake_case  )  )  )




      def     lowercase__   (      self      :			List[str]  )    ->				Optional[Any]:
            _lowerCAmelCase												=							torch.tensor([-1_00, -1, -0.1, 0, 0.1, 1.0, 1_00]  )
            _lowerCAmelCase												=							get_activation("""gelu"""  )
            _lowerCAmelCase												=							get_activation("""gelu_10"""  )

            _lowerCAmelCase												=							torch_builtin(__snake_case  )
            _lowerCAmelCase												=							geluaa(__snake_case  )

            _lowerCAmelCase												=							torch.where(y_gelu_aa < 10.0      ,      1      ,      0  )

            self.assertTrue(torch.max(__snake_case  ).item() == 10.0  )
            self.assertTrue(torch.allclose(y_gelu * clipped_mask      ,      y_gelu_aa * clipped_mask  )  )




      def     lowercase__   (      self      :			Union[str, Any]  )    ->				Any:
            get_activation("""gelu"""  )
            get_activation("""gelu_10"""  )
            get_activation("""gelu_fast"""  )
            get_activation("""gelu_new"""  )
            get_activation("""gelu_python"""  )
            get_activation("""gelu_pytorch_tanh"""  )
            get_activation("""linear"""  )
            get_activation("""mish"""  )
            get_activation("""quick_gelu"""  )
            get_activation("""relu"""  )
            get_activation("""sigmoid"""  )
            get_activation("""silu"""  )
            get_activation("""swish"""  )
            get_activation("""tanh"""  )
            with self.assertRaises(__snake_case  ):
                  get_activation("""bogus"""  )
            with self.assertRaises(__snake_case  ):
                  get_activation(__snake_case  )




      def     lowercase__   (      self      :			Tuple  )    ->				Any:
            _lowerCAmelCase												=							get_activation("""gelu"""  )
            _lowerCAmelCase												=							1
            _lowerCAmelCase												=							get_activation("""gelu"""  )
            self.assertEqual(acta.a      ,      1  )
            with self.assertRaises(__snake_case  ):
                  _lowerCAmelCase												=							acta.a













'''simple docstring'''






import os
import tempfile
import unittest

from transformers.models.marian.convert_marian_tatoeba_to_pytorch import DEFAULT_REPO, TatoebaConverter
from transformers.testing_utils import slow
from transformers.utils import cached_property




@unittest.skipUnless(os.path.exists(snake_case_       )							,		'''Tatoeba directory does not exist.'''       )
class 			UpperCAmelCase					(      unittest.TestCase       ):




      @cached_property
      def     lowercase__   (      self      :			int  )    ->				Any:
            _lowerCAmelCase												=							tempfile.mkdtemp()
            return TatoebaConverter(save_dir=__snake_case  )




      @slow
      def     lowercase__   (      self      :			Dict  )    ->				int:
            self.resolver.convert_models(["""heb-eng"""]  )




      @slow
      def     lowercase__   (      self      :			Optional[int]  )    ->				Tuple:
            _lowerCAmelCase					,							_lowerCAmelCase												=							self.resolver.write_model_card("""opus-mt-he-en"""      ,      dry_run=__snake_case  )
            assert mmeta["long_pair"] == "heb-eng"






