import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard



class 			UpperCamelCase					(			unittest.TestCase			):

     '''simple docstring'''

     def 		UpperCamelCase_    (       self    )			->					Optional[int]:






           """simple docstring"""
           _lowerCamelCase           =					{
               '''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''': 76},
           }



     def 		UpperCamelCase_    (       self    )			->					Optional[Any]:






           """simple docstring"""
           _lowerCamelCase           =					ModelCard.from_dict(self.inputs_dict    )
           self.assertTrue(hasattr(A_					,					'''model_details'''    )    )
           self.assertTrue(hasattr(A_					,					'''intended_use'''    )    )
           self.assertTrue(hasattr(A_					,					'''factors'''    )    )
           self.assertTrue(hasattr(A_					,					'''metrics'''    )    )
           self.assertTrue(hasattr(A_					,					'''evaluation_data'''    )    )
           self.assertTrue(hasattr(A_					,					'''training_data'''    )    )
           self.assertTrue(hasattr(A_					,					'''quantitative_analyses'''    )    )
           self.assertTrue(hasattr(A_					,					'''ethical_considerations'''    )    )
           self.assertTrue(hasattr(A_					,					'''caveats_and_recommendations'''    )    )



     def 		UpperCamelCase_    (       self    )			->					List[str]:






           """simple docstring"""
           _lowerCamelCase           =					ModelCard.from_dict(self.inputs_dict    )
           _lowerCamelCase           =					json.loads(modelcard.to_json_string()    )
           for key, value in self.inputs_dict.items():
                 self.assertEqual(obj[key]					,					A_    )



     def 		UpperCamelCase_    (       self    )			->					int:






           """simple docstring"""
           _lowerCamelCase           =					ModelCard.from_dict(self.inputs_dict    )

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

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





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






           """simple docstring"""
           _lowerCamelCase           =					ModelCard.from_dict(self.inputs_dict    )

           with tempfile.TemporaryDirectory() as tmpdirname:
                 model_card_first.save_pretrained(A_    )
                 _lowerCamelCase           =					ModelCard.from_pretrained(A_    )

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

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


logging.set_verbosity_info()
def    __magic_name__(	__UpperCAmelCase			,    __UpperCAmelCase		)    ->     Tuple:



      '''simple docstring'''

      _lowerCamelCase           =					CanineConfig()
      _lowerCamelCase           =					CanineModel(__UpperCAmelCase		)
      model.eval()

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

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

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

      # Save tokenizer files
      _lowerCamelCase           =					CanineTokenizer()
      print(F'Save tokenizer files to {pytorch_dump_path}'		)
      tokenizer.save_pretrained(__UpperCAmelCase		)


if __name__ == "__main__":
     snake_case__						      =			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.',
     )
     snake_case__						      =			parser.parse_args()
     convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.pytorch_dump_path)