

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


lowerCAmelCase							:  Optional[int]   	=						logging.get_logger(__name__)

lowerCAmelCase							:  Any   	=						{
    'shi-labs/dinat-mini-in1k-224': 'https://huggingface.co/shi-labs/dinat-mini-in1k-224/resolve/main/config.json',
    # See all Dinat models at https://huggingface.co/models?filter=dinat
}



class   __lowercase				( UpperCAmelCase_		,       UpperCAmelCase_	):




			"""simple docstring"""







			_UpperCAmelCase   :							str										=     '''dinat'''

			_UpperCAmelCase   :							str										=     {
			    '''num_attention_heads''': '''num_heads''',
			    '''num_hidden_layers''': '''num_layers''',
			}



			def __init__( self  :     Optional[Any]   ,						lowerCAmelCase__  :     Optional[Any]=4   ,						lowerCAmelCase__  :     List[str]=3   ,						lowerCAmelCase__  :     Optional[Any]=64   ,						lowerCAmelCase__  :     Union[str, Any]=[3, 4, 6, 5]   ,						lowerCAmelCase__  :     Optional[Any]=[2, 4, 8, 16]   ,						lowerCAmelCase__  :     Union[str, Any]=7   ,						lowerCAmelCase__  :     List[Any]=[[1, 8, 1], [1, 4, 1, 4], [1, 2, 1, 2, 1, 2], [1, 1, 1, 1, 1]]   ,						lowerCAmelCase__  :     str=3.0   ,						lowerCAmelCase__  :     List[str]=True   ,						lowerCAmelCase__  :     Any=0.0   ,						lowerCAmelCase__  :     Optional[Any]=0.0   ,						lowerCAmelCase__  :     List[str]=0.1   ,						lowerCAmelCase__  :     Dict="gelu"   ,						lowerCAmelCase__  :     Any=0.02   ,						lowerCAmelCase__  :     List[Any]=1E-5   ,						lowerCAmelCase__  :     Tuple=0.0   ,						lowerCAmelCase__  :     Optional[Any]=None   ,						lowerCAmelCase__  :     Tuple=None   ,						**lowerCAmelCase__  :     Any   ,						):
									super().__init__(**A__)

									SCREAMING_SNAKE_CASE_: List[str]  		=       patch_size
									SCREAMING_SNAKE_CASE_: int  		=       num_channels
									SCREAMING_SNAKE_CASE_: Tuple  		=       embed_dim
									SCREAMING_SNAKE_CASE_: Optional[Any]  		=       depths
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       len(A__)
									SCREAMING_SNAKE_CASE_: List[Any]  		=       num_heads
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       kernel_size
									SCREAMING_SNAKE_CASE_: str  		=       dilations
									SCREAMING_SNAKE_CASE_: Dict  		=       mlp_ratio
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       qkv_bias
									SCREAMING_SNAKE_CASE_: str  		=       hidden_dropout_prob
									SCREAMING_SNAKE_CASE_: List[str]  		=       attention_probs_dropout_prob
									SCREAMING_SNAKE_CASE_: Tuple  		=       drop_path_rate
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       hidden_act
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       layer_norm_eps
									SCREAMING_SNAKE_CASE_: Dict  		=       initializer_range
									# we set the hidden_size attribute in order to make Dinat work with VisionEncoderDecoderModel
									# this indicates the channel dimension after the last stage of the model
									SCREAMING_SNAKE_CASE_: List[str]  		=       int(embed_dim * 2 ** (len(A__) - 1))
									SCREAMING_SNAKE_CASE_: Dict  		=       layer_scale_init_value
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       ["""stem"""] + [F"stage{idx}" for idx in range(1   ,						len(A__) + 1)]
									SCREAMING_SNAKE_CASE_: int  		=       get_aligned_output_features_output_indices(
									    out_features=A__   ,						out_indices=A__   ,						stage_names=self.stage_names)









import argparse

import torch

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


logging.set_verbosity_info()

def 						UpperCamelCase					(lowercase_: Optional[int]    ,      lowercase_: Union[str, Any]    ,      lowercase_: Optional[Any]					)     ->      Tuple:
	# Initialise PyTorch model
	A__							:    str        =		AlbertConfig.from_json_file(lowercase_					)
	print(f"""Building PyTorch model from configuration: {config}"""					)
	A__							:    List[Any]        =		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__":
	A_       : int         =			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_       : int         =			parser.parse_args()
	convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.albert_config_file, args.pytorch_dump_path)



