



"""simple docstring"""

import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast
@dataclass
class     lowerCAmelCase__						(	datasets.BuilderConfig ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE	:		Optional[datasets.Features]  						= None




class     lowerCAmelCase__						(	datasets.ArrowBasedBuilder ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE	:		Union[str, Any]  						= PandasConfig





	def 			_lowerCAmelCase     (      self				:       Optional[int]    )						->	Tuple:





					"""simple docstring"""


					return datasets.DatasetInfo(features=self.config.features    )





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





					"""simple docstring"""


					if not self.config.data_files:
									raise ValueError(f"""At least one data file must be specified, but got data_files={self.config.data_files}"""    )
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     dl_manager.download_and_extract(self.config.data_files    )
					if isinstance(_SCREAMING_SNAKE_CASE     ,       (str, list, tuple)    ):
									SCREAMING_SNAKE_CASE						:							Tuple							=     data_files
									if isinstance(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    ):
													SCREAMING_SNAKE_CASE						:							Optional[Any]							=     [files]
									# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
									SCREAMING_SNAKE_CASE						:							Any							=     [dl_manager.iter_files(_SCREAMING_SNAKE_CASE    ) for file in files]
									return [datasets.SplitGenerator(name=datasets.Split.TRAIN     ,       gen_kwargs={'files': files}    )]
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     []
					for split_name, files in data_files.items():
									if isinstance(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    ):
													SCREAMING_SNAKE_CASE						:							List[str]							=     [files]
									# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
									SCREAMING_SNAKE_CASE						:							Optional[Any]							=     [dl_manager.iter_files(_SCREAMING_SNAKE_CASE    ) for file in files]
									splits.append(datasets.SplitGenerator(name=_SCREAMING_SNAKE_CASE     ,       gen_kwargs={'files': files}    )    )
					return splits





	def 			_lowerCAmelCase     (      self				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       pa.Table    )						->	pa.Table:





					"""simple docstring"""


					if self.config.features is not None:
									# more expensive cast to support nested features with keys in a different order
									# allows str <-> int/float or str to Audio for example
									SCREAMING_SNAKE_CASE						:							Tuple							=     table_cast(_SCREAMING_SNAKE_CASE     ,       self.config.features.arrow_schema    )
					return pa_table







	def 			_lowerCAmelCase     (      self				:       List[Any]     ,       _SCREAMING_SNAKE_CASE				:       List[Any]    )						->	Optional[Any]:





					"""simple docstring"""


					for i, file in enumerate(itertools.chain.from_iterable(_SCREAMING_SNAKE_CASE    )    ):
									with open(_SCREAMING_SNAKE_CASE     ,       'rb'    ) as f:
													SCREAMING_SNAKE_CASE						:							Dict							=     pa.Table.from_pandas(pd.read_pickle(_SCREAMING_SNAKE_CASE    )    )
													yield i, self._cast_table(_SCREAMING_SNAKE_CASE    )










"""simple docstring"""

import argparse

import torch

from transformers import BertConfig, BertForPreTraining, load_tf_weights_in_bert
from transformers.utils import logging


logging.set_verbosity_info()
def  __snake_case							(	__A      :						Union[str, Any]							,		__A      :						Any							,		__A      :						Dict     )     ->       Tuple:






				'''simple docstring'''
				# Initialise PyTorch model
				SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     BertConfig.from_json_file(__A     )
				print(F"""Building PyTorch model from configuration: {config}"""     )
				SCREAMING_SNAKE_CASE						:							List[Any]							=     BertForPreTraining(__A     )

				# Load weights from tf checkpoint
				load_tf_weights_in_bert(__A							,		__A							,		__A     )

				# Save pytorch-model
				print(F"""Save PyTorch model to {pytorch_dump_path}"""     )
				torch.save(model.state_dict()							,		__A     )


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 path.'
							)
							parser.add_argument(
							    '--bert_config_file',
							    default=None,
							    type=str,
							    required=True,
							    help=(
							        'The config json file corresponding to the pre-trained BERT model. \n'
							        'This specifies the model architecture.'
							    ),
							)
							parser.add_argument(
							    '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
							)
							A_						:    str				=      parser.parse_args()
							convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.bert_config_file, args.pytorch_dump_path)





