





import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
 pass

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


__A      		=     logging.get_logger(__name__)

__A      		=     {
    '''kakaobrain/align-base''': '''https://huggingface.co/kakaobrain/align-base/resolve/main/config.json''',
}



class   lowercase_   (  __lowercase					):
      UpperCamelCase_      :		int										=    '''align_text_model'''



      def __init__(      self				:    Tuple      , A__				:    Tuple=30522      , A__				:    str=768      , A__				:    Tuple=12      , A__				:    Dict=12      , A__				:    Any=3072      , A__				:    str="gelu"      , A__				:    int=0.1      , A__				:    Optional[Any]=0.1      , A__				:    int=512      , A__				:    List[str]=2      , A__				:    Any=0.02      , A__				:    Dict=1e-12      , A__				:    Tuple=0      , A__				:    Optional[Any]="absolute"      , A__				:    str=True      , **A__				:    Union[str, Any]      , )   ->					Optional[int]:
        super().__init__(**_a		)

        _snake_case						=							vocab_size
        _snake_case						=							hidden_size
        _snake_case						=							num_hidden_layers
        _snake_case						=							num_attention_heads
        _snake_case						=							hidden_act
        _snake_case						=							intermediate_size
        _snake_case						=							hidden_dropout_prob
        _snake_case						=							attention_probs_dropout_prob
        _snake_case						=							max_position_embeddings
        _snake_case						=							type_vocab_size
        _snake_case						=							initializer_range
        _snake_case						=							layer_norm_eps
        _snake_case						=							position_embedding_type
        _snake_case						=							use_cache
        _snake_case						=							pad_token_id







      @classmethod
      def 						UpperCamelCase_		(      cls				:    List[str]      , A__				:    Union[str, os.PathLike]      , **A__				:    Any		)   ->					Optional[Any]:
        cls._set_token_in_kwargs(_a		)

        _snake_case,					_snake_case						=							cls.get_config_dict(_a      , **_a		)

        # get the text config dict if we are loading from AlignConfig
        if config_dict.get('''model_type'''		) == "align":
          _snake_case						=							config_dict['''text_config''']

        if "model_type" in config_dict and hasattr(cls      , '''model_type'''		) and config_dict["model_type"] != cls.model_type:
          logger.warning(
              f"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
              f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""		)

        return cls.from_dict(_a      , **_a		)



class   lowercase_   (  __lowercase					):
      UpperCamelCase_      :		List[Any]										=    '''align_vision_model'''



      def __init__(      self				:    List[str]      , A__				:    int = 3      , A__				:    int = 600      , A__				:    float = 2.0      , A__				:    float = 3.1      , A__				:    int = 8      , A__				:    List[int] = [3, 3, 5, 3, 5, 5, 3]      , A__				:    List[int] = [32, 16, 24, 40, 80, 112, 192]      , A__				:    List[int] = [16, 24, 40, 80, 112, 192, 320]      , A__				:    List[int] = []      , A__				:    List[int] = [1, 2, 2, 2, 1, 2, 1]      , A__				:    List[int] = [1, 2, 2, 3, 3, 4, 1]      , A__				:    List[int] = [1, 6, 6, 6, 6, 6, 6]      , A__				:    float = 0.25      , A__				:    str = "swish"      , A__				:    int = 2560      , A__				:    str = "mean"      , A__				:    float = 0.02      , A__				:    float = 0.001      , A__				:    float = 0.99      , A__				:    float = 0.2      , **A__				:    List[Any]      , )   ->					str:
        super().__init__(**_a		)

        _snake_case						=							num_channels
        _snake_case						=							image_size
        _snake_case						=							width_coefficient
        _snake_case						=							depth_coefficient
        _snake_case						=							depth_divisor
        _snake_case						=							kernel_sizes
        _snake_case						=							in_channels
        _snake_case						=							out_channels
        _snake_case						=							depthwise_padding
        _snake_case						=							strides
        _snake_case						=							num_block_repeats
        _snake_case						=							expand_ratios
        _snake_case						=							squeeze_expansion_ratio
        _snake_case						=							hidden_act
        _snake_case						=							hidden_dim
        _snake_case						=							pooling_type
        _snake_case						=							initializer_range
        _snake_case						=							batch_norm_eps
        _snake_case						=							batch_norm_momentum
        _snake_case						=							drop_connect_rate
        _snake_case						=							sum(_a		) * 4







      @classmethod
      def 						UpperCamelCase_		(      cls				:    Tuple      , A__				:    Union[str, os.PathLike]      , **A__				:    Union[str, Any]		)   ->					List[str]:
        cls._set_token_in_kwargs(_a		)

        _snake_case,					_snake_case						=							cls.get_config_dict(_a      , **_a		)

        # get the vision config dict if we are loading from AlignConfig
        if config_dict.get('''model_type'''		) == "align":
          _snake_case						=							config_dict['''vision_config''']

        if "model_type" in config_dict and hasattr(cls      , '''model_type'''		) and config_dict["model_type"] != cls.model_type:
          logger.warning(
              f"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
              f"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""		)

        return cls.from_dict(_a      , **_a		)



class   lowercase_   (  __lowercase					):
      UpperCamelCase_      :		List[Any]										=    '''align'''
      UpperCamelCase_      :		Optional[int]										=    True



      def __init__(      self				:    Optional[int]      , A__				:    Tuple=None      , A__				:    int=None      , A__				:    Any=640      , A__				:    Optional[Any]=1.0      , A__				:    Tuple=0.02      , **A__				:    List[Any]      , )   ->					Optional[int]:
        super().__init__(**_a		)

        if text_config is None:
          _snake_case						=							{}
          logger.info('''text_config is None. Initializing the AlignTextConfig with default values.'''		)

        if vision_config is None:
          _snake_case						=							{}
          logger.info('''vision_config is None. Initializing the AlignVisionConfig with default values.'''		)

        _snake_case						=							AlignTextConfig(**_a		)
        _snake_case						=							AlignVisionConfig(**_a		)

        _snake_case						=							projection_dim
        _snake_case						=							temperature_init_value
        _snake_case						=							initializer_range



      @classmethod
      def 						UpperCamelCase_		(      cls				:    Optional[int]      , A__				:    AlignTextConfig      , A__				:    AlignVisionConfig      , **A__				:    Optional[Any]		)   ->					Optional[Any]:
        return cls(text_config=text_config.to_dict()      , vision_config=vision_config.to_dict()      , **_a		)







      def 						UpperCamelCase_		(      self				:    Tuple		)   ->					Any:
        _snake_case						=							copy.deepcopy(self.__dict__		)
        _snake_case						=							self.text_config.to_dict()
        _snake_case						=							self.vision_config.to_dict()
        _snake_case						=							self.__class__.model_type
        return output




import argparse

import torch

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


logging.set_verbosity_info()



def 				snake_case_(_UpperCamelCase			,	_UpperCamelCase			,	_UpperCamelCase					)							->     Optional[Any]:



  """simple docstring"""






  _snake_case						=							AlbertConfig.from_json_file(_UpperCamelCase					)
  print(F"""Building PyTorch model from configuration: {config}"""					)
  _snake_case						=							AlbertForPreTraining(_UpperCamelCase					)

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

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


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

