"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A			   = logging.get_logger(__name__)

__A			   = {
    "facebook/s2t-small-librispeech-asr": (
        "https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json"
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}


class     UpperCAmelCase						(_UpperCAmelCase  ):



    """simple docstring"""

    _UpperCAmelCase	:str						    = "speech_to_text"
    _UpperCAmelCase	:List[str]						    = ["past_key_values"]
    _UpperCAmelCase	:Dict						    = {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}






    def __init__(   self    ,			_UpperCAmelCase=10000    ,			_UpperCAmelCase=12    ,			_UpperCAmelCase=2048    ,			_UpperCAmelCase=4    ,			_UpperCAmelCase=6    ,			_UpperCAmelCase=2048    ,			_UpperCAmelCase=4    ,			_UpperCAmelCase=0.0    ,			_UpperCAmelCase=0.0    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase="relu"    ,			_UpperCAmelCase=256    ,			_UpperCAmelCase=0.1    ,			_UpperCAmelCase=0.0    ,			_UpperCAmelCase=0.0    ,			_UpperCAmelCase=0.02    ,			_UpperCAmelCase=2    ,			_UpperCAmelCase=True    ,			_UpperCAmelCase=1    ,			_UpperCAmelCase=0    ,			_UpperCAmelCase=2    ,			_UpperCAmelCase=6000    ,			_UpperCAmelCase=1024    ,			_UpperCAmelCase=2    ,			_UpperCAmelCase=(5, 5)    ,			_UpperCAmelCase=1024    ,			_UpperCAmelCase=80    ,			_UpperCAmelCase=1    ,			**_UpperCAmelCase    ,			):
       lowercase__:   Optional[int]					=      vocab_size
       lowercase__:   int					=      d_model
       lowercase__:   Optional[int]					=      encoder_ffn_dim
       lowercase__:   Optional[Any]					=      encoder_layers
       lowercase__:   str					=      encoder_attention_heads
       lowercase__:   Tuple					=      decoder_ffn_dim
       lowercase__:   List[Any]					=      decoder_layers
       lowercase__:   Dict					=      decoder_attention_heads
       lowercase__:   Union[str, Any]					=      dropout
       lowercase__:   str					=      attention_dropout
       lowercase__:   List[str]					=      activation_dropout
       lowercase__:   Optional[int]					=      activation_function
       lowercase__:   int					=      init_std
       lowercase__:   str					=      encoder_layerdrop
       lowercase__:   Any					=      decoder_layerdrop
       lowercase__:   Optional[int]					=      use_cache
       lowercase__:   List[str]					=      encoder_layers
       lowercase__:   Optional[int]					=      scale_embedding  # scale factor will be sqrt(d_model) if True
       lowercase__:   Union[str, Any]					=      max_source_positions
       lowercase__:   Union[str, Any]					=      max_target_positions
       lowercase__:   Any					=      num_conv_layers
       lowercase__:   Dict					=      list(_UpperCAmelCase							)
       lowercase__:   Optional[int]					=      conv_channels
       lowercase__:   Any					=      input_feat_per_channel
       lowercase__:   Dict					=      input_channels

       if len(self.conv_kernel_sizes							) != self.num_conv_layers:
          raise ValueError(
              '''Configuration for convolutional module is incorrect. '''
              '''It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '''
              F"""but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes							)}`, """
              F"""`config.num_conv_layers = {self.num_conv_layers}`."""							)

       super().__init__(
           pad_token_id=_UpperCAmelCase    ,			bos_token_id=_UpperCAmelCase    ,			eos_token_id=_UpperCAmelCase    ,			is_encoder_decoder=_UpperCAmelCase    ,			decoder_start_token_id=_UpperCAmelCase    ,			**_UpperCAmelCase    ,			)

"""simple docstring"""






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 SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase       ,    __UpperCAmelCase )  ->  List[Any]:
   # Initialise PyTorch model
   lowercase__:   Optional[Any]					=      FunnelConfig.from_json_file(__UpperCAmelCase )
   print(F"""Building PyTorch model from configuration: {config}""" )
   lowercase__:   List[Any]					=      FunnelBaseModel(__UpperCAmelCase ) if base_model else FunnelModel(__UpperCAmelCase )

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

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


if __name__ == "__main__":
       __A			   = 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			   = parser.parse_args()
       convert_tf_checkpoint_to_pytorch(
           args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.base_model
       )
