


"""simple docstring"""



from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__snake_case       =       logging.get_logger(__name__)

__snake_case       =       {
    """microsoft/beit-base-patch16-224-pt22k""": (
        """https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json"""
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}







class _lowerCAmelCase							( snake_case_      ):
   __UpperCAmelCase					:			List[Any]				    =    '''beit'''







   def __init__(      self		,      UpperCamelCase__=8192		,      UpperCamelCase__=768		,      UpperCamelCase__=12		,      UpperCamelCase__=12		,      UpperCamelCase__=3072		,      UpperCamelCase__="gelu"		,      UpperCamelCase__=0.0		,      UpperCamelCase__=0.0		,      UpperCamelCase__=0.02		,      UpperCamelCase__=1e-12		,      UpperCamelCase__=224		,      UpperCamelCase__=16		,      UpperCamelCase__=3		,      UpperCamelCase__=False		,      UpperCamelCase__=False		,      UpperCamelCase__=False		,      UpperCamelCase__=False		,      UpperCamelCase__=0.1		,      UpperCamelCase__=0.1		,      UpperCamelCase__=True		,      UpperCamelCase__=[3, 5, 7, 11]		,      UpperCamelCase__=[1, 2, 3, 6]		,      UpperCamelCase__=True		,      UpperCamelCase__=0.4		,      UpperCamelCase__=256		,      UpperCamelCase__=1		,      UpperCamelCase__=False		,      UpperCamelCase__=255		,      **UpperCamelCase__		,      )      ->						List[str]:

       '''simple docstring'''




       super().__init__(**UpperCamelCase__		)

       snake_case       : Dict    =       vocab_size
       snake_case       : Tuple    =       hidden_size
       snake_case       : List[Any]    =       num_hidden_layers
       snake_case       : List[Any]    =       num_attention_heads
       snake_case       : int    =       intermediate_size
       snake_case       : Optional[int]    =       hidden_act
       snake_case       : str    =       hidden_dropout_prob
       snake_case       : List[Any]    =       attention_probs_dropout_prob
       snake_case       : Optional[int]    =       initializer_range
       snake_case       : Optional[Any]    =       layer_norm_eps

       snake_case       : List[str]    =       image_size
       snake_case       : str    =       patch_size
       snake_case       : str    =       num_channels
       snake_case       : Optional[int]    =       use_mask_token
       snake_case       : Tuple    =       use_absolute_position_embeddings
       snake_case       : int    =       use_relative_position_bias
       snake_case       : List[Any]    =       use_shared_relative_position_bias
       snake_case       : Dict    =       layer_scale_init_value
       snake_case       : List[str]    =       drop_path_rate
       snake_case       : Optional[Any]    =       use_mean_pooling
       # decode head attributes (semantic segmentation)
       snake_case       : Optional[Any]    =       out_indices
       snake_case       : Union[str, Any]    =       pool_scales
       # auxiliary head attributes (semantic segmentation)
       snake_case       : List[str]    =       use_auxiliary_head
       snake_case       : int    =       auxiliary_loss_weight
       snake_case       : Dict    =       auxiliary_channels
       snake_case       : List[Any]    =       auxiliary_num_convs
       snake_case       : List[Any]    =       auxiliary_concat_input
       snake_case       : Optional[int]    =       semantic_loss_ignore_index







class _lowerCAmelCase							( snake_case_      ):
   __UpperCAmelCase					:			List[Any]				    =    version.parse('''1.11'''      )







   @property
   def 					lowerCamelCase						(      self		)      ->						Mapping[str, Mapping[int, str]]:

       '''simple docstring'''




       return OrderedDict(
           [
               ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
           ]		)







   @property
   def 					lowerCamelCase						(      self		)      ->						float:

       '''simple docstring'''




       return 1e-4









"""simple docstring"""



import argparse

import torch

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


logging.set_verbosity_info()







def     __lowerCAmelCase		(		lowercase    :    List[Any]		,				lowercase    :    Dict		,				lowercase    :    str					)      ->		Optional[int]:


    """simple docstring"""





    snake_case       : Tuple    =       AlbertConfig.from_json_file(lowercase					)
    print(F'Building PyTorch model from configuration: {config}'					)
    snake_case       : int    =       AlbertForPreTraining(lowercase					)

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

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


if __name__ == "__main__":
  __snake_case       =       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."""
  )
  __snake_case       =       parser.parse_args()
  convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.albert_config_file, args.pytorch_dump_path)





