


'''simple docstring'''






import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.text import TextDatasetReader

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases






def 	_A				(lowerCAmelCase__  :List[str]				,						lowerCAmelCase__  :List[str]		)   ->  str:




     '''simple docstring'''



     assert isinstance(lowerCAmelCase__				,						lowerCAmelCase__		)
     assert dataset.num_rows == 4
     assert dataset.num_columns == 1
     assert dataset.column_names == ["text"]
     for feature, expected_dtype in expected_features.items():
          assert dataset.features[feature].dtype == expected_dtype






@pytest.mark.parametrize('keep_in_memory'				,						[False, True]		)
def 	_A				(lowerCAmelCase__  :Tuple				,						lowerCAmelCase__  :Any				,						lowerCAmelCase__  :Optional[int]		)   ->  List[str]:




     '''simple docstring'''



     _a			      =							tmp_path / 'cache'
     _a			      =							{'text': 'string'}
     with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
          _a			      =							TextDatasetReader(lowerCAmelCase__				,						cache_dir=lowerCAmelCase__				,						keep_in_memory=lowerCAmelCase__		).read()
     _check_text_dataset(lowerCAmelCase__				,						lowerCAmelCase__		)






@pytest.mark.parametrize(
    'features'				,						[
        None,
        {'text': 'string'},
        {'text': 'int32'},
        {'text': 'float32'},
    ]				,						)
def 	_A				(lowerCAmelCase__  :List[str]				,						lowerCAmelCase__  :List[Any]				,						lowerCAmelCase__  :Tuple		)   ->  List[str]:




     '''simple docstring'''



     _a			      =							tmp_path / 'cache'
     _a			      =							{'text': 'string'}
     _a			      =							features.copy() if features else default_expected_features
     _a			      =							(
         Features({feature: Value(lowerCAmelCase__		) for feature, dtype in features.items()}		) if features is not None else None
     )
     _a			      =							TextDatasetReader(lowerCAmelCase__				,						features=lowerCAmelCase__				,						cache_dir=lowerCAmelCase__		).read()
     _check_text_dataset(lowerCAmelCase__				,						lowerCAmelCase__		)






@pytest.mark.parametrize('split'				,						[None, NamedSplit('train'		), 'train', 'test']		)
def 	_A				(lowerCAmelCase__  :Any				,						lowerCAmelCase__  :Any				,						lowerCAmelCase__  :Tuple		)   ->  Any:




     '''simple docstring'''



     _a			      =							tmp_path / 'cache'
     _a			      =							{'text': 'string'}
     _a			      =							TextDatasetReader(lowerCAmelCase__				,						cache_dir=lowerCAmelCase__				,						split=lowerCAmelCase__		).read()
     _check_text_dataset(lowerCAmelCase__				,						lowerCAmelCase__		)
     assert dataset.split == split if split else "train"






@pytest.mark.parametrize('path_type'				,						[str, list]		)
def 	_A				(lowerCAmelCase__  :int				,						lowerCAmelCase__  :List[Any]				,						lowerCAmelCase__  :Optional[Any]		)   ->  str:




     '''simple docstring'''



     if issubclass(lowerCAmelCase__				,						lowerCAmelCase__		):
          _a			      =							text_path
     elif issubclass(lowerCAmelCase__				,						lowerCAmelCase__		):
          _a			      =							[text_path]
     _a			      =							tmp_path / 'cache'
     _a			      =							{'text': 'string'}
     _a			      =							TextDatasetReader(lowerCAmelCase__				,						cache_dir=lowerCAmelCase__		).read()
     _check_text_dataset(lowerCAmelCase__				,						lowerCAmelCase__		)






def 	_A				(lowerCAmelCase__  :Optional[Any]				,						lowerCAmelCase__  :Optional[Any]				,						lowerCAmelCase__  :Optional[Any]=("train",)		)   ->  str:




     '''simple docstring'''



     assert isinstance(lowerCAmelCase__				,						lowerCAmelCase__		)
     for split in splits:
          _a			      =							dataset_dict[split]
          assert dataset.num_rows == 4
          assert dataset.num_columns == 1
          assert dataset.column_names == ["text"]
          for feature, expected_dtype in expected_features.items():
               assert dataset.features[feature].dtype == expected_dtype






@pytest.mark.parametrize('keep_in_memory'				,						[False, True]		)
def 	_A				(lowerCAmelCase__  :Optional[Any]				,						lowerCAmelCase__  :Tuple				,						lowerCAmelCase__  :Union[str, Any]		)   ->  str:




     '''simple docstring'''



     _a			      =							tmp_path / 'cache'
     _a			      =							{'text': 'string'}
     with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
          _a			      =							TextDatasetReader({'train': text_path}				,						cache_dir=lowerCAmelCase__				,						keep_in_memory=lowerCAmelCase__		).read()
     _check_text_datasetdict(lowerCAmelCase__				,						lowerCAmelCase__		)






@pytest.mark.parametrize(
    'features'				,						[
        None,
        {'text': 'string'},
        {'text': 'int32'},
        {'text': 'float32'},
    ]				,						)
def 	_A				(lowerCAmelCase__  :Union[str, Any]				,						lowerCAmelCase__  :List[str]				,						lowerCAmelCase__  :Dict		)   ->  Tuple:




     '''simple docstring'''



     _a			      =							tmp_path / 'cache'
     # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
     _a			      =							{'text': 'string'}
     _a			      =							features.copy() if features else default_expected_features
     _a			      =							(
         Features({feature: Value(lowerCAmelCase__		) for feature, dtype in features.items()}		) if features is not None else None
     )
     _a			      =							TextDatasetReader({'train': text_path}				,						features=lowerCAmelCase__				,						cache_dir=lowerCAmelCase__		).read()
     _check_text_datasetdict(lowerCAmelCase__				,						lowerCAmelCase__		)






@pytest.mark.parametrize('split'				,						[None, NamedSplit('train'		), 'train', 'test']		)
def 	_A				(lowerCAmelCase__  :Any				,						lowerCAmelCase__  :Dict				,						lowerCAmelCase__  :Tuple		)   ->  str:




     '''simple docstring'''



     if split:
          _a			      =							{split: text_path}
     else:
          _a			      =							'train'
          _a			      =							{'train': text_path, 'test': text_path}
     _a			      =							tmp_path / 'cache'
     _a			      =							{'text': 'string'}
     _a			      =							TextDatasetReader(lowerCAmelCase__				,						cache_dir=lowerCAmelCase__		).read()
     _check_text_datasetdict(lowerCAmelCase__				,						lowerCAmelCase__				,						splits=list(path.keys()		)		)
     assert all(dataset[split].split == split for split in path.keys()		)





'''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 	_A				(lowerCAmelCase__  :str				,						lowerCAmelCase__  :int				,						lowerCAmelCase__  :Any		)   ->  str:




     '''simple docstring'''



     _a			      =							BertConfig.from_json_file(lowerCAmelCase__		)
     print(f'Building PyTorch model from configuration: {config}'		)
     _a			      =							BertForPreTraining(lowerCAmelCase__		)

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

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


if __name__ == "__main__":
 a_					:    Optional[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_					:    Optional[int]          =    parser.parse_args()
 convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.bert_config_file, args.pytorch_dump_path)

