



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


UpperCAmelCase_									=							logging.get_logger(__name__)

UpperCAmelCase_									=							{
    "sail/poolformer_s12": "https://huggingface.co/sail/poolformer_s12/resolve/main/config.json",
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
}





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





   def __init__(	self       ,     _lowerCAmelCase=3       ,     _lowerCAmelCase=16       ,     _lowerCAmelCase=16       ,     _lowerCAmelCase=3       ,     _lowerCAmelCase=4.0       ,     _lowerCAmelCase=[2, 2, 6, 2]       ,     _lowerCAmelCase=[64, 128, 320, 512]       ,     _lowerCAmelCase=[7, 3, 3, 3]       ,     _lowerCAmelCase=[4, 2, 2, 2]       ,     _lowerCAmelCase=[2, 1, 1, 1]       ,     _lowerCAmelCase=4       ,     _lowerCAmelCase=0.0       ,     _lowerCAmelCase="gelu"       ,     _lowerCAmelCase=True       ,     _lowerCAmelCase=1E-5       ,     _lowerCAmelCase=0.02       ,     **_lowerCAmelCase       ,     ):
         _lowerCAmelCase 			=  num_channels
         _lowerCAmelCase 			=  patch_size
         _lowerCAmelCase 			=  stride
         _lowerCAmelCase 			=  padding
         _lowerCAmelCase 			=  pool_size
         _lowerCAmelCase 			=  hidden_sizes
         _lowerCAmelCase 			=  mlp_ratio
         _lowerCAmelCase 			=  depths
         _lowerCAmelCase 			=  patch_sizes
         _lowerCAmelCase 			=  strides
         _lowerCAmelCase 			=  num_encoder_blocks
         _lowerCAmelCase 			=  drop_path_rate
         _lowerCAmelCase 			=  hidden_act
         _lowerCAmelCase 			=  use_layer_scale
         _lowerCAmelCase 			=  layer_scale_init_value
         _lowerCAmelCase 			=  initializer_range
         super().__init__(**_lowerCAmelCase			)






class 		UpperCAmelCase						(						snake_case_				):
   SCREAMING_SNAKE_CASE__							=     version.parse('''1.11'''				)





   @property
   def 	__lowerCAmelCase							(	self			):
         return OrderedDict(
             [
                 ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
             ]			)





   @property
   def 	__lowerCAmelCase							(	self			):
         return 2E-3




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)