
'''simple docstring'''





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 			UpperCamelCase__	(     unittest.TestCase):






 def 						lowercase_    (      self	:Dict      )					->      Any:







       '''simple docstring'''



       __A													=      tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0]      )
       __A													=      get_tf_activation('gelu'      )
       __A													=      get_tf_activation('gelu_10'      )

       __A													=      gelu(_A      )
       __A													=      geluaa(_A      )

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

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






 def 						lowercase_    (      self	:Union[str, Any]      )					->      int:







       '''simple docstring'''



       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(_A      ):
             get_tf_activation('bogus'      )
       with self.assertRaises(_A      ):
             get_tf_activation(_A      )










import argparse

from transformers import CanineConfig, CanineModel, CanineTokenizer, load_tf_weights_in_canine
from transformers.utils import logging


logging.set_verbosity_info()



def      __lowerCAmelCase    (				snake_case						:     Union[str, Any]    ,   snake_case						:     Optional[int]			)							->				List[Any]:
   # Initialize PyTorch model
   __lowerCamelCase:					str	 =						CanineConfig()
   __lowerCamelCase:					Union[str, Any]	 =						CanineModel(snake_case			)
   model.eval()

   print(f'Building PyTorch model from configuration: {config}'			)

   # Load weights from tf checkpoint
   load_tf_weights_in_canine(snake_case    ,   snake_case    ,   snake_case			)

   # Save pytorch-model (weights and configuration)
   print(f'Save PyTorch model to {pytorch_dump_path}'			)
   model.save_pretrained(snake_case			)

   # Save tokenizer files
   __lowerCamelCase:					Optional[int]	 =						CanineTokenizer()
   print(f'Save tokenizer files to {pytorch_dump_path}'			)
   tokenizer.save_pretrained(snake_case			)


if __name__ == "__main__":
   _A		:					int          =							argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       '''--tf_checkpoint_path''',
       default=None,
       type=str,
       required=True,
       help='''Path to the TensorFlow checkpoint. Should end with model.ckpt''',
   )
   parser.add_argument(
       '''--pytorch_dump_path''',
       default=None,
       type=str,
       required=True,
       help='''Path to a folder where the PyTorch model will be placed.''',
   )
   _A		:					int          =							parser.parse_args()
   convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.pytorch_dump_path)


