





import argparse

import torch

from transformers import FunnelBaseModel, FunnelConfig, FunnelModel, load_tf_weights_in_funnel
from transformers.utils import logging


logging.set_verbosity_info()



def 				lowerCAmelCase_ (							A_    ,A_    ,A_    ,A_):
    # Initialise PyTorch model
    UpperCamelCase__:	Dict					=     FunnelConfig.from_json_file(A_)
    print(F"Building PyTorch model from configuration: {config}")
    UpperCamelCase__:	int					=     FunnelBaseModel(A_) if base_model else FunnelModel(A_)

    # Load weights from tf checkpoint
    load_tf_weights_in_funnel(A_    ,A_    ,A_)

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


if __name__ == "__main__":
   A__:    Dict  	=	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(
       '''--config_file''',
       default=None,
       type=str,
       required=True,
       help='''The config json file corresponding to the pre-trained model. \nThis 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(
       '''--base_model''', action='''store_true''', help='''Whether you want just the base model (no decoder) or not.'''
   )
   A__:    Union[str, Any]  	=	parser.parse_args()
   convert_tf_checkpoint_to_pytorch(
       args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.base_model
   )








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
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


A__:    Tuple  	=	logging.get_logger(__name__)

A__:    List[Any]  	=	{
    '''microsoft/swin-tiny-patch4-window7-224''': (
        '''https://huggingface.co/microsoft/swin-tiny-patch4-window7-224/resolve/main/config.json'''
    ),
    # See all Swin models at https://huggingface.co/models?filter=swin
}




class        _a    (    UpperCamelCase__						,			UpperCamelCase__):

      """simple docstring"""


      UpperCamelCase__  		=       """swin"""

      UpperCamelCase__  		=       {
          """num_attention_heads""": """num_heads""",
          """num_hidden_layers""": """num_layers""",
      }






      def __init__(		self:			Any	,    __lowerCamelCase:			Optional[Any]=224	,    __lowerCamelCase:			List[Any]=4	,    __lowerCamelCase:			Any=3	,    __lowerCamelCase:			Dict=96	,    __lowerCamelCase:			List[str]=[2, 2, 6, 2]	,    __lowerCamelCase:			int=[3, 6, 12, 24]	,    __lowerCamelCase:			str=7	,    __lowerCamelCase:			Union[str, Any]=4.0	,    __lowerCamelCase:			Union[str, Any]=True	,    __lowerCamelCase:			List[str]=0.0	,    __lowerCamelCase:			Union[str, Any]=0.0	,    __lowerCamelCase:			List[str]=0.1	,    __lowerCamelCase:			Union[str, Any]="gelu"	,    __lowerCamelCase:			List[str]=False	,    __lowerCamelCase:			Any=0.02	,    __lowerCamelCase:			Any=1e-5	,    __lowerCamelCase:			Optional[Any]=32	,    __lowerCamelCase:			Tuple=None	,    __lowerCamelCase:			int=None	,    **__lowerCamelCase:			int	,    ):
          '''simple docstring'''


          super().__init__(**__lowerCamelCase					)

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




class        _a    (    UpperCamelCase__):

      """simple docstring"""


      UpperCamelCase__  		=       version.parse("""1.11""")






      @property
      def 			UpperCAmelCase_       (		self:			List[Any]					):
          '''simple docstring'''


          return OrderedDict(
              [
                  ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
              ]					)






      @property
      def 			UpperCAmelCase_       (		self:			Union[str, Any]					):
          '''simple docstring'''


          return 1e-4

