





"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


UpperCamelCase_									=logging.get_logger(__name__)

UpperCamelCase_									={
    """microsoft/focalnet-tiny""": """https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json""",
}




class 			_a						(				_lowerCAmelCase     ,    _lowerCAmelCase    ):
				UpperCamelCase								=   '''focalnet'''






				def __init__(			self		:   List[Any],			lowerCAmelCase__		:   str=2_2_4,			lowerCAmelCase__		:   Optional[int]=4,			lowerCAmelCase__		:   Union[str, Any]=3,			lowerCAmelCase__		:   Any=9_6,			lowerCAmelCase__		:   Dict=False,			lowerCAmelCase__		:   List[Any]=[1_9_2, 3_8_4, 7_6_8, 7_6_8],			lowerCAmelCase__		:   Optional[int]=[2, 2, 6, 2],			lowerCAmelCase__		:   Optional[int]=[2, 2, 2, 2],			lowerCAmelCase__		:   Tuple=[3, 3, 3, 3],			lowerCAmelCase__		:   Tuple="gelu",			lowerCAmelCase__		:   Optional[int]=4.0,			lowerCAmelCase__		:   List[str]=0.0,			lowerCAmelCase__		:   int=0.1,			lowerCAmelCase__		:   Optional[int]=False,			lowerCAmelCase__		:   Optional[Any]=1e-4,			lowerCAmelCase__		:   str=False,			lowerCAmelCase__		:   Tuple=False,			lowerCAmelCase__		:   Any=False,			lowerCAmelCase__		:   List[str]=0.02,			lowerCAmelCase__		:   int=1e-5,			lowerCAmelCase__		:   Dict=3_2,			lowerCAmelCase__		:   List[Any]=None,			lowerCAmelCase__		:   Any=None,			**lowerCAmelCase__		:   Union[str, Any],			)     ->				Dict:




										'''simple docstring'''



										super().__init__(**lowerCamelCase_							)

										_UpperCamelCase      : Optional[Any]         =   image_size
										_UpperCamelCase      : str         =   patch_size
										_UpperCamelCase      : int         =   num_channels
										_UpperCamelCase      : List[str]         =   embed_dim
										_UpperCamelCase      : int         =   use_conv_embed
										_UpperCamelCase      : List[Any]         =   hidden_sizes
										_UpperCamelCase      : List[str]         =   depths
										_UpperCamelCase      : Dict         =   focal_levels
										_UpperCamelCase      : List[Any]         =   focal_windows
										_UpperCamelCase      : Optional[Any]         =   hidden_act
										_UpperCamelCase      : Any         =   mlp_ratio
										_UpperCamelCase      : Optional[int]         =   hidden_dropout_prob
										_UpperCamelCase      : Union[str, Any]         =   drop_path_rate
										_UpperCamelCase      : Tuple         =   use_layerscale
										_UpperCamelCase      : Dict         =   layerscale_value
										_UpperCamelCase      : Tuple         =   use_post_layernorm
										_UpperCamelCase      : Optional[int]         =   use_post_layernorm_in_modulation
										_UpperCamelCase      : Optional[int]         =   normalize_modulator
										_UpperCamelCase      : Tuple         =   initializer_range
										_UpperCamelCase      : List[str]         =   layer_norm_eps
										_UpperCamelCase      : str         =   encoder_stride
										_UpperCamelCase      : Optional[int]         =   ['''stem'''] + [f"""stage{idx}""" for idx in range(1,			len(self.depths							) + 1							)]
										_UpperCamelCase       ,							_UpperCamelCase      : Union[str, Any]         =   get_aligned_output_features_output_indices(
										    out_features=lowerCamelCase_,			out_indices=lowerCamelCase_,			stage_names=self.stage_names							)










"""simple docstring"""




import argparse

import torch

from transformers import MobileBertConfig, MobileBertForPreTraining, load_tf_weights_in_mobilebert
from transformers.utils import logging


logging.set_verbosity_info()





def 	a_    (							_lowercase	,						_lowercase	,						_lowercase       ):
						# Initialise PyTorch model
						_UpperCamelCase      : List[Any]         =   MobileBertConfig.from_json_file(_lowercase       )
						print(F"""Building PyTorch model from configuration: {config}"""       )
						_UpperCamelCase      : List[str]         =   MobileBertForPreTraining(_lowercase       )
						# Load weights from tf checkpoint
						_UpperCamelCase      : Union[str, Any]         =   load_tf_weights_in_mobilebert(_lowercase	,						_lowercase	,						_lowercase       )
						# Save pytorch-model
						print(F"""Save PyTorch model to {pytorch_dump_path}"""       )
						torch.save(model.state_dict()	,						_lowercase       )


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(
						    """--mobilebert_config_file""",
						    default=None,
						    type=str,
						    required=True,
						    help=(
						        """The config json file corresponding to the pre-trained MobileBERT 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.mobilebert_config_file, args.pytorch_dump_path)



