



'''simple docstring'''
from collections import Counter
from pathlib import Path
from typing import Optional, Tuple

import yaml






class 							lowercase__     (							yaml.SafeLoader       ):





	def      UpperCamelCase_  (			self :    Optional[Any]			,lowerCamelCase__ :    List[str]			):







							'''simple docstring'''
							_UpperCamelCase :		Union[str, Any]			    =       [self.constructed_objects[key_node] for key_node, _ in node.value]
							_UpperCamelCase :		Optional[int]			    =       [tuple(__lowerCAmelCase			) if isinstance(__lowerCAmelCase			,__lowerCAmelCase			) else key for key in keys]
							_UpperCamelCase :		Optional[Any]			    =       Counter(__lowerCAmelCase			)
							_UpperCamelCase :		Dict			    =       [key for key in counter if counter[key] > 1]
							if duplicate_keys:
													raise TypeError(F'Got duplicate yaml keys: {duplicate_keys}'			)





	def      UpperCamelCase_  (			self :    str			,lowerCamelCase__ :    Optional[int]			,lowerCamelCase__ :    Optional[int]=False			):







							'''simple docstring'''
							_UpperCamelCase :		Dict			    =       super().construct_mapping(__lowerCAmelCase			,deep=__lowerCAmelCase			)
							self._check_no_duplicates_on_constructed_node(__lowerCAmelCase			)
							return mapping






def A__   (					UpperCAmelCase_							):
						_UpperCamelCase :		List[Any]			    =       list(readme_content.splitlines()							)
						if full_content and full_content[0] == "---" and "---" in full_content[1:]:
												_UpperCamelCase :		str			    =       full_content[1:].index('---'							) + 1
												_UpperCamelCase :		Tuple			    =       '\n'.join(full_content[1:sep_idx]							)
												return yamlblock, "\n".join(full_content[sep_idx + 1 :]							)

						return None, "\n".join(a__							)






class 							lowercase__     (							_a       ):
	# class attributes
	lowercase__      =      {"""train_eval_index"""}  # train-eval-index in the YAML metadata





	@classmethod
	def      UpperCamelCase_  (			cls :    Union[str, Any]			,lowerCamelCase__ :    Dict			):







							'''simple docstring'''
							with open(__lowerCAmelCase			,encoding='utf-8'			) as readme_file:
													_UpperCamelCase    ,      _UpperCamelCase :		List[Any]			    =       _split_yaml_from_readme(readme_file.read()			)
							if yaml_string is not None:
													return cls.from_yaml_string(__lowerCAmelCase			)
							else:
													return cls()





	def      UpperCamelCase_  (			self :    str			,lowerCamelCase__ :    str			):







							'''simple docstring'''
							if path.exists():
													with open(__lowerCAmelCase			,encoding='utf-8'			) as readme_file:
																			_UpperCamelCase :		Optional[int]			    =       readme_file.read()
							else:
													_UpperCamelCase :		Optional[int]			    =       None
							_UpperCamelCase :		Any			    =       self._to_readme(__lowerCAmelCase			)
							with open(__lowerCAmelCase			,'w'			,encoding='utf-8'			) as readme_file:
													readme_file.write(__lowerCAmelCase			)





	def      UpperCamelCase_  (			self :    Union[str, Any]			,lowerCamelCase__ :    Any = None			):







							'''simple docstring'''
							if readme_content is not None:
													_UpperCamelCase    ,      _UpperCamelCase :		str			    =       _split_yaml_from_readme(__lowerCAmelCase			)
													_UpperCamelCase :		Optional[int]			    =       '---\n' + self.to_yaml_string() + '---\n' + content
							else:
													_UpperCamelCase :		Dict			    =       '---\n' + self.to_yaml_string() + '---\n'
							return full_content





	@classmethod
	def      UpperCamelCase_  (			cls :    List[str]			,lowerCamelCase__ :    Dict			):







							'''simple docstring'''
							_UpperCamelCase :		Any			    =       yaml.load(__lowerCAmelCase			,Loader=_NoDuplicateSafeLoader			) or {}

							# Convert the YAML keys to DatasetMetadata fields
							_UpperCamelCase :		Tuple			    =       {
							    (key.replace('-'			,'_'			) if key.replace('-'			,'_'			) in cls._FIELDS_WITH_DASHES else key): value
							    for key, value in metadata_dict.items()
							}
							return cls(**__lowerCAmelCase			)





	def      UpperCamelCase_  (			self :    Tuple			):







							'''simple docstring'''
							return yaml.safe_dump(
							    {
							        (key.replace('_'			,'-'			) if key in self._FIELDS_WITH_DASHES else key): value
							        for key, value in self.items()
							    }			,sort_keys=__lowerCAmelCase			,allow_unicode=__lowerCAmelCase			,encoding='utf-8'			,).decode('utf-8'			)
snake_case_			:     List[Any]  	=  {
    'image-classification': [],
    'translation': [],
    'image-segmentation': [],
    'fill-mask': [],
    'automatic-speech-recognition': [],
    'token-classification': [],
    'sentence-similarity': [],
    'audio-classification': [],
    'question-answering': [],
    'summarization': [],
    'zero-shot-classification': [],
    'table-to-text': [],
    'feature-extraction': [],
    'other': [],
    'multiple-choice': [],
    'text-classification': [],
    'text-to-image': [],
    'text2text-generation': [],
    'zero-shot-image-classification': [],
    'tabular-classification': [],
    'tabular-regression': [],
    'image-to-image': [],
    'tabular-to-text': [],
    'unconditional-image-generation': [],
    'text-retrieval': [],
    'text-to-speech': [],
    'object-detection': [],
    'audio-to-audio': [],
    'text-generation': [],
    'conversational': [],
    'table-question-answering': [],
    'visual-question-answering': [],
    'image-to-text': [],
    'reinforcement-learning': [],
    'voice-activity-detection': [],
    'time-series-forecasting': [],
    'document-question-answering': [],
}


if __name__ == "__main__":
					from argparse import ArgumentParser

					snake_case_			:     Any  	=  ArgumentParser(usage='Validate the yaml metadata block of a README.md file.')
					ap.add_argument('readme_filepath')
					snake_case_			:     int  	=  ap.parse_args()

					snake_case_			:     List[Any]  	=  Path(args.readme_filepath)
					snake_case_			:     List[str]  	=  DatasetMetadata.from_readme(readme_filepath)
					print(dataset_metadata)
					dataset_metadata.to_readme(readme_filepath)





'''simple docstring'''
import argparse

import torch

from transformers import LxmertConfig, LxmertForPreTraining, load_tf_weights_in_lxmert
from transformers.utils import logging


logging.set_verbosity_info()






def A__   (					UpperCAmelCase_  ,  UpperCAmelCase_  ,  UpperCAmelCase_							):
						# Initialise PyTorch model
						_UpperCamelCase :		Any			    =       LxmertConfig.from_json_file(UpperCAmelCase_							)
						print(f'Building PyTorch model from configuration: {config}'							)
						_UpperCamelCase :		int			    =       LxmertForPreTraining(UpperCAmelCase_							)

						# Load weights from tf checkpoint
						load_tf_weights_in_lxmert(UpperCAmelCase_  ,  UpperCAmelCase_  ,  UpperCAmelCase_							)

						# Save pytorch-model
						print(f'Save PyTorch model to {pytorch_dump_path}'							)
						torch.save(model.state_dict()  ,  UpperCAmelCase_							)


if __name__ == "__main__":
					snake_case_			:     int  	=  argparse.ArgumentParser()
					# Required parameters
					parser.add_argument(
					    '--tf_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
					)
					parser.add_argument(
					    '--config_file',
					    default=None,
					    type=str,
					    required=True,
					    help='The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.',
					)
					parser.add_argument(
					    '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
					)
					snake_case_			:     List[str]  	=  parser.parse_args()
					convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)


