
"""simple docstring"""




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


lowerCAmelCase__							=				logging.get_logger(__name__)

lowerCAmelCase__							=				{
    '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  snake_case     (							__lowercase       ,			__lowercase   ):
							UpperCAmelCase__						     =      '''dinat'''

							UpperCAmelCase__						     =      {
							    '''num_attention_heads''': '''num_heads''',
							    '''num_hidden_layers''': '''num_layers''',
							}

							def __init__(self       ,       SCREAMING_SNAKE_CASE_=4       ,       SCREAMING_SNAKE_CASE_=3       ,       SCREAMING_SNAKE_CASE_=64       ,       SCREAMING_SNAKE_CASE_=[3, 4, 6, 5]       ,       SCREAMING_SNAKE_CASE_=[2, 4, 8, 16]       ,       SCREAMING_SNAKE_CASE_=7       ,       SCREAMING_SNAKE_CASE_=[[1, 8, 1], [1, 4, 1, 4], [1, 2, 1, 2, 1, 2], [1, 1, 1, 1, 1]]       ,       SCREAMING_SNAKE_CASE_=3.0       ,       SCREAMING_SNAKE_CASE_=True       ,       SCREAMING_SNAKE_CASE_=0.0       ,       SCREAMING_SNAKE_CASE_=0.0       ,       SCREAMING_SNAKE_CASE_=0.1       ,       SCREAMING_SNAKE_CASE_="gelu"       ,       SCREAMING_SNAKE_CASE_=0.02       ,       SCREAMING_SNAKE_CASE_=1e-5       ,       SCREAMING_SNAKE_CASE_=0.0       ,       SCREAMING_SNAKE_CASE_=None       ,       SCREAMING_SNAKE_CASE_=None       ,       **SCREAMING_SNAKE_CASE_       ,       ):

									"""simple docstring"""







									super().__init__(**SCREAMING_SNAKE_CASE_    )

									SCREAMING_SNAKE_CASE_						 = patch_size
									SCREAMING_SNAKE_CASE_						 = num_channels
									SCREAMING_SNAKE_CASE_						 = embed_dim
									SCREAMING_SNAKE_CASE_						 = depths
									SCREAMING_SNAKE_CASE_						 = len(SCREAMING_SNAKE_CASE_    )
									SCREAMING_SNAKE_CASE_						 = num_heads
									SCREAMING_SNAKE_CASE_						 = kernel_size
									SCREAMING_SNAKE_CASE_						 = dilations
									SCREAMING_SNAKE_CASE_						 = mlp_ratio
									SCREAMING_SNAKE_CASE_						 = qkv_bias
									SCREAMING_SNAKE_CASE_						 = hidden_dropout_prob
									SCREAMING_SNAKE_CASE_						 = attention_probs_dropout_prob
									SCREAMING_SNAKE_CASE_						 = drop_path_rate
									SCREAMING_SNAKE_CASE_						 = hidden_act
									SCREAMING_SNAKE_CASE_						 = layer_norm_eps
									SCREAMING_SNAKE_CASE_						 = 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_						 = int(embed_dim * 2 ** (len(SCREAMING_SNAKE_CASE_    ) - 1)    )
									SCREAMING_SNAKE_CASE_						 = layer_scale_init_value
									SCREAMING_SNAKE_CASE_						 = ['''stem'''] + [f'stage{idx}' for idx in range(1       ,       len(SCREAMING_SNAKE_CASE_    ) + 1    )]
									SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_						 = get_aligned_output_features_output_indices(
									    out_features=SCREAMING_SNAKE_CASE_       ,       out_indices=SCREAMING_SNAKE_CASE_       ,       stage_names=self.stage_names    )

"""simple docstring"""




import argparse

from transformers import BigBirdConfig, BigBirdForPreTraining, BigBirdForQuestionAnswering, load_tf_weights_in_big_bird
from transformers.utils import logging


logging.set_verbosity_info()



def        _lowerCamelCase ( __a,							__a,							__a,							__a    ):
		# Initialise PyTorch model
		SCREAMING_SNAKE_CASE_						 = BigBirdConfig.from_json_file(__a    )
		print(F'Building PyTorch model from configuration: {config}'    )

		if is_trivia_qa:
				SCREAMING_SNAKE_CASE_						 = BigBirdForQuestionAnswering(__a    )
		else:
				SCREAMING_SNAKE_CASE_						 = BigBirdForPreTraining(__a    )

		# Load weights from tf checkpoint
		load_tf_weights_in_big_bird(__a,							__a,							is_trivia_qa=__a    )

		# Save pytorch-model
		print(F'Save PyTorch model to {pytorch_dump_path}'    )
		model.save_pretrained(__a    )


if __name__ == "__main__":
						lowerCAmelCase__							=				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(
						    '--big_bird_config_file',
						    default=None,
						    type=str,
						    required=True,
						    help=(
						        'The config json file corresponding to the pre-trained BERT 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.'
						)
						parser.add_argument(
						    '--is_trivia_qa', action='store_true', help='Whether to convert a model with a trivia_qa head.'
						)
						lowerCAmelCase__							=				parser.parse_args()
						convert_tf_checkpoint_to_pytorch(
						    args.tf_checkpoint_path, args.big_bird_config_file, args.pytorch_dump_path, args.is_trivia_qa
						)