



import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard







class    lowerCamelCase__     ( unittest.TestCase):





     def   __A      (self )  ->     int:
      _lowercase							   ={
          '''model_details''': {
              '''Organization''': '''testing''',
              '''Model date''': '''today''',
              '''Model version''': '''v2.1, Developed by Test Corp in 2019.''',
              '''Architecture''': '''Convolutional Neural Network.''',
          },
          '''metrics''': '''BLEU and ROUGE-1''',
          '''evaluation_data''': {
              '''Datasets''': {'''BLEU''': '''My-great-dataset-v1''', '''ROUGE-1''': '''My-short-dataset-v2.1'''},
              '''Preprocessing''': '''See details on https://arxiv.org/pdf/1810.03993.pdf''',
          },
          '''training_data''': {
              '''Dataset''': '''English Wikipedia dump dated 2018-12-01''',
              '''Preprocessing''': (
                  '''Using SentencePiece vocabulary of size 52k tokens. See details on'''
                  ''' https://arxiv.org/pdf/1810.03993.pdf'''
              ),
          },
          '''quantitative_analyses''': {'''BLEU''': 55.1, '''ROUGE-1''': 7_6},
      }





     def   __A      (self )  ->     Tuple:
      _lowercase							   =ModelCard.from_dict(self.inputs_dict )
      self.assertTrue(hasattr(UpperCAmelCase	,  '''model_details''' ) )
      self.assertTrue(hasattr(UpperCAmelCase	,  '''intended_use''' ) )
      self.assertTrue(hasattr(UpperCAmelCase	,  '''factors''' ) )
      self.assertTrue(hasattr(UpperCAmelCase	,  '''metrics''' ) )
      self.assertTrue(hasattr(UpperCAmelCase	,  '''evaluation_data''' ) )
      self.assertTrue(hasattr(UpperCAmelCase	,  '''training_data''' ) )
      self.assertTrue(hasattr(UpperCAmelCase	,  '''quantitative_analyses''' ) )
      self.assertTrue(hasattr(UpperCAmelCase	,  '''ethical_considerations''' ) )
      self.assertTrue(hasattr(UpperCAmelCase	,  '''caveats_and_recommendations''' ) )





     def   __A      (self )  ->     List[str]:
      _lowercase							   =ModelCard.from_dict(self.inputs_dict )
      _lowercase							   =json.loads(modelcard.to_json_string() )
      for key, value in self.inputs_dict.items():
       self.assertEqual(obj[key]	,  UpperCAmelCase )





     def   __A      (self )  ->     Any:
      _lowercase							   =ModelCard.from_dict(self.inputs_dict )

      with tempfile.TemporaryDirectory() as tmpdirname:
       _lowercase							   =os.path.join(UpperCAmelCase	,  '''modelcard.json''' )
       model_card_first.to_json_file(UpperCAmelCase )
       _lowercase							   =ModelCard.from_json_file(UpperCAmelCase )

      self.assertEqual(model_card_second.to_dict()	,  model_card_first.to_dict() )





     def   __A      (self )  ->     List[Any]:
      _lowercase							   =ModelCard.from_dict(self.inputs_dict )

      with tempfile.TemporaryDirectory() as tmpdirname:
       model_card_first.save_pretrained(UpperCAmelCase )
       _lowercase							   =ModelCard.from_pretrained(UpperCAmelCase )

      self.assertEqual(model_card_second.to_dict()	,  model_card_first.to_dict() )





import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
  import tensorflow as tf

  from transformers.activations_tf import get_tf_activation







@require_tf
class    lowerCamelCase__     ( unittest.TestCase):





     def   __A      (self )  ->     Optional[Any]:
      _lowercase							   =tf.constant([-1_0_0, -1.0, -0.1, 0, 0.1, 1.0, 100.0] )
      _lowercase							   =get_tf_activation('''gelu''' )
      _lowercase							   =get_tf_activation('''gelu_10''' )

      _lowercase							   =gelu(UpperCAmelCase )
      _lowercase							   =geluaa(UpperCAmelCase )

      _lowercase							   =tf.where(y_gelu_aa < 10.0	,  1.0	,  0.0 )

      self.assertEqual(tf.math.reduce_max(UpperCAmelCase ).numpy().item()	,  10.0 )
      self.assertTrue(np.allclose(y_gelu * clipped_mask	,  y_gelu_aa * clipped_mask ) )





     def   __A      (self )  ->     Optional[Any]:
      get_tf_activation('''gelu''' )
      get_tf_activation('''gelu_10''' )
      get_tf_activation('''gelu_fast''' )
      get_tf_activation('''gelu_new''' )
      get_tf_activation('''glu''' )
      get_tf_activation('''mish''' )
      get_tf_activation('''quick_gelu''' )
      get_tf_activation('''relu''' )
      get_tf_activation('''sigmoid''' )
      get_tf_activation('''silu''' )
      get_tf_activation('''swish''' )
      get_tf_activation('''tanh''' )
      with self.assertRaises(UpperCAmelCase ):
       get_tf_activation('''bogus''' )
      with self.assertRaises(UpperCAmelCase ):
       get_tf_activation(UpperCAmelCase )

