
import functools
import operator

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


__lowerCAmelCase			:     List[Any]           =   logging.get_logger(__name__)

__lowerCAmelCase			:     Tuple           =   {
    'microsoft/unispeech-sat-base-100h-libri-ft': (
        'https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json'
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}




class        UpperCAmelCase_			( _A     ):


  '''simple docstring'''







  a__           =		"""unispeech-sat"""
  def __init__( self			: Optional[int]			,							UpperCamelCase__			: List[str]=32			,							UpperCamelCase__			: List[str]=768			,							UpperCamelCase__			: List[Any]=12			,							UpperCamelCase__			: List[Any]=12			,							UpperCamelCase__			: Dict=3072			,							UpperCamelCase__			: List[str]="gelu"			,							UpperCamelCase__			: Tuple=0.1			,							UpperCamelCase__			: List[str]=0.1			,							UpperCamelCase__			: Optional[Any]=0.1			,							UpperCamelCase__			: Optional[Any]=0.0			,							UpperCamelCase__			: int=0.0			,							UpperCamelCase__			: Dict=0.1			,							UpperCamelCase__			: Any=0.1			,							UpperCamelCase__			: List[Any]=0.02			,							UpperCamelCase__			: int=1E-5			,							UpperCamelCase__			: Union[str, Any]="group"			,							UpperCamelCase__			: int="gelu"			,							UpperCamelCase__			: Optional[Any]=(512, 512, 512, 512, 512, 512, 512)			,							UpperCamelCase__			: Optional[int]=(5, 2, 2, 2, 2, 2, 2)			,							UpperCamelCase__			: List[str]=(10, 3, 3, 3, 3, 2, 2)			,							UpperCamelCase__			: Dict=False			,							UpperCamelCase__			: Dict=128			,							UpperCamelCase__			: Optional[int]=16			,							UpperCamelCase__			: List[Any]=False			,							UpperCamelCase__			: Optional[int]=True			,							UpperCamelCase__			: Tuple=0.05			,							UpperCamelCase__			: List[str]=10			,							UpperCamelCase__			: int=2			,							UpperCamelCase__			: Optional[int]=0.0			,							UpperCamelCase__			: Any=10			,							UpperCamelCase__			: Optional[int]=0			,							UpperCamelCase__			: Dict=320			,							UpperCamelCase__			: List[str]=2			,							UpperCamelCase__			: int=0.1			,							UpperCamelCase__			: Optional[Any]=100			,							UpperCamelCase__			: Union[str, Any]=256			,							UpperCamelCase__			: Any=256			,							UpperCamelCase__			: List[str]=0.1			,							UpperCamelCase__			: Union[str, Any]="mean"			,							UpperCamelCase__			: Optional[int]=False			,							UpperCamelCase__			: Dict=False			,							UpperCamelCase__			: Optional[Any]=256			,							UpperCamelCase__			: Union[str, Any]=(512, 512, 512, 512, 1500)			,							UpperCamelCase__			: Any=(5, 3, 3, 1, 1)			,							UpperCamelCase__			: Union[str, Any]=(1, 2, 3, 1, 1)			,							UpperCamelCase__			: List[str]=512			,							UpperCamelCase__			: int=0			,							UpperCamelCase__			: Dict=1			,							UpperCamelCase__			: int=2			,							UpperCamelCase__			: List[Any]=504			,							**UpperCamelCase__			: List[str]			,							)			->	str:







    """simple docstring"""






    super().__init__(**UpperCamelCase__			,							pad_token_id=UpperCamelCase__			,							bos_token_id=UpperCamelCase__			,							eos_token_id=UpperCamelCase__    )
    __magic_name__				     =       hidden_size
    __magic_name__				     =       feat_extract_norm
    __magic_name__				     =       feat_extract_activation
    __magic_name__				     =       list(UpperCamelCase__    )
    __magic_name__				     =       list(UpperCamelCase__    )
    __magic_name__				     =       list(UpperCamelCase__    )
    __magic_name__				     =       conv_bias
    __magic_name__				     =       num_conv_pos_embeddings
    __magic_name__				     =       num_conv_pos_embedding_groups
    __magic_name__				     =       len(self.conv_dim    )
    __magic_name__				     =       num_hidden_layers
    __magic_name__				     =       intermediate_size
    __magic_name__				     =       hidden_act
    __magic_name__				     =       num_attention_heads
    __magic_name__				     =       hidden_dropout
    __magic_name__				     =       attention_dropout
    __magic_name__				     =       activation_dropout
    __magic_name__				     =       feat_proj_dropout
    __magic_name__				     =       final_dropout
    __magic_name__				     =       layerdrop
    __magic_name__				     =       layer_norm_eps
    __magic_name__				     =       initializer_range
    __magic_name__				     =       vocab_size
    __magic_name__				     =       num_clusters
    __magic_name__				     =       do_stable_layer_norm
    __magic_name__				     =       use_weighted_layer_sum

    if (
        (len(self.conv_stride    ) != self.num_feat_extract_layers)
        or (len(self.conv_kernel    ) != self.num_feat_extract_layers)
        or (len(self.conv_dim    ) != self.num_feat_extract_layers)
    ):
      raise ValueError(
          """Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="""
          """ `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="""
          F''' {len(self.conv_dim    )}`, `len(config.conv_stride) = {len(self.conv_stride    )}`,'''
          F''' `len(config.conv_kernel) = {len(self.conv_kernel    )}`.'''    )

    # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
    __magic_name__				     =       apply_spec_augment
    __magic_name__				     =       mask_time_prob
    __magic_name__				     =       mask_time_length
    __magic_name__				     =       mask_time_min_masks
    __magic_name__				     =       mask_feature_prob
    __magic_name__				     =       mask_feature_length
    __magic_name__				     =       mask_feature_min_masks

    # parameters for pretraining with codevector quantized representations
    __magic_name__				     =       num_codevectors_per_group
    __magic_name__				     =       num_codevector_groups
    __magic_name__				     =       contrastive_logits_temperature
    __magic_name__				     =       feat_quantizer_dropout
    __magic_name__				     =       num_negatives
    __magic_name__				     =       codevector_dim
    __magic_name__				     =       proj_codevector_dim
    __magic_name__				     =       diversity_loss_weight

    # ctc loss
    __magic_name__				     =       ctc_loss_reduction
    __magic_name__				     =       ctc_zero_infinity

    # SequenceClassification-specific parameter. Feel free to ignore for other classes.
    __magic_name__				     =       classifier_proj_size

    # XVector-specific parameters. Feel free to ignore for other classes.
    __magic_name__				     =       list(UpperCamelCase__    )
    __magic_name__				     =       list(UpperCamelCase__    )
    __magic_name__				     =       list(UpperCamelCase__    )
    __magic_name__				     =       xvector_output_dim





  @property
  def 							_lowercase							( self			: int    )			->	Union[str, Any]:







    """simple docstring"""






    return functools.reduce(operator.mul			,							self.conv_stride			,							1    )



import argparse
from argparse import Namespace

import torch
from torch import nn

from transformers import XGLMConfig, XGLMForCausalLM

def a__    (       A_					):






  '''simple docstring'''





  __magic_name__				     =       [
      """decoder.version""",
      """decoder.output_projection.weight""",
      """_float_tensor""",
      """decoder.embed_positions._float_tensor""",
  ]
  for k in ignore_keys:
    state_dict.pop(A_,     A_					)

def a__    (       A_					):






  '''simple docstring'''





  __magic_name__     ,    __magic_name__				     =       emb.weight.shape
  __magic_name__				     =       nn.Linear(A_,     A_,     bias=A_					)
  __magic_name__				     =       emb.weight.data
  return lin_layer

def a__    (       A_					):






  '''simple docstring'''





  __magic_name__				     =       torch.load(A_,     map_location="""cpu"""					)
  __magic_name__				     =       Namespace(**checkpoint["""cfg"""]["""model"""]					)
  __magic_name__				     =       checkpoint["""model"""]
  remove_ignore_keys_(A_					)
  __magic_name__				     =       state_dict["""decoder.embed_tokens.weight"""].shape[0]

  __magic_name__				     =       {key.replace("""decoder""",     """model"""					): val for key, val in state_dict.items()}

  __magic_name__				     =       XGLMConfig(
      vocab_size=A_,     max_position_embeddings=args.max_target_positions,     num_layers=args.decoder_layers,     attention_heads=args.decoder_attention_heads,     ffn_dim=args.decoder_ffn_embed_dim,     d_model=args.decoder_embed_dim,     layerdrop=args.decoder_layerdrop,     dropout=args.dropout,     attention_dropout=args.attention_dropout,     activation_dropout=args.activation_dropout,     activation_function="""gelu""",     scale_embedding=not args.no_scale_embedding,     tie_word_embeddings=args.share_decoder_input_output_embed,     )

  __magic_name__				     =       XGLMForCausalLM(A_					)
  __magic_name__				     =       model.load_state_dict(A_,     strict=A_					)
  print(A_					)
  __magic_name__				     =       make_linear_from_emb(model.model.embed_tokens					)

  return model


if __name__ == "__main__":
    __lowerCAmelCase			:     Dict           =   argparse.ArgumentParser()
    # Required parameters
    parser.add_argument('fairseq_path', type=str, help='path to a model.pt on local filesystem.')
    parser.add_argument('pytorch_dump_folder_path', default=None, type=str, help='Path to the output PyTorch model.')
    __lowerCAmelCase			:     List[str]           =   parser.parse_args()
    __lowerCAmelCase			:     str           =   convert_fairseq_xglm_checkpoint_from_disk(args.fairseq_path)
    model.save_pretrained(args.pytorch_dump_folder_path)

