




'''simple docstring'''







import argparse

from . import (
    BertConfig,
    BertGenerationConfig,
    BertGenerationDecoder,
    BertGenerationEncoder,
    load_tf_weights_in_bert_generation,
    logging,
)


logging.set_verbosity_info()







def 	_A			(   UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase	):






   '''simple docstring'''







   A__         =    BertConfig.from_pretrained(
       'bert-large-cased'			,vocab_size=UpperCAmelCase			,max_position_embeddings=512			,is_decoder=UpperCAmelCase			,add_cross_attention=UpperCAmelCase			,)
   A__         =    bert_config.to_dict()
   del bert_config_dict["type_vocab_size"]
   A__         =    BertGenerationConfig(**UpperCAmelCase	)
   if is_encoder:
      A__         =    BertGenerationEncoder(UpperCAmelCase	)
   else:
      A__         =    BertGenerationDecoder(UpperCAmelCase	)
   print(F"""Building PyTorch model from configuration: {config}"""	)

   # Load weights from tf checkpoint
   load_tf_weights_in_bert_generation(
       UpperCAmelCase			,UpperCAmelCase			,model_class='bert'			,is_encoder_named_decoder=UpperCAmelCase			,is_encoder=UpperCAmelCase			,)

   # Save pytorch-model
   print(F"""Save PyTorch model and config to {pytorch_dump_path}"""	)
   model.save_pretrained(UpperCAmelCase	)


if __name__ == "__main__":
    lowerCAmelCase_    	=							argparse.ArgumentParser()
    # Required parameters
    parser.add_argument(
        '''--tf_hub_path''', default=None, type=str, required=True, help='''Path to the TensorFlow checkpoint path.'''
    )
    parser.add_argument(
        '''--pytorch_dump_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
    )
    parser.add_argument(
        '''--is_encoder_named_decoder''',
        action='''store_true''',
        help='''If decoder has to be renamed to encoder in PyTorch model.''',
    )
    parser.add_argument('''--is_encoder''', action='''store_true''', help='''If model is an encoder.''')
    parser.add_argument('''--vocab_size''', default=5_0_3_5_8, type=int, help='''Vocab size of model''')
    lowerCAmelCase_    	=							parser.parse_args()
    convert_tf_checkpoint_to_pytorch(
        args.tf_hub_path,
        args.pytorch_dump_path,
        args.is_encoder_named_decoder,
        args.vocab_size,
        is_encoder=args.is_encoder,
    )








'''simple docstring'''







import os

from apache_beam.io.filesystems import FileSystems
from apache_beam.pipeline import Pipeline

from .logging import get_logger


lowerCAmelCase_    	=							2 << 2_0  # 2mb
lowerCAmelCase_    	=							get_logger(__name__)

class   _snake_case( UpperCAmelCase			):






 def 	_UpperCamelCase   (self					:     Optional[int]						)					->      Optional[Any]:






    """simple docstring"""


    A__         =    self._options.get_all_options().get('runner'						)
    return runner in [None, "DirectRunner", "PortableRunner"]







def 	_A			(   UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase=False	):






   '''simple docstring'''







   A__         =    FileSystems
   if fs.exists(UpperCAmelCase	):
      if force_upload:
         logger.info(F"""Remote path already exist: {remote_file_path}. Overwriting it as force_upload=True."""	)
      else:
         logger.info(F"""Remote path already exist: {remote_file_path}. Skipping it as force_upload=False."""	)
         return
   with fs.create(UpperCAmelCase	) as remote_file:
      with open(UpperCAmelCase			,'rb'	) as local_file:
         A__         =    local_file.read(UpperCAmelCase	)
         while chunk:
            remote_file.write(UpperCAmelCase	)
            A__         =    local_file.read(UpperCAmelCase	)







def 	_A			(   UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase=False	):






   '''simple docstring'''







   A__         =    FileSystems
   if os.path.exists(UpperCAmelCase	):
      if force_download:
         logger.info(F"""Local path already exist: {remote_file_path}. Overwriting it as force_upload=True."""	)
      else:
         logger.info(F"""Local path already exist: {remote_file_path}. Skipping it as force_upload=False."""	)
         return
   with fs.open(UpperCAmelCase	) as remote_file:
      with open(UpperCAmelCase			,'wb'	) as local_file:
         A__         =    remote_file.read(UpperCAmelCase	)
         while chunk:
            local_file.write(UpperCAmelCase	)
            A__         =    remote_file.read(UpperCAmelCase	)


