



from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase_									=							logging.get_logger(__name__)

UpperCAmelCase_									=							{
    "uclanlp/visualbert-vqa": "https://huggingface.co/uclanlp/visualbert-vqa/resolve/main/config.json",
    "uclanlp/visualbert-vqa-pre": "https://huggingface.co/uclanlp/visualbert-vqa-pre/resolve/main/config.json",
    "uclanlp/visualbert-vqa-coco-pre": (
        "https://huggingface.co/uclanlp/visualbert-vqa-coco-pre/resolve/main/config.json"
    ),
    "uclanlp/visualbert-vcr": "https://huggingface.co/uclanlp/visualbert-vcr/resolve/main/config.json",
    "uclanlp/visualbert-vcr-pre": "https://huggingface.co/uclanlp/visualbert-vcr-pre/resolve/main/config.json",
    "uclanlp/visualbert-vcr-coco-pre": (
        "https://huggingface.co/uclanlp/visualbert-vcr-coco-pre/resolve/main/config.json"
    ),
    "uclanlp/visualbert-nlvr2": "https://huggingface.co/uclanlp/visualbert-nlvr2/resolve/main/config.json",
    "uclanlp/visualbert-nlvr2-pre": "https://huggingface.co/uclanlp/visualbert-nlvr2-pre/resolve/main/config.json",
    "uclanlp/visualbert-nlvr2-coco-pre": (
        "https://huggingface.co/uclanlp/visualbert-nlvr2-coco-pre/resolve/main/config.json"
    )
    # See all VisualBERT models at https://huggingface.co/models?filter=visual_bert
}





class 		UpperCAmelCase						(						snake_case_				):
   SCREAMING_SNAKE_CASE__							=     '''visual_bert'''





   def __init__(	self       ,     _lowerCAmelCase=30_522       ,     _lowerCAmelCase=768       ,     _lowerCAmelCase=512       ,     _lowerCAmelCase=12       ,     _lowerCAmelCase=12       ,     _lowerCAmelCase=3_072       ,     _lowerCAmelCase="gelu"       ,     _lowerCAmelCase=0.1       ,     _lowerCAmelCase=0.1       ,     _lowerCAmelCase=512       ,     _lowerCAmelCase=2       ,     _lowerCAmelCase=0.02       ,     _lowerCAmelCase=1E-12       ,     _lowerCAmelCase=False       ,     _lowerCAmelCase=True       ,     _lowerCAmelCase=1       ,     _lowerCAmelCase=0       ,     _lowerCAmelCase=2       ,     **_lowerCAmelCase       ,     ):
         super().__init__(pad_token_id=_lowerCAmelCase       ,     bos_token_id=_lowerCAmelCase       ,     eos_token_id=_lowerCAmelCase       ,     **_lowerCAmelCase			)

         _lowerCAmelCase 			=  vocab_size
         _lowerCAmelCase 			=  max_position_embeddings
         _lowerCAmelCase 			=  hidden_size
         _lowerCAmelCase 			=  visual_embedding_dim
         _lowerCAmelCase 			=  num_hidden_layers
         _lowerCAmelCase 			=  num_attention_heads
         _lowerCAmelCase 			=  intermediate_size
         _lowerCAmelCase 			=  hidden_act
         _lowerCAmelCase 			=  hidden_dropout_prob
         _lowerCAmelCase 			=  attention_probs_dropout_prob
         _lowerCAmelCase 			=  initializer_range
         _lowerCAmelCase 			=  type_vocab_size
         _lowerCAmelCase 			=  layer_norm_eps
         _lowerCAmelCase 			=  bypass_transformer
         _lowerCAmelCase 			=  special_visual_initialize




import argparse

import torch

from ...utils import logging
from . import AlbertConfig, AlbertForPreTraining, load_tf_weights_in_albert


logging.set_verbosity_info()
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Optional[Any]     ,				_SCREAMING_SNAKE_CASE   :	List[Any]     ,				_SCREAMING_SNAKE_CASE   :	List[Any]				)->Dict:
      # Initialise PyTorch model
      _lowerCAmelCase 			=  AlbertConfig.from_json_file(_SCREAMING_SNAKE_CASE				)
      print(f'''Building PyTorch model from configuration: {config}'''				)
      _lowerCAmelCase 			=  AlbertForPreTraining(_SCREAMING_SNAKE_CASE				)

      # Load weights from tf checkpoint
      load_tf_weights_in_albert(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)

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


if __name__ == "__main__":
    UpperCAmelCase_									=							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(
        "--albert_config_file",
        default=None,
        type=str,
        required=True,
        help=(
            "The config json file corresponding to the pre-trained ALBERT 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."
    )
    UpperCAmelCase_									=							parser.parse_args()
    convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.albert_config_file, args.pytorch_dump_path)